~kaijanmaki/+junk/indicators-ng

« back to all changes in this revision

Viewing changes to zinc/python/zinc/util/Markdown-2.6.2/docs/extensions/code_hilite.txt

  • Committer: Antti Kaijanmäki
  • Date: 2015-09-21 20:43:11 UTC
  • Revision ID: antti.kaijanmaki@canonical.com-20150921204311-bnmu8s14n6ovobyu
foo

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
title:      CodeHilite Extension
 
2
prev_title: Admonition Extension
 
3
prev_url:   admonition.html
 
4
next_title: HeaderId Extension
 
5
next_url:   header_id.html
 
6
 
 
7
CodeHilite
 
8
==========
 
9
 
 
10
Summary
 
11
-------
 
12
 
 
13
The CodeHilite extension adds code/syntax highlighting to standard
 
14
Python-Markdown code blocks using [Pygments][].
 
15
 
 
16
[Pygments]: http://pygments.org/
 
17
 
 
18
This extension is included in the standard Markdown library.
 
19
 
 
20
Setup
 
21
-----
 
22
 
 
23
You will also need to [download][dl] and install the Pygments package on your
 
24
`PYTHONPATH`. You will need to determine the appropriate CSS classes and create
 
25
appropriate rules for them, which are either defined in or linked from the
 
26
header of your HTML templates. See the excellent [documentation][] for more
 
27
details. If no language is defined, Pygments will attempt to guess the
 
28
language. When that fails, the code block will not be highlighted.
 
29
 
 
30
[dl]: http://pygments.org/download/
 
31
[documentation]: http://pygments.org/docs
 
32
 
 
33
!!! Note
 
34
    The CSS and/or JavaScript is not included as part of this extension
 
35
    but must be provided by the end user. The Pygments project provides
 
36
    default CSS styles which you may find to be a useful starting point.
 
37
 
 
38
Syntax
 
39
------
 
40
 
 
41
The CodeHilite extension follows the same [syntax][] as regular Markdown code
 
42
blocks, with one exception. The highlighter needs to know what language to use for
 
43
the code block. There are three ways to tell the highlighter what language the
 
44
code block contains and each one has a different result.
 
45
 
 
46
!!! Note
 
47
    The format of the language identifier only effects the display of line numbers
 
48
    if `linenums` is set to `None` (the default). If set to `True` or `False`
 
49
    (see [Usage](#usage) below) the format of the identifier has no effect on the
 
50
    display of line numbers -- it only serves as a means to define the language
 
51
    of the code block.
 
52
 
 
53
[syntax]: http://daringfireball.net/projects/markdown/syntax#precode
 
54
 
 
55
### Shebang (with path) ###
 
56
 
 
57
If the first line of the code block contains a shebang, the language is derived
 
58
from that and line numbers are used.
 
59
 
 
60
        #!/usr/bin/python
 
61
        # Code goes here ...
 
62
 
 
63
Will result in:
 
64
 
 
65
    #!/usr/bin/python
 
66
    # Code goes here ...
 
67
 
 
68
### Shebang (no path) ###
 
69
 
 
70
If the first line contains a shebang, but the shebang line does not contain a
 
71
path (a single `/` or even a space), then that line is removed from the code
 
72
block before processing. Line numbers are used.
 
73
 
 
74
        #!python
 
75
        # Code goes here ...
 
76
 
 
77
Will result in:
 
78
 
 
79
    # Code goes here ...
 
80
 
 
81
### Colons ###
 
82
 
 
83
If the first line begins with three or more colons, the text following the
 
84
colons identifies the language. The first line is removed from the code block
 
85
before processing and line numbers are not used.
 
86
 
 
87
        :::python
 
88
        # Code goes here ...
 
89
 
 
90
Will result in:
 
91
 
 
92
    # Code goes here ...
 
93
 
 
94
Certain lines can be selected for emphasis with the colon syntax. When 
 
95
using Pygments' default CSS styles, emphasized lines have a yellow background. 
 
96
This is useful to direct the reader's attention to specific lines.
 
97
 
 
98
    :::python hl_lines="1 3"
 
99
    # This line is emphasized
 
100
    # This line isn't
 
101
    # This line is emphasized
 
102
 
 
103
!!! Note
 
104
    `hl_lines` is named for Pygments' option meaning "highlighted lines".
 
105
 
 
106
### When No Language is Defined ###
 
107
 
 
108
CodeHilite is completely backwards compatible so that if a code block is
 
109
encountered that does not define a language, the block is simply wrapped in
 
110
`<pre>` tags and output. 
 
111
 
 
112
        # Code goes here ...
 
113
 
 
114
Will result in:
 
115
 
 
116
    # Code goes here ...
 
117
 
 
118
Lets see the source for that:
 
119
 
 
120
    <div class="codehilite"><pre><code># Code goes here ...
 
121
    </code></pre></div>
 
122
 
 
123
!!! Note
 
124
    When no language is defined, the Pygments highlighting engine will try to guess 
 
125
    the language (unless `guess_lang` is set to `False`). Upon failure, the same 
 
126
    behavior will happen as described above.
 
127
 
 
128
Usage
 
129
-----
 
130
 
 
131
See [Extensions](index.html) for general extension usage, specify `markdown.extensions.codehilite`
 
132
as the name of the extension.
 
133
 
 
134
See the [Library Reference](../reference.html#extensions) for information about
 
135
configuring extensions.
 
136
 
 
137
The following options are provided to configure the output:
 
138
 
 
139
* **`linenums`**:
 
140
    Use line numbers. Possible values are `True` for yes, `False` for no and
 
141
    `None` for auto. Defaults to `None`.
 
142
 
 
143
    Using `True` will force every code block to have line numbers, even when
 
144
    using colons (`:::`) for language identification.
 
145
 
 
146
    Using `False` will turn off all line numbers, even when using shebangs
 
147
    (`#!`) for language identification.
 
148
 
 
149
* **`guess_lang`**:
 
150
    Automatic language detection. Defaults to `True`.
 
151
 
 
152
    Using `False` will prevent Pygments from guessing the language, and thus
 
153
    highlighting blocks only when you explicitly set the language.
 
154
 
 
155
* **`css_class`**:
 
156
    Set CSS class name for the wrapper `<div>` tag. Defaults to
 
157
    `codehilite`.
 
158
 
 
159
* **`pygments_style`**:
 
160
    Pygments HTML Formatter Style (`ColorScheme`). Defaults to `default`.
 
161
 
 
162
    !!! Note
 
163
        This is useful only when `noclasses` is set to `True`, otherwise the
 
164
        CSS styles must be provided by the end user.
 
165
 
 
166
* **`noclasses`**:
 
167
    Use inline styles instead of CSS classes. Defaults to `False`.
 
168
 
 
169
* **`use_pygments`**:
 
170
    Defaults to `True`. Set to `False` to disable the use of Pygments.
 
171
    If a language is defined for a code block, it will be assigned to the
 
172
    `<code>` tag as a class in the manner suggested by the [HTML5 spec][spec]
 
173
    (alternate output will not be entertained) and might be used by a JavaScript
 
174
    library in the browser to highlight the code block.
 
175
 
 
176
[spec]: http://www.w3.org/TR/html5/text-level-semantics.html#the-code-element