"Fossies" - the Fresh Open Source Software Archive

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

    1 
    2 Description="Modify URLs within comments to clickable hyperlinks in HTML, LaTeX, ODT and RTF output"
    3 
    4 Categories = {"html", "rtf", "latex", "odt", "hyperlinks" }
    5 
    6 function syntaxUpdate(desc)
    7 
    8   table.insert( Keywords,
    9         { Id=100,
   10                 Regex=[[https?\:\/\/[\w\./&\?\-\+\,\;\=\:\(\)]+]]
   11                 })
   12   table.insert( Keywords,
   13                 { Id=101,
   14                 Regex=[[[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+]]
   15                 })
   16 
   17   function getURL(token)
   18 
   19     if (HL_OUTPUT== HL_FORMAT_HTML or HL_OUTPUT == HL_FORMAT_XHTML) then
   20       return '<a class="hl" target="new" href="' .. token .. '">'.. token .. '</a>'
   21     elseif (HL_OUTPUT == HL_FORMAT_LATEX) then
   22       return '\\href{'..token..'}{'..token..'}'
   23     elseif (HL_OUTPUT == HL_FORMAT_RTF) then
   24       return '{{\\field{\\*\\fldinst HYPERLINK "'..token..'" }{\\fldrslt\\ul\\ulc0 '..token..'}}}'
   25     elseif (HL_OUTPUT == HL_FORMAT_ODT) then
   26       return '<text:a xlink:type="simple" xlink:href="'..token..'">'..token..'</text:a>'
   27     end
   28   end
   29 
   30   function getMailURL(token)
   31     if (HL_OUTPUT== HL_FORMAT_HTML or HL_OUTPUT == HL_FORMAT_XHTML) then
   32       return '<a class="hl" href="mailto:' .. token .. '">'.. token .. '</a>'
   33     end
   34   end
   35 
   36   function Decorate(token, state)
   37 
   38     if (state ~= HL_LINE_COMMENT and state ~= HL_BLOCK_COMMENT) then
   39       return
   40     end
   41 
   42     if string.find(token, "https?://")==1 then
   43       return getURL(token)
   44     end
   45 
   46     if string.find(token, "[%w%p]+@[%w%p]+%.%a+")==1 then
   47       return getMailURL(token)
   48     end
   49 
   50   end
   51 end
   52 
   53 function themeUpdate(desc)
   54   if (HL_OUTPUT == HL_FORMAT_HTML or HL_OUTPUT == HL_FORMAT_XHTML) then
   55     Injections[#Injections+1]="a.hl, a.hl:visited {color:inherit;font-weight:inherit;}"
   56   elseif (HL_OUTPUT==HL_FORMAT_LATEX) then
   57     Injections[#Injections+1]="\\usepackage[colorlinks=false, pdfborderstyle={/S/U/W 1}]{hyperref}"
   58   end
   59 end
   60 
   61 Plugins={
   62 
   63   { Type="lang", Chunk=syntaxUpdate },
   64   { Type="theme", Chunk=themeUpdate },
   65 
   66 }