diff options
author | 3gg <3gg@shellblade.net> | 2025-08-30 16:53:58 -0700 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2025-08-30 16:53:58 -0700 |
commit | 6aaedb813fa11ba0679c3051bc2eb28646b9506c (patch) | |
tree | 34acbfc9840e02cb4753e6306ea7ce978bf8b58e /src/contrib/SDL-3.2.20/examples/highlight-plugin.lua | |
parent | 8f228ade99dd3d4c8da9b78ade1815c9adf85c8f (diff) |
Update to SDL3
Diffstat (limited to 'src/contrib/SDL-3.2.20/examples/highlight-plugin.lua')
-rw-r--r-- | src/contrib/SDL-3.2.20/examples/highlight-plugin.lua | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/contrib/SDL-3.2.20/examples/highlight-plugin.lua b/src/contrib/SDL-3.2.20/examples/highlight-plugin.lua new file mode 100644 index 0000000..9598ec9 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/highlight-plugin.lua | |||
@@ -0,0 +1,79 @@ | |||
1 | -- This code adapted from https://gitlab.com/saalen/highlight/-/wikis/Plug-Ins | ||
2 | |||
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" | ||
5 | |||
6 | -- define the plugin categories (ie. supported output formats; languages) | ||
7 | Categories = { "c", "c++" } | ||
8 | |||
9 | -- the syntaxUpdate function contains code related to syntax recognition | ||
10 | function syntaxUpdate(desc) | ||
11 | |||
12 | -- if the current file is not C/C++ file we exit | ||
13 | if desc~="C and C++" then | ||
14 | return | ||
15 | end | ||
16 | |||
17 | -- this function returns a qt-project reference link of the given token | ||
18 | function getURL(token) | ||
19 | -- generate the URL | ||
20 | url='https://wiki.libsdl.org/SDL3/'.. token | ||
21 | |||
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..'}}}' | ||
32 | end | ||
33 | end | ||
34 | |||
35 | -- the Decorate function will be invoked for every recognized token | ||
36 | function Decorate(token, state) | ||
37 | |||
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 | ||
41 | return | ||
42 | end | ||
43 | |||
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 ( (token == "Uint8") or (token == "Uint16") or (token == "Uint32") or (token == "Uint64") or | ||
48 | (token == "Sint8") or (token == "Sint16") or (token == "Sint32") or (token == "Sint64") or | ||
49 | (string.find(token, "SDL_") == 1) ) then | ||
50 | return getURL(token) | ||
51 | end | ||
52 | |||
53 | end | ||
54 | end | ||
55 | |||
56 | -- the themeUpdate function contains code related to the theme | ||
57 | function themeUpdate(desc) | ||
58 | -- the Injections table can be used to add style information to the theme | ||
59 | |||
60 | -- HTML: we add additional CSS style information to beautify hyperlinks, | ||
61 | -- they should have the same color as their surrounding tags | ||
62 | if (HL_OUTPUT == HL_FORMAT_HTML or HL_OUTPUT == HL_FORMAT_XHTML) then | ||
63 | Injections[#Injections+1]= | ||
64 | "a.hl, a.hl:visited {color:inherit;font-weight:inherit;text-decoration:none}" | ||
65 | |||
66 | -- LaTeX: hyperlinks require the hyperref package, so we add this here | ||
67 | -- the colorlinks and pdfborderstyle options remove ugly boxes in the output | ||
68 | elseif (HL_OUTPUT==HL_FORMAT_LATEX) then | ||
69 | Injections[#Injections+1]= | ||
70 | "\\usepackage[colorlinks=false, pdfborderstyle={/S/U/W 1}]{hyperref}" | ||
71 | end | ||
72 | end | ||
73 | |||
74 | -- let highlight load the chunks | ||
75 | Plugins={ | ||
76 | { Type="lang", Chunk=syntaxUpdate }, | ||
77 | { Type="theme", Chunk=themeUpdate }, | ||
78 | } | ||
79 | |||