[Checkins] SVN: manuel/trunk/src/manuel/ add support for docutils-style code blocks
Benji York
cvs-admin at zope.org
Wed Feb 13 21:50:39 UTC 2013
Log message for revision 129362:
add support for docutils-style code blocks
Changed:
U manuel/trunk/src/manuel/codeblock.py
U manuel/trunk/src/manuel/index.txt
-=-
Modified: manuel/trunk/src/manuel/codeblock.py
===================================================================
--- manuel/trunk/src/manuel/codeblock.py 2013-02-13 21:24:17 UTC (rev 129361)
+++ manuel/trunk/src/manuel/codeblock.py 2013-02-13 21:50:39 UTC (rev 129362)
@@ -3,14 +3,15 @@
import textwrap
CODEBLOCK_START = re.compile(
- r'(^\.\.\s*(invisible-)?code-block::?\s*python\b(?:\s*\:\w+\:)*)',
+ r'(^\.\.\s*(invisible-)?code(-block)?::?\s*python\b(?:\s*\:\w+\:.*\n)*)',
re.MULTILINE)
CODEBLOCK_END = re.compile(r'(\n\Z|\n(?=\S))')
class CodeBlock(object):
- def __init__(self, code):
+ def __init__(self, code, source):
self.code = code
+ self.source = source
def find_code_blocks(document):
@@ -20,7 +21,7 @@
source_location = '%s:%d' % (document.location, region.lineno)
code = compile(source, source_location, 'exec', 0, True)
document.claim_region(region)
- region.parsed = CodeBlock(code)
+ region.parsed = CodeBlock(code, source)
def execute_code_block(region, document, globs):
Modified: manuel/trunk/src/manuel/index.txt
===================================================================
--- manuel/trunk/src/manuel/index.txt 2013-02-13 21:24:17 UTC (rev 129361)
+++ manuel/trunk/src/manuel/index.txt 2013-02-13 21:50:39 UTC (rev 129362)
@@ -429,6 +429,50 @@
particular block.
+.. reset-globs
+
+Docutils Code Blocks
+--------------------
+
+Sphinx and docutils have different ideas of how code blocks should be spelled.
+Manuel supports the docutils-style code blocks too.
+
+::
+
+ .. code:: python
+
+ a = 1
+
+.. -> source
+
+ >>> import manuel
+ >>> document = manuel.Document(source)
+ >>> import manuel.codeblock
+ >>> m = manuel.codeblock.Manuel()
+ >>> document.parse_with(m)
+ >>> for region in document:
+ ... print((region.lineno, region.parsed or region.source))
+ (1, <manuel.codeblock.CodeBlock object...>)
+
+Docutils options after the opening of the code block are also allowed::
+
+ .. code:: python
+ :class: hidden
+
+ a = 1
+
+.. -> source
+
+ >>> import manuel
+ >>> document = manuel.Document(source)
+ >>> import manuel.codeblock
+ >>> m = manuel.codeblock.Manuel()
+ >>> document.parse_with(m)
+ >>> for region in document:
+ ... print((region.lineno, region.parsed, region.parsed.source))
+ (1, <manuel.codeblock.CodeBlock object...>, '\na = 1\n')
+
+
Invisible Code Blocks
---------------------
More information about the checkins
mailing list