SDL

Форк
0
/
highlight-plugin.lua 
76 строк · 2.7 Кб
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 string.find(token, "SDL_")==1 then
48
      return getURL(token)
49
    end
50

51
  end
52
end
53

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
57

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}"
63

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}"
69
  end
70
end
71

72
-- let highlight load the chunks
73
Plugins={
74
  { Type="lang", Chunk=syntaxUpdate },
75
  { Type="theme", Chunk=themeUpdate },
76
}
77

78

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.