"Fossies" - the Fresh Open Source Software Archive

Member "highlight-3.57-x64/plugins/mark_lines.lua" (12 May 2020, 3065 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 "mark_lines.lua": 3.56_vs_3.57.

    1 
    2 Description="Marks the lines defined as comma separated list in the plug-in parameter (HTML and RTF only)."
    3 
    4 Categories = {"format", "html", "rtf" }
    5 
    6 
    7 function syntaxUpdate(desc)
    8 
    9   if HL_OUTPUT ~= HL_FORMAT_HTML and HL_OUTPUT ~= HL_FORMAT_XHTML
   10     and HL_OUTPUT ~= HL_FORMAT_RTF then return end
   11 
   12   if #HL_PLUGIN_PARAM == 0 then return end
   13 
   14   -- we need a dummy kw class to get the line mark colour into the colour map
   15   if HL_OUTPUT == HL_FORMAT_RTF then
   16     table.insert( Keywords, { Id=#Keywords+1, List={"HL_RTF_DUMMY" } } )
   17   end
   18 
   19   -- explode (separator, string)
   20   function explode(d,p)
   21     local t, ll
   22     t={}
   23     ll=0
   24     if(#p == 1) then return {p} end
   25     while true do
   26       l=string.find(p,d,ll,true) -- find the next d in the string
   27       if l~=nil then -- if "not not" found then..
   28         t[tonumber(string.sub(p,ll,l-1))] = 1
   29         ll=l+1 -- save just after where we found it for searching next time.
   30       else
   31         t[tonumber(string.sub(p,ll))] = 1
   32         break -- Break at end, as it should be, according to the lua manual.
   33       end
   34     end
   35     return t
   36   end
   37 
   38   linesToMark=explode(',', HL_PLUGIN_PARAM)
   39   currentLineNumber=0
   40 
   41   function DecorateLineBegin(lineNumber)
   42     currentLineNumber = lineNumber
   43     if (linesToMark[currentLineNumber]) then
   44       if HL_OUTPUT==HL_FORMAT_RTF then
   45         patternIdx = 12 + #Keywords  -- Index of the style which was added before
   46         return '\\chcbpat'..patternIdx..'{'
   47       end
   48       return '<span class="hl mark">'
   49     end
   50   end
   51 
   52   function DecorateLineEnd()
   53     if (linesToMark[currentLineNumber]) then
   54       if HL_OUTPUT==HL_FORMAT_RTF then
   55           return '}'
   56       end
   57       return '</span>'
   58     end
   59   end
   60 
   61 end
   62 
   63 function themeUpdate(desc)
   64 
   65   function lighten(colour)
   66     if string.match(colour, "#%x+")==nil then
   67       return "#000000"
   68     end
   69 
   70     base_rr = ("0x"..string.match(colour, "%x%x", 2))
   71     base_gg = ("0x"..string.match(colour, "%x%x", 4))
   72     base_bb = ("0x"..string.match(colour, "%x%x", 6))
   73 
   74     min_bright=math.min(base_rr, base_gg, base_bb)
   75     max_bright=math.max(base_rr, base_gg, base_bb)
   76     brightness = (min_bright + max_bright) / (255*2.0)
   77 
   78     if (brightness < 0.1) then
   79       return "#444444"
   80     elseif (brightness < 0.5) then
   81       percent = 100
   82     elseif (brightness > 0.95) then
   83       percent = -10
   84     else
   85       percent = 80
   86     end
   87 
   88     rr = math.floor(base_rr * (100 + percent) / 100 )
   89     gg = math.floor(base_gg * (100 + percent) / 100 )
   90     bb = math.floor(base_bb * (100 + percent) / 100 )
   91 
   92     if (rr>255) then rr = 255 end
   93     if (gg>255) then gg = 255 end
   94     if (bb>255) then bb = 255 end
   95     return string.format("#%02x%02x%02x", rr, gg, bb)
   96   end
   97 
   98   if (HL_OUTPUT == HL_FORMAT_HTML or HL_OUTPUT == HL_FORMAT_XHTML) then
   99     Injections[#Injections+1]=".hl.mark { background-color:"..lighten(Canvas.Colour).."; width:100%;float:left;}"
  100   elseif (HL_OUTPUT == HL_FORMAT_RTF) then
  101     table.insert(Keywords, {Colour=lighten(Canvas.Colour)})
  102   end
  103 end
  104 
  105 Plugins={
  106   { Type="lang", Chunk=syntaxUpdate },
  107   { Type="theme", Chunk=themeUpdate },
  108 }