✨ Add the eval-rst directive#226
Conversation
|
Thanks for submitting your first pull request! You are awesome! 🤗 |
Codecov Report
@@ Coverage Diff @@
## master #226 +/- ##
==========================================
- Coverage 91.00% 90.92% -0.08%
==========================================
Files 12 12
Lines 1301 1323 +22
==========================================
+ Hits 1184 1203 +19
- Misses 117 120 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
|
Thanks @stephenroller! a few points: Can you make it The I think error reporting won't quite work correctly at present though. I think this could work, which is along the lines of what I do in myst_parser/mocking.py:
for node in newdoc.traverse():
if node.line:
node.line += token.map[0] |
|
Also in https://github.com/chrisjsewell/docutils/blob/8adab0660b2097b4f3c32cef7e5ff4cb3c72b084/docutils/docutils/parsers/rst/__init__.py#L193-L194, I note the rST parser removes the default role. class CustomParser(Parser):
def parse(self, inputstring, document, reporter):
"""Parse `inputstring` and populate `document`, a document tree."""
self.inputstring = inputstring
self.document = document
self.reporter = reporter
self.statemachine = states.RSTStateMachine(
state_classes=self.state_classes,
initial_state=self.initial_state,
debug=document.reporter.debug_flag)
inputlines = docutils.statemachine.string2lines(
inputstring, tab_width=document.settings.tab_width,
convert_whitespace=True)
self.statemachine.run(inputlines, document, inliner=self.inliner) |
|
We might even able to "spoof" the line number reporting at this point, like class CustomParser(Parser):
def parse(self, inputstring, document, reporter, directive_line):
"""Parse `inputstring` and populate `document`, a document tree."""
self.inputstring = inputstring
self.document = document
self.reporter = reporter
self.statemachine = states.RSTStateMachine(
state_classes=self.state_classes,
initial_state=self.initial_state,
debug=document.reporter.debug_flag)
inputlines = docutils.statemachine.string2lines(
inputstring, tab_width=document.settings.tab_width,
convert_whitespace=True)
inputlines = ["" for _ in range(directive_line)] + inputlines
self.statemachine.run(inputlines, document, inliner=self.inliner, input_offset=directive_line) |
|
Oh and also maybe set the document language: newdoc.settings.language_code = document.settings.language_code |
|
So just a few things for you to do there 😆 |
|
Setting source and doing the line adjustments as suggested works. I think I've got references working but the sphinx tests don't build locally for me. Pushing to see what CI says. Not sure I understand what that side effect you pointed out is. Could you clarify? (It looks quite innocuous...) |
|
thanks
So in RST the syntax for literal strings is with two |
You need to update the pytest-regressions file, try running (or |
|
thanks @stephenroller for this PR -- this will be useful. This is more for discussion than a suggested change. Is there any reason we couldn't just name the directive Directive: vs. Syntax Highlighting: Also, many of the core @choldgraf @chrisjsewell should we adopt a naming standard / convention for directives for consistency and add it to CONTRIBUTING.md? |
Yeh thats probably better 👍 |
|
Alright I think I addressed all the comments. From the coverage, you can see the empty role block is never being hit; not sure why that is. |
Ok ta, so basically the final thing are what is the warnings you get for: |
|
After the commit I just added: |
|
thats the one 😄 so you can just add this to the bottom of tests/test_renderers/fixtures/reporter_warnings.md: |
|
Sweet! If you don't mind, I will just push to this branch, to document it. |
|
Alright! See:
I also removed: for node in newdoc.traverse():
if node.line:
# keep line numbers aligned
node.line += token.map[0]
node.source = self.document["source"]Since, after the addition of |
|
https://myst-parser--226.org.readthedocs.build/en/226/using/syntax.html#how-directives-parse-content the "ref from inside in this page does not show up as link. Is that intentional? |
|
|
||
| Party time! | ||
|
|
||
| A reference from inside: ref:`rst-fun-fish` |
There was a problem hiding this comment.
Ah damn thanks, so close to perfection 😆
Thanks for the spot, fixed in: https://myst-parser.readthedocs.io/en/latest/using/syntax.html#how-directives-parse-content |

Adds support the
eval-rstdirective, similar to recommonmark's version. Fixes #164.Examples (which I added unit tests for):
Links:
Bold text:
Or as I'll use it in ParlAI. I tested this in my own repo.