"Fossies" - the Fresh Open Source Software Archive

Member "highlight-3.57-x64/plugins/outhtml_keyword_matcher.lua" (12 May 2020, 2024 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.

    1 
    2 
    3 Description="Shows matching keywords in HTML output. Define the keyword group as plug-in parameter."
    4 
    5 Categories = {"format", "html", "usability" }
    6 
    7 -- optional parameter: syntax description
    8 function syntaxUpdate(desc)
    9 
   10   if (HL_OUTPUT == HL_FORMAT_HTML or HL_OUTPUT == HL_FORMAT_XHTML) then
   11 
   12     -- can use 1 to 4, depending on the syntax definition
   13     keywordGroup=1
   14     if (#HL_PLUGIN_PARAM>0) then keywordGroup = tonumber(HL_PLUGIN_PARAM) end
   15 
   16     kwID = { }
   17     kwIDCnt=0
   18 
   19     HeaderInjection=[[
   20       <script type="text/javascript">
   21       function showSameKW(sender){
   22         var myRegexp = /(kw_\d+)/;
   23         var kwID = myRegexp.exec(sender.id)[1];
   24         var elements=document.getElementsByTagName('span');
   25         for (var i = 0; i < elements.length; i++) {
   26           if (elements[i].id.indexOf( kwID)==0 && myRegexp.exec(elements[i].id)[1] ==  kwID){
   27             elements[i].style.background= (elements[i].style.background=='') ? 'yellow': '';
   28           }
   29         }
   30       }
   31       </script>
   32 ]]
   33   end
   34 
   35   --may be triggered twice per keyword
   36   function OnStateChange(oldState, newState, token, kwgroup)
   37     if newState==HL_KEYWORD  and kwgroup==keywordGroup then
   38 
   39       if kwID[token] == nil then
   40         kwIDCnt=kwIDCnt+1
   41         kwID[token] = { }
   42         kwID[token][0] = kwIDCnt
   43         kwID[token][1] = 1
   44       else
   45         kwID[token][1] = kwID[token][1] + 1
   46       end
   47 
   48     end
   49     return newState
   50   end
   51 
   52   function Decorate(token, state)
   53     if (state ~= HL_KEYWORD or kwID[token]==nil or HL_OUTPUT ~= HL_FORMAT_HTML) then
   54       return
   55     end
   56     return '<span class="hl box" id="kw_'..kwID[token][0]..'_'..kwID[token][1]..'" onclick="showSameKW(this);">'..token..'</span>'
   57   end
   58 
   59 end
   60 
   61 
   62 function themeUpdate(desc)
   63   if (HL_OUTPUT == HL_FORMAT_HTML or HL_OUTPUT == HL_FORMAT_XHTML) then
   64     Injections[#Injections+1]=".hl.box { border-width:1px;border-style:dotted;border-color:gray; cursor: pointer;}"
   65   end
   66 end
   67 
   68 Plugins={
   69 
   70   { Type="lang", Chunk=syntaxUpdate },
   71   { Type="theme", Chunk=themeUpdate },
   72 
   73 }