Anonymous avatar Anonymous committed 48b8f03

[svn] Add a section on directive options.

Comments (0)

Files changed (1)


         your code here
+If you want to have two or more variants of the directive, you can utilize
+ReST *directive options*, like so:
+.. sourcecode:: python
+    normal_fmter = HtmlFormatter()
+    lineno_fmter = HtmlFormatter(linenos=True)
+    def pygments_directive(name, arguments, options, content, lineno,
+                           content_offset, block_text, state, state_machine):
+        try:
+            lexer = get_lexer_by_name(arguments[0])
+        except ValueError:
+            # no lexer found - use the text one instead of an exception
+            lexer = get_lexer_by_name('text')
+	formatter = ('linenos' in options) and lineno_fmter ornormal_fmter
+        parsed = highlight(u'\n'.join(content), lexer, formatter)
+        return [nodes.raw('', parsed, format='html')]
+    pygments_directive.arguments = (1, 0, 1)
+    pygments_directive.content = 1
+    pygments_directive.options = {'linenos': directives.flag}
+    directives.register_directive('sourcecode', pygments_directive)
+And use it like so::
+    .. sourcecode:: language
+       :linenos:
+       the code starts here...
+Look at the `directive documentation`_ to get all the gory details.
 *Loosely related note:* The ReST lexer now recognizes ``.. sourcecode::`` and
 ``.. code::`` directives and highlights the contents in the specified language
 if the `handlecodeblocks` option is true.
 .. _ReST:
+.. _directive documentation:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.