diff --git a/Makefile b/Makefile index 1093888..62cdf94 100644 --- a/Makefile +++ b/Makefile @@ -53,7 +53,8 @@ dist: examples: PYTHONPATH = . examples: PYTHONPATH=. - sed --regexp-extended 's/(\.\. )envvar(::)/\1note\2/;' examples/fold-markers-debops.yml examples/main.yml | bin/yaml2rst - examples/main.rst --strip-regex '\s*(:?\[{3}|\]{3})\d?$$' + sed --regexp-extended 's/(\.\. )envvar(::)/\1note\2/;' examples/fold-markers-debops.yml examples/main.yml \ + | bin/yaml2rst - examples/main.rst --strip-regex '\s*(:?\[{3}|\]{3})\d?$$' --yaml-strip-regex '^\s{65,66}#\s\]{3}\d?$$' ## --no-generator does not do the trick on Debian Jessie. rst2html --stylesheet=examples/demo.css examples/main.rst | grep --invert-match --fixed-strings ' examples/main.html rst2html --stylesheet=examples/demo.css tests/patternsTest.rst > tests/patternsTest.html diff --git a/bin/yaml2rst b/bin/yaml2rst index 16344fb..0a14af0 100755 --- a/bin/yaml2rst +++ b/bin/yaml2rst @@ -32,7 +32,7 @@ import argparse import sys -def main(infilename, outfilename, strip_regex): +def main(infilename, outfilename, strip_regex, yaml_strip_regex): if infilename == '-': infh = sys.stdin else: @@ -41,7 +41,7 @@ def main(infilename, outfilename, strip_regex): outfh = sys.stdout else: outfh = open(outfilename, "w") - for l in yaml2rst.convert(infh.readlines(), strip_regex): + for l in yaml2rst.convert(infh.readlines(), strip_regex, yaml_strip_regex): print(l.rstrip(), file=outfh) @@ -55,5 +55,8 @@ parser.add_argument('--strip-regex', metavar='regex', " Can be used to remove fold markers from headings for example." " Example to strip out [[[,]]] fold markers: '\s*(:?\[{3}|\]{3})\d?$'." " Check the README for more details.") +parser.add_argument('--yaml-strip-regex', metavar='regex', + help="Same usage as --strip-regex except that this regex substitution" + "is preformed on the YAMl part of the file as opposed RST part.") args = parser.parse_args() main(**vars(args)) diff --git a/examples/main.html b/examples/main.html index 08fbea1..3000800 100644 --- a/examples/main.html +++ b/examples/main.html @@ -74,8 +74,6 @@

Main configuration

Some text describing this boolean.

 example__enabled: True
-
-                                                                  # ]]]
 

Note

@@ -84,8 +82,6 @@

Main configuration

List of additional APT packages which will be installed by the role.

 example__packages: []
-                                                                  # ]]]
-                                                                  # ]]]
 
@@ -97,9 +93,6 @@

Something

Some text describing this list.

 example__periodic: []
-                                                                  # ]]]
-                                                                  # ]]]
-                                                                  # ]]]
 
diff --git a/examples/main.rst b/examples/main.rst index c778ae7..c1cf7d4 100644 --- a/examples/main.rst +++ b/examples/main.rst @@ -18,7 +18,7 @@ Some text describing this boolean. example__enabled: True - # ]]] + .. note:: example__packages @@ -26,8 +26,8 @@ List of additional APT packages which will be installed by the role. :: example__packages: [] - # ]]] - # ]]] + + Something ------------- @@ -38,9 +38,9 @@ Some text describing this list. :: example__periodic: [] - # ]]] - # ]]] - # ]]] + + + collectd ================ diff --git a/yaml2rst.py b/yaml2rst.py index ab072cc..5e7073c 100644 --- a/yaml2rst.py +++ b/yaml2rst.py @@ -98,7 +98,7 @@ def get_stripped_line(line, strip_regex): return line -def convert(lines, strip_regex): +def convert(lines, strip_regex, yaml_strip_regex): state = STATE_TEXT last_text_line = '' last_indent = '' @@ -124,16 +124,17 @@ def convert(lines, strip_regex): if not last_text_line.endswith('::'): yield last_indent + '::' yield '' + line = get_stripped_line(line, yaml_strip_regex) yield last_indent + ' ' + line state = STATE_YAML -def convert_text(yaml_text, strip_regex=None): - return '\n'.join(convert(yaml_text.splitlines(), strip_regex)) +def convert_text(yaml_text, strip_regex=None, yaml_strip_regex=None): + return '\n'.join(convert(yaml_text.splitlines(), strip_regex, yaml_strip_regex)) -def convert_file(infilename, outfilename, strip_regex=None): +def convert_file(infilename, outfilename, strip_regex=None, yaml_strip_regex=None): with open(infilename) as infh: with open(outfilename, "w") as outfh: - for l in convert(infh.readlines(), strip_regex): + for l in convert(infh.readlines(), strip_regex, yaml_strip_regex): print(l.rstrip(), file=outfh)