From 3702f9b9c92a5ec98d3b6f4b8be2fb3ec130052b Mon Sep 17 00:00:00 2001 From: Robin Schneider Date: Sat, 28 May 2016 18:09:50 +0200 Subject: [PATCH] Filter out Fold markers. It started out when I introduced more and more fold markers to the DebOps project. I used `(((` as marker because it was not highlighted by my editor as being a Jinja2 control sequence. The fold marker as turned out to be not-optimal because it also appears in complex Jinja2 conditions quite often. So @drybjed and me settled on `[[[`. The problem was, however, that we always needed to introduce additional redundancy to the files. Example: ```YAML --- ``` @drybjed and I discussed this and agreed that the best thing would be to patch up `yaml2rst` to filter out the fold marker which would allow it to be directly appended after headings for instance. Example: ```YAML --- ``` With this patch, this input gets converted into: ```reStructuredText .. vim: foldmarker=[[[,]]]:foldmethod=marker Default variables ================= .. contents:: Sections :local: ---------------------- Role configuration ---------------------- ``` Can we make this the default behavior or should it be made optional? I limited the regex to only match a very defined set of occurrences. --- examples/main.yml | 2 +- yaml2rst.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/main.yml b/examples/main.yml index 6eb1d57..d71f913 100644 --- a/examples/main.yml +++ b/examples/main.yml @@ -88,7 +88,7 @@ collectd_plugins_default_config: IgnoreSelected true # -# Indention of Literal Blocks behind Lists +# Indention of Literal Blocks behind Lists [[[1 # ----------------------------------------- # # Code will properly be indented after lists: diff --git a/yaml2rst.py b/yaml2rst.py index 6b4c429..9e04b0e 100644 --- a/yaml2rst.py +++ b/yaml2rst.py @@ -104,6 +104,9 @@ def convert(lines): elif line.startswith('# ') or line == '#': if state != STATE_TEXT: yield '' + # Filter out [[[\d and ]]] at the end of a documentation line. + # Those sequences can be used for folding sections. + line = re.sub(r"\s*(:?\[{3}|\]{3})\d?$", "", line) line = last_text_line = line[2:] yield line last_indent = get_indent(line) * ' '