1--[[
2Sample plugin file for highlight 3.14
3
4Assumes that CSS is enabled (ie Inline CSS is not set)
5]]
6
7Description="Shows matching parentheses and curly brackets in HTML output."
8
9Categories = {"format", "html", "usability" }
10
11-- optional parameter: syntax description
12function syntaxUpdate(desc)
13
14  if (desc=="Bash") then
15    return
16  end
17
18  if (HL_OUTPUT == HL_FORMAT_HTML or HL_OUTPUT == HL_FORMAT_XHTML) then
19    pID=0      -- just a sequential counter to generate HTML IDs
20    pCnt=0     -- parenthesis counter to keep track of opening and closing pairs
21    openPID={} -- save opening IDs as they are needed again for the close tag IDs
22
23    HeaderInjection=[=[
24<script type="text/javascript">
25/* <![CDATA[ */
26  function showMP(sender){
27    var color=sender.id[1]=='p' ? 'yellow':'orange';
28    sender.style.background= (sender.style.background=='') ?  color : '';
29    var otherParenID = (sender.id[0]=='c') ? 'o' : 'c';
30    otherParenID+=sender.id.substr(1);
31    other=document.getElementById(otherParenID);
32    other.style.background= (other.style.background=='') ? color : '';
33  }
34/* ]]> */
35</script>
36]=]
37    end
38
39  function getTag(token, id, kind)
40    return '<span class="hl box" id="'..kind..'_'..id..'" onclick="showMP(this);">'..token..'</span>'
41  end
42
43  function getOpenParen(token, kind)
44    pID=pID+1
45    pCnt=pCnt+1
46    openPID[pCnt] = pID
47    return getTag(token, pID, kind)
48  end
49
50  function getCloseParen(token, kind)
51    oID=openPID[pCnt]
52    if oID then
53      pCnt=pCnt-1
54      return getTag(token, oID, kind)
55    end
56  end
57
58  function Decorate(token, state)
59
60    if (state ~= HL_OPERATOR or HL_OUTPUT ~= HL_FORMAT_HTML) then
61      return
62    end
63
64    if string.find(token, '%(')==1 then
65      return getOpenParen(token, 'op')
66    end
67
68    if string.find(token, '%)')==1 then
69      return getCloseParen(token, 'cp')
70    end
71
72    if string.find(token, '%{')==1 then
73      return getOpenParen(token, 'ob')
74    end
75
76    if string.find(token, '%}')==1 then
77      return getCloseParen(token, 'cb')
78    end
79
80  end
81end
82
83function themeUpdate(desc)
84  if (HL_OUTPUT == HL_FORMAT_HTML or HL_OUTPUT == HL_FORMAT_XHTML) then
85    Injections[#Injections+1]=".hl.box { border-width:1px;border-style:dotted;border-color:gray; cursor: pointer;}"
86  end
87end
88
89--The Plugins array assigns code chunks to themes or language definitions.
90--The chunks are interpreted after the theme or lang file were parsed,
91--so you can refer to elements of these files
92
93Plugins={
94
95  { Type="lang", Chunk=syntaxUpdate },
96  { Type="theme", Chunk=themeUpdate },
97
98}
99