WIP: Add substitution definition code and tests#385
Conversation
d09bc21 to
c1b4be0
Compare
| qa, | ||
| known_refs, | ||
| local_refs=lr, | ||
| substitution_defs=substitution_defs, |
| self.children = [MImage(url=children[0].args, alt="")] | ||
| elif children[0].name == "replace": | ||
| self.children = [ReplaceNode(value=self.value, text=children[0].args)] | ||
| else: |
There was a problem hiding this comment.
Here is a quick search of what kind of subst we can find:
$ rg '^\.\. \|.+\| ' | cut -f3 -d'|' | cut -f 1 -d':' |tr -d ' '| sort | uniq -c | sort -n
htb/2023-sept-responder/Responder/certs/responder.key: Permission denied (os error 13)
1 baddata
1 digraph
1 directive
1 https
2 remplace
2 types
3 there'snodirectivehere
4 hazard
4 note
6 date
8 class
8 d
12 dir
16 r
24 raw
298 image
448 replace
2656 unicode
I think more generally a substition def should be .. |thename| directive-without-dot-dot:: content, so we might be able to not special case and just recurse on directive ?
There was a problem hiding this comment.
That makes sense, I went with the docutils information but I guess there are other inline directives that are not docutils. I will give it a try. Marking this as a draft in the meantime oh I see you already did, thanks!
|
Ok, this is a bit more complicated that I thought, I've push a few commits to try to see how we can push this a bit further. |
| def cbor(self, encoder): | ||
| assert False, self |
There was a problem hiding this comment.
This is currently failing on a table because of the |<table cell>| syntax in https://numpy.org/doc/stable/reference/generated/numpy.isscalar.html
There was a problem hiding this comment.
Yeah, I think we can just add the part that fail on a table on hte ignore list. I don't think tree-sitter-rst plan to parse tables, and I'm wondering if having a .. table:: directive could be a good workaround, we can add it to sphinx as well, so that projects work on both papyri and sphinx at the same time.
c7a6ca7 to
8c28d3b
Compare
TODO: - [ ] Add tests for substitution definitions in ascii_expected (currently failing) - [ ] Implement substitution definitions for all section types in gen.py (including narrative and module docstrings) - [ ] Implement support for custom inline directives
8c28d3b to
265836e
Compare
This make SubstitutionDef (and Ref) unserialisable, to ensure things fail at gen time. We also mute a couple of warnings to make the log cleaner
|
This should be almost all good with the exception of numpy narrative that makes use of a global substitution using |
It took me long enough because I think I was trying to do too much. This is a first pass and definitely needs improvement but it does work. I need some feedback on whether this is the right approach and whether we should look at resolving external links too?
TODO: