1
-- This code adapted from https://gitlab.com/saalen/highlight/-/wikis/Plug-Ins
3
-- first add a description of what the plug-in does
4
Description="Add wiki.libsdl.org reference links to HTML, LaTeX or RTF output"
6
-- define the plugin categories (ie. supported output formats; languages)
7
Categories = { "c", "c++" }
9
-- the syntaxUpdate function contains code related to syntax recognition
10
function syntaxUpdate(desc)
12
-- if the current file is not C/C++ file we exit
13
if desc~="C and C++" then
17
-- this function returns a qt-project reference link of the given token
18
function getURL(token)
20
url='https://wiki.libsdl.org/SDL3/'.. token
22
-- embed the URL in a hyperlink according to the output format
23
-- first HTML, then LaTeX and RTF
24
if (HL_OUTPUT== HL_FORMAT_HTML or HL_OUTPUT == HL_FORMAT_XHTML) then
25
return '<a class="hl" target="new" href="'
26
.. url .. '">'.. token .. '</a>'
27
elseif (HL_OUTPUT == HL_FORMAT_LATEX) then
28
return '\\href{'..url..'}{'..token..'}'
29
elseif (HL_OUTPUT == HL_FORMAT_RTF) then
30
return '{{\\field{\\*\\fldinst HYPERLINK "'
31
..url..'" }{\\fldrslt\\ul\\ulc0 '..token..'}}}'
35
-- the Decorate function will be invoked for every recognized token
36
function Decorate(token, state)
38
-- we are only interested in keywords, preprocessor or default items
39
if (state ~= HL_STANDARD and state ~= HL_KEYWORD and
40
state ~=HL_PREPROC) then
44
-- SDL keywords start with SDL_
45
-- if this pattern applies to the token, we return the URL
46
-- if we return nothing, the token is outputted as is
47
if string.find(token, "SDL_")==1 then
54
-- the themeUpdate function contains code related to the theme
55
function themeUpdate(desc)
56
-- the Injections table can be used to add style information to the theme
58
-- HTML: we add additional CSS style information to beautify hyperlinks,
59
-- they should have the same color as their surrounding tags
60
if (HL_OUTPUT == HL_FORMAT_HTML or HL_OUTPUT == HL_FORMAT_XHTML) then
61
Injections[#Injections+1]=
62
"a.hl, a.hl:visited {color:inherit;font-weight:inherit;text-decoration:none}"
64
-- LaTeX: hyperlinks require the hyperref package, so we add this here
65
-- the colorlinks and pdfborderstyle options remove ugly boxes in the output
66
elseif (HL_OUTPUT==HL_FORMAT_LATEX) then
67
Injections[#Injections+1]=
68
"\\usepackage[colorlinks=false, pdfborderstyle={/S/U/W 1}]{hyperref}"
72
-- let highlight load the chunks
74
{ Type="lang", Chunk=syntaxUpdate },
75
{ Type="theme", Chunk=themeUpdate },