"Fossies" - the Fresh Open Source Software Archive

Member "highlight-3.57-x64/plugins/outhtml_curly_brackets_matcher.lua" (12 May 2020, 2290 Bytes) of package /windows/www/highlight-3.57-x64.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Lua source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "outhtml_curly_brackets_matcher.lua": 3.53_vs_3.54.

    1 --[[
    2 Sample plugin file for highlight 3.14
    3 
    4 Assumes that CSS is enabled (ie Inline CSS is not set)
    5 ]]
    6 
    7 Description="Shows matching curly brackets in HTML output."
    8 
    9 Categories = {"format", "html", "usability" }
   10 
   11 -- optional parameter: syntax description
   12 function 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     pCount=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 showMB(sender){
   27     sender.style.background= (sender.style.background=='') ?  'yellow' : '';
   28     var otherParenID = (sender.id[0]=='c') ? 'o' : 'c';
   29     otherParenID+=sender.id.substr(1);
   30     other=document.getElementById(otherParenID);
   31     other.style.background= (other.style.background=='') ? 'yellow': '';
   32   }
   33   /* ]]> */
   34 </script>
   35 ]=]
   36   end
   37 
   38   function getTag(token, id, kind)
   39     return '<span class="hl box" id="'..kind..'b_'..id..'" onclick="showMB(this);">'..token..'</span>'
   40   end
   41 
   42   function getOpenParen(token)
   43     pID=pID+1
   44     pCount=pCount+1
   45     openPID[pCount] = pID
   46     return getTag(token, pID, 'o')
   47   end
   48 
   49   function getCloseParen(token)
   50     oID=openPID[pCount]
   51     if oID then
   52       pCount=pCount-1
   53       return getTag(token, oID, 'c')
   54     end
   55   end
   56 
   57   function Decorate(token, state)
   58 
   59     if (state ~= HL_OPERATOR or HL_OUTPUT ~= HL_FORMAT_HTML) then
   60       return
   61     end
   62 
   63     if string.find(token, "{")==1 then
   64       return getOpenParen(token)
   65     end
   66 
   67     if string.find(token, "}")==1 then
   68       return getCloseParen(token)
   69     end
   70 
   71   end
   72 end
   73 
   74 
   75 function themeUpdate(desc)
   76   if (HL_OUTPUT == HL_FORMAT_HTML or HL_OUTPUT == HL_FORMAT_XHTML) then
   77     Injections[#Injections+1]=".hl.box { border-width:1px;border-style:dotted;border-color:gray; cursor: pointer;}"
   78   end
   79 end
   80 --The Plugins array assigns code chunks to themes or language definitions.
   81 --The chunks are interpreted after the theme or lang file were parsed,
   82 --so you can refer to elements of these files
   83 
   84 Plugins={
   85 
   86   { Type="lang", Chunk=syntaxUpdate },
   87   { Type="theme", Chunk=themeUpdate },
   88 
   89 }