mirror of
https://github.com/clearlinux/clear-linux-documentation.git
synced 2026-06-29 17:26:01 +00:00
added ability to create a list of code blocks to parse
This commit is contained in:
@@ -3,19 +3,26 @@ Usage: python code-blocks.py path/to/file.rst
|
||||
|
||||
Default output is to stdout
|
||||
|
||||
Parses bash code blocks out of rst file for instruction testing.
|
||||
Parses all code found in blocks listed in blockTypes out of rst file for instruction testing.
|
||||
'''
|
||||
import sys
|
||||
|
||||
blockTypes = ["bash","console"]
|
||||
|
||||
def code_blocks(filename):
|
||||
with open(filename, 'r') as fd:
|
||||
c_indent = ''
|
||||
in_section = []
|
||||
for line in fd:
|
||||
blockFound = False
|
||||
indent = line[:len(line) - len(line.lstrip())]
|
||||
if 'code-block:: bash' in line:
|
||||
for blockType in blockTypes:
|
||||
if 'code-block:: ' + blockType in line:
|
||||
blockFound = True
|
||||
if blockFound:
|
||||
in_section = [line.strip()]
|
||||
c_indent = ''
|
||||
blockFound = False
|
||||
elif in_section:
|
||||
if not c_indent and line.strip():
|
||||
c_indent = indent
|
||||
|
||||
Reference in New Issue
Block a user