"Fossies" - the Fresh Open Source Software Archive

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

    1 --[[
    2 Sample plugin file for highlight 3.9
    3 ]]
    4 
    5 Description="Add python.org reference links to HTML, LaTeX, RTF and ODT output of Python code"
    6 
    7 Categories = {"python", "html", "rtf", "latex", "odt" }
    8 
    9 -- optional parameter: syntax description
   10 function syntaxUpdate(desc)
   11 
   12   if desc~="Python" then
   13     return
   14   end
   15 
   16   function Set (list)
   17     local set = {}
   18     for _, l in ipairs(list) do set[l] = true end
   19       return set
   20   end
   21 
   22   simple_items = Set {"assert","pass","del","print","return","yield","raise","break","continue","import","global","exec" }
   23   compound_items = Set {"if","while", "for","try", "with" }
   24 
   25   function getURL(token, cat)
   26     url='http://docs.python.org/reference/'..cat..'_stmts.html#the-'..token.. '-statement'
   27 
   28     if (HL_OUTPUT== HL_FORMAT_HTML or HL_OUTPUT == HL_FORMAT_XHTML) then
   29       return '<a class="hl" target="new" href="' .. url .. '">'.. token .. '</a>'
   30     elseif (HL_OUTPUT == HL_FORMAT_LATEX) then
   31       return '\\href{'..url..'}{'..token..'}'
   32     elseif (HL_OUTPUT == HL_FORMAT_RTF) then
   33       return '{{\\field{\\*\\fldinst HYPERLINK "'..url..'" }{\\fldrslt\\ul\\ulc0 '..token..'}}}'
   34     elseif (HL_OUTPUT == HL_FORMAT_ODT) then
   35       return '<text:a xlink:type="simple" xlink:href="'..url..'">'..token..'</text:a>'
   36     end
   37   end
   38 
   39   function Decorate(token, state)
   40 
   41     if (state ~= HL_STANDARD and state ~= HL_KEYWORD) then
   42       return
   43     end
   44 
   45     if simple_items[token] then
   46       return getURL(token,'simple')
   47     elseif compound_items[token] then
   48       return getURL(token,'compound')
   49     end
   50 
   51   end
   52 end
   53 
   54 function themeUpdate(desc)
   55   if (HL_OUTPUT == HL_FORMAT_HTML or HL_OUTPUT == HL_FORMAT_XHTML) then
   56     Injections[#Injections+1]="a.hl, a.hl:visited {color:inherit;font-weight:inherit;}"
   57   elseif (HL_OUTPUT==HL_FORMAT_LATEX) then
   58     Injections[#Injections+1]="\\usepackage[colorlinks=false, pdfborderstyle={/S/U/W 1}]{hyperref}"
   59   end
   60 end
   61 --The Plugins array assigns code chunks to themes or language definitions.
   62 --The chunks are interpreted after the theme or lang file were parsed,
   63 --so you can refer to elements of these files
   64 
   65 Plugins={
   66 
   67   { Type="lang", Chunk=syntaxUpdate },
   68   { Type="theme", Chunk=themeUpdate },
   69 
   70 }