Sophie

Sophie

distrib > Mageia > 5 > x86_64 > media > core-release > by-pkgid > 475047415fcf83c129d0834cea9418c4 > files > 115

python3-markdown-2.4.1-4.mga5.noarch.rpm

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>CodeHilite Extension &#8212; Python Markdown</title>
<link rel="stylesheet" href="../default.css" type="text/css">
</head>
<body>

<div class="related">
  <h3>Navigation</h3>
  <ul>
    <li class="right" style="margin-right: 10px">
      <a href="../siteindex.html" title="General Index">index</a></li>
    <li class="right">
      <a href="header_id.html" title="HeaderId Extension"
         accesskey="N">next</a> |</li>
    <li class="right">
      <a href="admonition.html" title="Admonition Extension"
         accesskey="P">previous</a> |</li>
    <li><img src="../py.png" alt=""
             style="vertical-align: middle; margin-top: -1px"/></li>
    <li><a href="../index.html">Python Markdown v2.4.1 documentation</a> &raquo;</li>
    <li><a href="index.html">Extensions</a> &raquo;</li>
<li><a href="code_hilite.html">CodeHilite Extension</a> &raquo;</li>
  </ul>
</div> <!-- .related -->

<div class="document">
  <div class="documentwrapper">
    <div class="bodywrapper">
      <div class="body">
<h1 id="codehilite">CodeHilite<a class="headerlink" href="#codehilite" title="Permanent link">&para;</a></h1>
<h2 id="summary">Summary<a class="headerlink" href="#summary" title="Permanent link">&para;</a></h2>
<p>The CodeHilite extension adds code/syntax highlighting to standard
Python-Markdown code blocks using <a href="http://pygments.org/">Pygments</a>.</p>
<p>This extension is included in the standard Markdown library.</p>
<h2 id="setup">Setup<a class="headerlink" href="#setup" title="Permanent link">&para;</a></h2>
<p>You will also need to <a href="http://pygments.org/download/">download</a> and install the Pygments package on your
<code>PYTHONPATH</code>. You will need to determine the appropriate CSS classes and create
appropriate rules for them, which are either defined in or linked from the
header of your HTML templates. See the excellent <a href="http://pygments.org/docs">documentation</a> for more
details. If no language is defined, Pygments will attempt to guess the
language. When that fails, the code block will display as un-highlighted code.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The css and/or javascript is not included as part of this extension
but must be provided by the end user. The Pygments project provides
default css styles which you may find to be a useful starting point.</p>
</div>
<h2 id="syntax">Syntax<a class="headerlink" href="#syntax" title="Permanent link">&para;</a></h2>
<p>The CodeHilite extension follows the same <a href="http://daringfireball.net/projects/markdown/syntax#precode">syntax</a> as regular Markdown code
blocks, with one exception. The hiliter needs to know what language to use for
the code block. There are three ways to tell the hiliter what language the code
block contains and each one has a different result.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The format of the language identifier only effects the display of line numbers
if <code>linenums</code> is set to <code>None</code> (the default). If set to <code>True</code> or <code>False</code>
(see <a href="#usage">Usage</a> below) the format of the identifier has no effect on the
display of line numbers &ndash; it only serves as a means to define the language
of the code block.</p>
</div>
<h3 id="shebang-with-path">SheBang (with path)<a class="headerlink" href="#shebang-with-path" title="Permanent link">&para;</a></h3>
<p>If the first line of the codeblock contains a shebang, the language is derived
from that and line numbers are used.</p>
<pre><code>    #!/usr/bin/python
    # Code goes here ...
</code></pre>
<p>Will result in:</p>
<pre><code>#!/usr/bin/python
# Code goes here ...
</code></pre>
<h3 id="shebang-no-path">SheBang (no path)<a class="headerlink" href="#shebang-no-path" title="Permanent link">&para;</a></h3>
<p>If the first line contains a shebang, but the shebang line does not contain a
path (a single <code>/</code> or even a space), then that line is removed from the code
block before processing. Line numbers are used.</p>
<pre><code>    #!python
    # Code goes here ...
</code></pre>
<p>Will result in:</p>
<pre><code># Code goes here ...
</code></pre>
<h3 id="colons">Colons<a class="headerlink" href="#colons" title="Permanent link">&para;</a></h3>
<p>If the first line begins with three or more colons, the text following the
colons identifies the language. The first line is removed from the code block
before processing and line numbers are not used.</p>
<pre><code>    :::python
    # Code goes here ...
</code></pre>
<p>Will result in:</p>
<pre><code># Code goes here ...
</code></pre>
<p>Certain lines can be selected for emphasis with the colon syntax. When 
using Pygments&rsquo; default css styles, emphasized lines have a yellow background. 
This is useful to direct the reader&rsquo;s attention to specific lines.</p>
<pre><code>:::python hl_lines="1 3"
# This line is emphasized
# This line isn't
# This line is emphasized
</code></pre>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p><code>hl_lines</code> is named for Pygments&rsquo; option meaning &ldquo;highlighted lines&rdquo;.</p>
</div>
<h3 id="when-no-language-is-defined">When No Language is Defined<a class="headerlink" href="#when-no-language-is-defined" title="Permanent link">&para;</a></h3>
<p>CodeHilite is completely backwards compatible so that if a code block is
encountered that does not define a language, the block is simply wrapped in
<code>&lt;pre&gt;</code> tags and output. </p>
<pre><code>    # Code goes here ...
</code></pre>
<p>Will result in:</p>
<pre><code># Code goes here ...
</code></pre>
<p>Lets see the source for that:</p>
<pre><code>&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;code&gt;# Code goes here ...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</code></pre>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>When no language is defined, the Pygments highlighting engine will try to guess 
the language (unless <code>guess_lang</code> is set to <code>False</code>). Upon failure, the same 
behavior will happen as described above.</p>
</div>
<h2 id="usage">Usage<a class="headerlink" href="#usage" title="Permanent link">&para;</a></h2>
<p>See <a href="index.html">Extensions</a> for general extension usage, specify <code>codehilite</code>
as the name of the extension.</p>
<p>See the <a href="../reference.html#extensions">Library Reference</a> for information about
configuring extensions.</p>
<p>The following options are provided to configure the output:</p>
<ul>
<li>
<p><strong><code>linenums</code></strong>:
    Use line numbers. Possible values are <code>True</code> for yes, <code>False</code> for no and
    <code>None</code> for auto. Defaults to <code>None</code>.</p>
<p>Using <code>True</code> will force every code block to have line numbers, even when
using colons (<code>:::</code>) for language identification.</p>
<p>Using <code>False</code> will turn off all line numbers, even when using SheBangs
(<code>#!</code>) for language identification.</p>
</li>
<li>
<p><strong><code>guess_lang</code></strong>:
    Automatic language detection. Defaults to <code>True</code>.</p>
<p>Using <code>False</code> will prevent Pygments from guessing the language, and thus
highlighting blocks only when you explicitly set the language.</p>
</li>
<li>
<p><strong><code>css_class</code></strong>:
    Set CSS class name for the wrapper <code>&lt;div&gt;</code> tag. Defaults to
    <code>codehilite</code>.</p>
</li>
<li>
<p><strong><code>pygments_style</code></strong>:
    Pygments HTML Formatter Style (ColorScheme). Defaults to <code>default</code>.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>This is useful only when <code>noclasses</code> is set to <code>True</code>, otherwise the
CSS styles must be provided by the end user.</p>
</div>
</li>
<li>
<p><strong><code>noclasses</code></strong>:
    Use inline styles instead of CSS classes. Defaults to <code>False</code>.</p>
</li>
</ul>
      </div> <!-- .body -->
    </div> <!-- .bodywrapper -->
  </div> <!-- .documentwrapper -->

  <div class="sphinxsidebar">
    <div class="sphinxsidebarwrapper">
    <h3>Table Of Contents</h3>
    <div class="toc">
<ul>
<li><a href="#codehilite">CodeHilite</a><ul>
<li><a href="#summary">Summary</a></li>
<li><a href="#setup">Setup</a></li>
<li><a href="#syntax">Syntax</a><ul>
<li><a href="#shebang-with-path">SheBang (with path)</a></li>
<li><a href="#shebang-no-path">SheBang (no path)</a></li>
<li><a href="#colons">Colons</a></li>
<li><a href="#when-no-language-is-defined">When No Language is Defined</a></li>
</ul>
</li>
<li><a href="#usage">Usage</a></li>
</ul>
</li>
</ul>
</div>


    <h4>Previous topic</h4>
      <p class="topless"><a href="admonition.html"
         title="previous chapter">Admonition Extension</a></p>
    <h4>Next topic</h4>
      <p class="topless"><a href="header_id.html"
         title="next chapter">HeaderId Extension</a></p>
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="https://github.com/waylan/Python-Markdown/issues"
             >Report a Bug</a></li>
      <li><a href="code_hilite.txt"
             rel="nofollow">Show Source</a></li>
    </ul>
    </div> <!-- .sphinxsidebarwrapper -->
  </div> <!-- .sphinxsidebar -->

  <div class="clearer"></div>
</div> <!-- .document -->

<div class="related">
  <h3>Navigation</h3>
  <ul>
    <li class="right" style="margin-right: 10px">
      <a href="../siteindex.html" title="General Index">index</a></li>
    <li class="right">
      <a href="header_id.html" title="HeaderId Extension"
         accesskey="N">next</a> |</li>
    <li class="right">
      <a href="admonition.html" title="Admonition Extension"
         accesskey="P">previous</a> |</li>
    <li><img src="../py.png" alt=""
             style="vertical-align: middle; margin-top: -1px"/></li>
    <li><a href="../index.html">Python Markdown v2.4.1 documentation</a> &raquo;</li>
    <li><a href="index.html">Extensions</a> &raquo;</li>
<li><a href="code_hilite.html">CodeHilite Extension</a> &raquo;</li>
  </ul>
</div> <!-- .related -->

<div class="footer">&copy; 2010-2012 Python Markdown Project</div>
</body>
</html>