Atlas - highlight-plugin.lua

Home / ext / SDL / examples Lines: 1 | Size: 2922 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
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 4Description="Add wiki.libsdl.org reference links to HTML, LaTeX or RTF output" 5 6-- define the plugin categories (ie. supported output formats; languages) 7Categories = { "c", "c++" } 8 9-- the syntaxUpdate function contains code related to syntax recognition 10function 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 54end 55 56-- the themeUpdate function contains code related to the theme 57function 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 72end 73 74-- let highlight load the chunks 75Plugins={ 76 { Type="lang", Chunk=syntaxUpdate }, 77 { Type="theme", Chunk=themeUpdate }, 78} 79 80
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.