"Fossies" - the Fresh Open Source Software Archive

Member "highlight-3.57-x64/plugins/outhtml_add_background_stripes.lua" (12 May 2020, 1825 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_add_background_stripes.lua": 3.53_vs_3.54.

    1 --[[
    2 Sample plugin file for highlight
    3 
    4 Adds background stripes
    5 ]]
    6 
    7 Description="Adds background stripes in HTML output "
    8 
    9 Categories = {"format", "html" }
   10 
   11 -- function to update theme definition
   12 -- optional parameter: theme description
   13 function themeUpdate()
   14 
   15   function lighten(colour)
   16     if string.match(colour, "#%x+")==nil then
   17       return "rgba(0,0,0,0)"
   18     end
   19 
   20     base_rr = ("0x"..string.match(colour, "%x%x", 2))
   21     base_gg = ("0x"..string.match(colour, "%x%x", 4))
   22     base_bb = ("0x"..string.match(colour, "%x%x", 6))
   23 
   24     min_bright=math.min(base_rr, base_gg, base_bb)
   25     max_bright=math.max(base_rr, base_gg, base_bb)
   26     brightness = (min_bright + max_bright) / (255*2.0)
   27 
   28     if (brightness < 0.1) then
   29       return "rgba(50,50,50, 0.5)"
   30     elseif (brightness < 0.5) then
   31       percent = 100
   32     elseif (brightness > 0.95) then
   33       percent = -10
   34     else
   35       percent = 80
   36     end
   37 
   38     rr = math.floor(base_rr * (100 + percent) / 100 )
   39     gg = math.floor(base_gg * (100 + percent) / 100 )
   40     bb = math.floor(base_bb * (100 + percent) / 100 )
   41 
   42     if (rr>255) then rr = 255 end
   43     if (gg>255) then gg = 255 end
   44     if (bb>255) then bb = 255 end
   45     return string.format("rgba(%d,%d,%d,0.25)", rr, gg, bb)
   46   end
   47 
   48   if (HL_OUTPUT == HL_FORMAT_HTML or HL_OUTPUT == HL_FORMAT_XHTML) then
   49 
   50     -- inspired by prismjs ;)
   51     Injections[#Injections+1]="pre.hl { background-image: linear-gradient(transparent 50%, "..lighten(Canvas.Colour)..
   52       " 50%); background-size:3em 3em; background-origin:content-box; font-size:100%/1.5;line-height: 1.5; }"
   53   end
   54 end
   55 
   56 --The Plugins array assigns code chunks to themes or language definitions.
   57 --The chunks are interpreted after the theme or lang file were parsed,
   58 --so you can refer to elements of these files
   59 Plugins={
   60 
   61   { Type="theme", Chunk=themeUpdate }
   62 
   63 }