-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rst: rst2html and doc now have clickable anchors for each paragraph/list element #17251
Conversation
lib/packages/docutils/rstgen.nim
Outdated
var idLast = 0 | ||
proc impl(n: PRstNode) = | ||
if n == nil: return | ||
n.anchorGen = "\0" # special char to indicate we've visited this node. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed? It's supposed to be a strict tree structure or at least an acyclic graph.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's needed because I'm processing the whole tree/DAG upon 1st call to renderRstToOut
, and because renderRstToOut
is reentrant. This sentinel avoids needs for a separate flag.
Without this logic, you can see it doesn't work:
nim rst2html -r doc/contributing.rst
the anchor next to separate test files
would be #-ROOT-2
instead of #-writing-tests-3
The idea is great. The current style is too visually disturbing. I'd like to put these marks outline: either to the left side margin of the text (where yellow dots are on the picture) or to the right margin (green dots): Unfortunately I don't know how to do it in HTML. But I think I've seen something like that somewhere. |
lib/packages/docutils/rstast.nim
Outdated
@@ -97,6 +97,7 @@ type | |||
anchor*: string ## anchor, internal link target | |||
## (aka HTML id tag, aka Latex label/hypertarget) | |||
sons*: RstNodeSeq ## the node's sons | |||
anchorGen*: string ## generated anchors from context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this additional field really needed? When anchor
is already defined you just use it; when it's not — you generate it. Anchor is always unique for any node.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed anchorGen (and reuse anchor), but added anchorKind which determines the kind of anchor (needed for book-keeping, among other things to make this work:
if n.anchorKind == raDefault: computeAnchorGen(n)
and knowing the kind of the anchor can be useful for other purposes.
d18285b
to
e772bf1
Compare
This pull request has been automatically marked as stale because it has not had recent activity. If you think it is still a valid PR, please rebase it on the latest devel; otherwise it will be closed. Thank you for your contributions. |
/cc @a-mr since you're our RST expert ;-)
fixes most of nim-lang/RFCs#117, plus a few other related improvements.
We can now point to any paragraph/list element in docs (rst or nim) and use it to share links. Ones in between stable anchor names (derived from a title or an anchor name) are considered non-stable and start with
-
to denote this. They're unstable in the sense that if a new paragraph/list element is added in the intervalanchoredName .. generatedAnchoredName
, the numbering may be off. This is expected and allows working with the common case of paragraphs/list elements that don't have an anchor name, yet still allow sharing links.there are 3 kinds of anchors:
Best practices
below): anchor name is derived from title.. _noimplicitbool
below): anchor name is explicitly provided and shouldn't change. Likewise for[display](link)
markdown syntaxdesign notes
nim rst2html -r doc/contributing.rst
ornim rst2html -r --doccmd:skip doc/manual.rst
TODO before merging
CI failures
only tests/stdlib/trstgen.nim fails, I'll fix it once the formatting in this PR is accepted to avoid back and forth on editing the tests
$nimb r nimdoc/rsttester.nim fails, I'll fix it once the formatting in this PR is accepted to avoid back and forth on editing the tests
see how this shows anchors on mouse over (hover) https://sublime-and-sphinx-guide.readthedocs.io/en/latest/references.html (eg when hovering on right of
Links to External Web Pages
)future work
https://nim-lang.github.io/Nim/manual.html#distinct-type-avoiding-sql-injection-attacks
=>
https://nim-lang.github.io/Nim/manual.html#avoiding-sql-injection-attacks
rstnodeToRefnameAux
shouldn't translate-
asminus
, this is anchor name is bad:https://nim-lang.github.io/Nim/manual.html#types-preminusdefined-integer-types
nim doc
in above logicgetFilePermissions <#getFilePermissions,string>
_ => $getFilePermissions
RFCs#125