Add backslash line continuation to productionlist

Fixes sphinx-doc/sphinx#1027
This commit is contained in:
Jakob Lykke Andersen
2020-01-22 22:51:22 +01:00
parent c084c3f124
commit bcbb167b0d
5 changed files with 19 additions and 1 deletions

View File

@@ -44,6 +44,7 @@ Features added
:py:meth:`.Sphinx.connect()`
* #3077: Implement the scoping for :rst:dir:`productionlist` as indicated
in the documentation.
* #1027: Support backslash line continuation in :rst:dir:`productionlist`.
Bugs fixed
----------

View File

@@ -439,9 +439,16 @@ class ProductionList(SphinxDirective):
def run(self) -> List[Node]:
domain = cast(StandardDomain, self.env.get_domain('std'))
node = addnodes.productionlist() # type: Element
# The backslash handling is from ObjectDescription.get_signatures
nl_escape_re = re.compile(r'\\\n')
strip_backslash_re = re.compile(r'\\(.)')
lines = nl_escape_re.sub('', self.arguments[0]).split('\n')
# remove backslashes to support (dummy) escapes; helps Vim highlighting
lines = [strip_backslash_re.sub(r'\1', line.strip()) for line in lines]
productionGroup = ""
i = 0
for rule in self.arguments[0].split('\n'):
for rule in lines:
if i == 0 and ':' not in rule:
productionGroup = rule.strip()
continue

View File

@@ -0,0 +1,6 @@
LineContinuation
================
.. productionlist:: lineContinuation
A: B C D \
E F G

View File

@@ -6,6 +6,7 @@
Dup1
Dup2
firstLineRule
LineContinuation
- A: :token:`A`
- B: :token:`B`

View File

@@ -370,3 +370,6 @@ def test_productionlist(app, status, warning):
('FirstLine', 'firstLineRule.html#grammar-token2-_firstline', 'FirstLine'),
('SecondLine', 'firstLineRule.html#grammar-token2-_secondline', 'SecondLine'),
]
text = (app.outdir / 'LineContinuation.html').text()
assert "A</strong> ::= B C D E F G" in text