Skip to content

WikiRestructuredText

JBBgameich edited this page May 1, 2018 · 2 revisions

reStructuredText Support in Trac

Trac supports using reStructuredText (RST) as an alternative to wiki markup in any context WikiFormatting is used.

From the reStucturedText webpage:

"reStructuredText is an easy-to-read, what-you-see-is-what-you-get plaintext markup syntax and parser system. It is useful for in-line program documentation (such as Python docstrings), for quickly creating simple web pages, and for standalone documents. reStructuredText is designed for extensibility for specific application domains. "

If you want a file from your Subversion repository be displayed as reStructuredText in Trac's source browser, set text/x-rst as value for the Subversion property svn:mime-type. See this example.

Requirements

Note that to activate RST support in Trac, the python docutils package must be installed. If not already available on your operating system, you can download it at the RST Website.

Install docutils using easy_install docutils. Do not use the package manager of your OS (e.g. apt-get install python-docutils), because Trac will not find docutils then.

More information on RST


Using RST in Trac

To specify that a block of text should be parsed using RST, use the rst processor.

TracLinks in reStructuredText

  • Trac provides a custom RST directive trac:: to allow TracLinks from within RST text.

+-----------------------------------+-----------------------------------+ | Wiki Markup | Display | +===================================+===================================+ | {.wiki} | <div class="document"> | | {{{ | | | #!rst | This is a reference to | | This is a reference to |a ticket| | <a href="/ticket/42" class="refer | | | ence external">#42</a> | | .. |a ticket| trac:: #42 | | | }}} | </div> | | | | +-----------------------------------+-----------------------------------+

  • Trac allows an even easier way of creating TracLinks in RST, using the custom :trac: role.

+-----------------------------------+-----------------------------------+ | Wiki Markup | Display | +===================================+===================================+ | {.wiki} | <div class="document"> | | {{{ | | | #!rst | This is a reference to ticket | | This is a reference to ticket `#1 | <a href="/ticket/12" class="refer | | 2`:trac: | ence external">#12</a> | | | | | To learn how to use Trac, see `Tr | To learn how to use Trac, see | | acGuide`:trac: | <a href="TracGuide.html" class="r | | }}} | eference external">TracGuide</a> | | | | | |

| +-----------------------------------+-----------------------------------+

For a complete example of all uses of the :trac: role, please see WikiRestructuredTextLinks.

Syntax highlighting in reStructuredText

There is a directive for doing TracSyntaxColoring in RST as well. The directive is called code-block

+-----------------------------------+-----------------------------------+ | Wiki Markup | Display | +===================================+===================================+ | {.wiki} | <div class="document"> | | {{{ | | | #!rst | <div class="code"> | | | | | .. code-block:: python | class Test: | | | def TestFunction(self): | | class Test: | pass | | | | | def TestFunction(self): | </div> | | pass | | | | </div> | | }}} | | | | | +-----------------------------------+-----------------------------------+

Note the need to indent the code at least one character after the .. code-block directive.

Wiki Macros in reStructuredText

For doing Wiki Macros in RST you use the same directive as for syntax highlighting i.e code-block.

+-----------------------------------+-----------------------------------+ | Wiki Markup | Display | +===================================+===================================+ | {.wiki} | <div class="document"> | | {{{ | | | #!rst | <div> | | | | | .. code-block:: RecentChanges | ### 03.11.2012 | | | | | Trac,3 | - [TracIni](/wiki/TracIni) | | | ([diff](/wiki/TracIni?action= | | }}} | diff&version=6)) | | | - [TracSyntaxColoring](/wiki/Tr | | | acSyntaxColoring) | | | ([diff](/wiki/TracSyntaxColor | | | ing?action=diff&version=6)) | | | - TracAdmin | | | ([diff](/wiki/TracAdmin?actio | | | n=diff&version=6)) | | | | | | | | | | | | | +-----------------------------------+-----------------------------------+

Or a more concise Wiki Macro like syntax is also available, using the :code-block: role:

+-----------------------------------+-----------------------------------+ | Wiki Markup | Display | +===================================+===================================+ | {.wiki} | <div class="document"> | | {{{ | | | #!rst | <div> | | | | | :code-block:`RecentChanges:Trac,3 | ### 03.11.2012 | | ` | | | }}} | - [TracIni](/wiki/TracIni) | | | ([diff](/wiki/TracIni?action= | | | diff&version=6)) | | | - [TracSyntaxColoring](/wiki/Tr | | | acSyntaxColoring) | | | ([diff](/wiki/TracSyntaxColor | | | ing?action=diff&version=6)) | | | - TracAdmin | | | ([diff](/wiki/TracAdmin?actio | | | n=diff&version=6)) | | | | | | | | | | | | | +-----------------------------------+-----------------------------------+

Bigger RST Example

The example below should be mostly self-explanatory:

+-----------------------------------+-----------------------------------+ | Wiki Markup | Display | +===================================+===================================+ | {.wiki} | <div id="foobar-header" | | {{{ | class="document"> | | #!rst | | | FooBar Header | reStructuredText is **nice**. It | | ============= | has its own | | reStructuredText is **nice**. It | <a href="http://docutils.sourcefo | | has its own webpage_. | rge.net/rst.html" class="referenc | | | e external">webpage</a>. | | A table: | | | | A table: | | ===== ===== ====== | | | Inputs Output | Inputs | | ------------ ------ | Output | | A B A or B | A | | ===== ===== ====== | B | | False False False | A or B | | True False True | False | | False True True | False | | True True True | False | | ===== ===== ====== | True | | | False | | RST TracLinks | True | | ------------- | False | | | True | | See also ticket `#42`:trac:. | True | | | True | | .. _webpage: http://docutils.sour | True | | ceforge.net/rst.html | True | | }}} | <div id="rst-traclinks" | | | class="section"> | | | | | | RST TracLinks | | | ============= | | | | | | See also ticket | | | #42. | | | | | | | | | | | | | +-----------------------------------+-----------------------------------+


See also: WikiRestructuredTextLinks, WikiProcessors, WikiFormatting

Clone this wiki locally