"Fossies" - the Fresh Open Source Software Archive

Member "highlight-3.57-x64/extras/pandoc/Highlight.pp" (12 May 2020, 8399 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) Ruby 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 !comment(   "Highlight" pp-macros set   )
    2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    3 "Highlight.pp" v2.1.1 (2017-10-26) | PP v2.0
    4 
    5 A set of macros for integrating André Simon's Highlight syntax highlighter with
    6 pandoc documents:
    7 
    8 -- http://www.andre-simon.de/
    9 
   10 ------------------------------------------------------------------------------
   11 MACROS LIST:
   12 
   13 -- !HighlightFile
   14 -- !Highlight
   15 -- !HighlightInlineTheme
   16 
   17 INTERNAL-USE MACROS:
   18 
   19 -- !_HLCounter
   20 -- !HighlightSh
   21 -- !HighlightCMD
   22 --------------------------------------------------------------------------------
   23   OUT FORMAT: html
   24   OS SUPPORT: Win + Linux + macOS
   25 REQUIREMENTS: Highlight cli tool must be available on system %PATH%.
   26 --------------------------------------------------------------------------------
   27 This file is part of "The Pandoc-Goodies PP-Macros Library":
   28  -- https://github.com/tajmone/pandoc-goodies/tree/master/pp
   29 
   30 (c) Tristano Ajmone 2017, MIT License.
   31 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   32 
   33 
   34 
   35 
   36 !comment{  !HighlightFile                                    v2.0 | 2017-10-25 }
   37 ````````````````````````````````````````````````````````````````````````````````
   38 DESCRIPTION: Syntax highlight the source code file passed in 1st parameter using
   39     Highlight external tool. The code language must be defined in the 2nd param,
   40     it will be passed as Highlight's syntax parameter option, and will also be
   41     added as a class to the <code> & <pre> tags to allow finer styling control
   42     with custom CSS.
   43     Optionally:
   44     -- 3rd parameter can contain extra Highlight invocation options.
   45 
   46 USAGE:
   47 
   48         !HighlightFile(FILE)(LANG)[(OPTIONS)]
   49 
   50 OUTPUT:
   51 
   52         <pre class="hl LANG"><code class="LANG">
   53         ... HIGHLIGHTED CODE ...
   54         </code></pre>
   55 
   56 ````````````````````````````````````````````````````````````````````````````````
   57 !define(   HighlightFile   )
   58 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   59 <pre class="hl !2"><code class="!2">!exec
   60 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   61 highlight -f -S !2 --no-trailing-nl --validate-input !3 -i !1
   62 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</code></pre>
   63 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   64 
   65 
   66 
   67 
   68 
   69 !comment{  !HighlightInlineTheme                             v2.0 | 2017-10-25 }
   70 ````````````````````````````````````````````````````````````````````````````````
   71 DESCRIPTION: Retrieves a Highlight Theme and injects its CSS into the document. 
   72             A quick solution for theming Highlight code without having to import
   73             an external CSS file via pandoc.
   74 
   75 NOTE:       The Theme name must be passed without the ".theme" extension!
   76 
   77 USAGE:
   78 
   79         !HighlightInlineTheme(THEME NAME)
   80 
   81 ````````````````````````````````````````````````````````````````````````````````
   82 !define(   HighlightInlineTheme  )
   83 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   84 <style type="text/css">
   85 !exec
   86 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   87 highlight --print-style --style=!1 --stdout
   88 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   89 </style>
   90 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   91 
   92 
   93 
   94 !comment{  !_HLCounter }
   95 ````````````````````````````````````````````````````````````````````````````````
   96 ** FOR INTERNAL USE ONLY! **
   97 Defines a temporary files counter at module load-time, and sets it to zero.
   98 ````````````````````````````````````````````````````````````````````````````````
   99 !define(   _HLCounter   )(0)
  100 
  101 
  102 
  103 !comment{   !Highlight                                     v2.1 | 2017-10-25 }
  104 ``````````````````````````````````````````````````````````````````````````````
  105 DESCRIPTION: Syntax highlight the source code within the 3rd parameter using
  106     Highlight external tool. The code language must be defined in 1st param.
  107     Optionally:
  108     -- 2nd parameter can contain extra Highlight invocation options.
  109 USAGE:
  110 
  111     !Highlight(LANG)([EXTRA HIGHLIGHT OPTIONS])
  112     ~~~~~~~~~~~~~~~~
  113     BLOCK OF SOURCECODE
  114     ~~~~~~~~~~~~~~~~
  115 
  116 NOTES: This macro will first try to establish under which context PP is being
  117        invoked (ie: Win CMD or Shell/Bash), then calls the appropriate variant
  118        of the !Highlight macro:
  119        -- If OS is Windows:
  120           -- if context is Git Bash:     invoke !HighlightSh
  121           -- otherwise (context is CMD): invoke !HighlightCMD
  122        -- If OS is other than Windows:   invoke !HighlightSh   
  123 
  124 Under Windows, establishing if the context is Git Bash or Win CMD is done by
  125 checking if the "SHELL" env var exists (ie: it's not empty).
  126 Inside Git Bash for Windows, the "SHELL" env var is available systemwide, its
  127 value being a string pointing to the location of the Bash executable. Eg:
  128 
  129     "C:\Program Files\Git\usr\bin\bash.exe"
  130 
  131 If the "!env(SHELL)" macro emits an empty string, we assume that PP is being
  132 invoked from CMD -- it could also be in PowerShell, but we have no means to
  133 check that.
  134 ``````````````````````````````````````````````````````````````````````````````
  135 !define(   Highlight   )
  136 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  137 !ifeq[!os][windows]
  138 [  !comment{ ======== OS Is Windows: ======== }
  139 
  140    !ifne(!env{SHELL})()
  141    (
  142         !comment{ ------ Bash/Shell for Windows found: ------ }
  143         !HighlightSh{!1}{!2}{!3}
  144    )
  145    (
  146         !comment{ ------ We're in Windows CMD: -------------- }
  147         !HighlightCMD{!1}{!2}{!3}
  148    )
  149 ]
  150 [  !comment{ ======== OS Not Windows: ======== }
  151    
  152    !HighlightSh{!1}{!2}{!3}
  153 ]
  154 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  155 
  156 
  157 
  158 
  159 !comment{   !HighlightCMD                                  v2.1 | 2017-10-25 }
  160 ``````````````````````````````````````````````````````````````````````````````
  161 DESCRIPTION: The Win CMD version of !Highlight macro, automatically invoked by
  162             !Highlight after establishing that the current context is Win CMD.
  163             Used for Windows CMD (not Git Bash for Windows).
  164 USAGE:
  165 
  166     !HighlightCMD(LANG)([EXTRA HIGHLIGHT OPTIONS])
  167     ~~~~~~~~~~~~~~~~
  168     BLOCK OF SOURCECODE
  169     ~~~~~~~~~~~~~~~~
  170 
  171 NOTES: This macro creates a temporary file (named “`_pp-tempfileX.tmp`, where
  172        `X` is a numeric counter) in the macros folder (`/pp/macros/`) for each
  173        macro call in the document, to temporarily store the code to highlight.
  174        At each PP invocation the `X` counter is reset, and the previous temp 
  175        files are written over. These temporary files are set to be ignored by 
  176        Git, so you shouldn't worry about them.
  177 ``````````````````````````````````````````````````````````````````````````````
  178 !define(HighlightCMD)
  179 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  180 !add(_HLCounter)
  181 !def(TEMPFILE)(!env(PP_MACROS_PATH)_pp-tempfile!_HLCounter.tmp)
  182 !quiet[!lit(!TEMPFILE)()(!3)]
  183 !quiet[!flushlit]
  184 
  185 <pre class="hl !1"><code class="!1">!exec
  186 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  187 highlight -f -S !1 --no-trailing-nl --validate-input !2 -i !TEMPFILE
  188 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</code></pre>
  189 
  190 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  191 
  192 
  193 
  194 
  195 !comment{   !HighlightSh                                   v2.1 | 2017-10-25 }
  196 ``````````````````````````````````````````````````````````````````````````````
  197 DESCRIPTION: The Shell version of !Highlight macro, automatically invoked by
  198             !Highlight after establishing the current context is Shell/Bash.
  199             Used for Linux, Mac and Git Bash for Windows.
  200 USAGE:
  201 
  202     !HighlightSh(LANG)([EXTRA HIGHLIGHT OPTIONS])
  203     ~~~~~~~~~~~~~~~~
  204     BLOCK OF SOURCECODE
  205     ~~~~~~~~~~~~~~~~
  206 
  207 NOTES: To disable Shell expansion of the sourcecode block (and errors when
  208        it contains backtick characters), the "EOF" delimiter string in the
  209        redirection operator is placed within single quotes:
  210 
  211            cat <<'EOF' |
  212 
  213        (see "Here Documents" for more info)
  214 ``````````````````````````````````````````````````````````````````````````````
  215 !define(   HighlightSh   )
  216 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  217 
  218 <pre class="hl !1"><code class="!1">!sh
  219 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  220 cat <<'EOF' | highlight -f -S !1 --no-trailing-nl --validate-input !2
  221 !3
  222 EOF
  223 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</code></pre>
  224 
  225 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~