Skip to content

Commit

Permalink
Filter out Fold markers.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ypid committed Jun 6, 2016
1 parent 19868a2 commit 3702f9b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions yaml2rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) * ' '
Expand Down

0 comments on commit 3702f9b

Please sign in to comment.