mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add backslash line continuation to productionlist
Fixes sphinx-doc/sphinx#1027
This commit is contained in:
1
CHANGES
1
CHANGES
@@ -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
|
||||
----------
|
||||
|
||||
@@ -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
|
||||
|
||||
6
tests/roots/test-productionlist/LineContinuation.rst
Normal file
6
tests/roots/test-productionlist/LineContinuation.rst
Normal file
@@ -0,0 +1,6 @@
|
||||
LineContinuation
|
||||
================
|
||||
|
||||
.. productionlist:: lineContinuation
|
||||
A: B C D \
|
||||
E F G
|
||||
@@ -6,6 +6,7 @@
|
||||
Dup1
|
||||
Dup2
|
||||
firstLineRule
|
||||
LineContinuation
|
||||
|
||||
- A: :token:`A`
|
||||
- B: :token:`B`
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user