File: outhtml_curly_brackets_matcher.lua

package info (click to toggle)
highlight 4.10-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,556 kB
  • sloc: cpp: 27,579; makefile: 411; sh: 341; ansic: 264; php: 236; python: 217; ruby: 132; perl: 61; tcl: 1
file content (89 lines) | stat: -rw-r--r-- 2,290 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
--[[
Sample plugin file for highlight 3.14

Assumes that CSS is enabled (ie Inline CSS is not set)
]]

Description="Shows matching curly brackets in HTML output."

Categories = {"format", "html", "usability" }

-- optional parameter: syntax description
function syntaxUpdate(desc)

  if (desc=="Bash") then
    return
  end

  if (HL_OUTPUT == HL_FORMAT_HTML or HL_OUTPUT == HL_FORMAT_XHTML) then
    pID=0     -- just a sequential counter to generate HTML IDs
    pCount=0    -- parenthesis counter to keep track of opening and closing pairs
    openPID={} -- save opening IDs as they are needed again for the close tag IDs

    HeaderInjection=[=[
<script type="text/javascript">
  /* <![CDATA[ */
  function showMB(sender){
    sender.style.background= (sender.style.background=='') ?  'yellow' : '';
    var otherParenID = (sender.id[0]=='c') ? 'o' : 'c';
    otherParenID+=sender.id.substr(1);
    other=document.getElementById(otherParenID);
    other.style.background= (other.style.background=='') ? 'yellow': '';
  }
  /* ]]> */
</script>
]=]
  end

  function getTag(token, id, kind)
    return '<span class="hl box" id="'..kind..'b_'..id..'" onclick="showMB(this);">'..token..'</span>'
  end

  function getOpenParen(token)
    pID=pID+1
    pCount=pCount+1
    openPID[pCount] = pID
    return getTag(token, pID, 'o')
  end

  function getCloseParen(token)
    oID=openPID[pCount]
    if oID then
      pCount=pCount-1
      return getTag(token, oID, 'c')
    end
  end

  function Decorate(token, state)

    if (state ~= HL_OPERATOR or HL_OUTPUT ~= HL_FORMAT_HTML) then
      return
    end

    if string.find(token, "{")==1 then
      return getOpenParen(token)
    end

    if string.find(token, "}")==1 then
      return getCloseParen(token)
    end

  end
end


function themeUpdate(desc)
  if (HL_OUTPUT == HL_FORMAT_HTML or HL_OUTPUT == HL_FORMAT_XHTML) then
    Injections[#Injections+1]=".hl.box { border-width:1px;border-style:dotted;border-color:gray; cursor: pointer;}"
  end
end
--The Plugins array assigns code chunks to themes or language definitions.
--The chunks are interpreted after the theme or lang file were parsed,
--so you can refer to elements of these files

Plugins={

  { Type="lang", Chunk=syntaxUpdate },
  { Type="theme", Chunk=themeUpdate },

}