Fix standalone markdown bugs found while planning escaping rewrite#1900
Merged
Conversation
* Make roxygen_parse_tag() UTF-8 aware, so findEndOfTag() accepts and
returns character offsets. Previously its byte offsets were mixed with
character offsets from gregexpr()/substr(), so a multibyte character
inside a fragile Rd tag (e.g. \code{café}) corrupted markdown
processing of the following text, and strip_rd_tag() mis-sliced
examples containing multibyte characters.
* Fix warning paths for tag-less markdown(): the fake default tag
crashed in basename(), and rd-family.R passed a bare string that
crashed on tag$tag. Both now pass NULL, which warn_roxy_tag()
handles.
* Delete dead markdown_pass1() and seven helpers duplicated between
markdown.R and markdown-code.R (the markdown.R copies silently shadow
the markdown-code.R ones due to collation order).
* Remove the stale claim that markdown is interpreted inside \if/
\ifelse arguments; fragile tags are protected with all their
arguments.
* Skip the commonmark parse in markdown_evaluate() when the text
contains no backtick or tilde, so tags without code don't pay for a
full parse.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While designing a replacement for the markdown escaping/unescaping machinery, I found several standalone bugs and cleanups worth landing first:
UTF-8 offsets:
roxygen_parse_tag()is now UTF-8 aware, sofindEndOfTag()accepts and returns character offsets. Previously its byte offsets were combined with character offsets fromgregexpr()/substr(), so a multibyte character inside a fragile Rd tag corrupted markdown processing of the text that followed — e.g.\code{café} *x*lost the emphasis and\code{café} `x`left the backticks literal. The same mismatch affectedstrip_rd_tag()on examples containing multibyte characters.rdComplete()is unaffected.Tag-less warnings:
markdown()'s fake default tag (list(file = NA, line = NA)) crashed inbasename(), andrd-family.Rpassed the bare string"family", which crashed ontag$tag. Both now passNULL, whichwarn_roxy_tag()handles, so e.g. a level-1 heading in anrd_family_titleprefix now warns instead of erroring.Dead code: deleted unused
markdown_pass1()plus seven helpers that were defined identically in bothmarkdown.Randmarkdown-code.R— themarkdown.Rcopies silently shadowed the others because of collation order. The one divergence (the "Multi-linermarkup" message) was reconciled to the version the snapshots expect.Stale docs: removed the claim that markdown is interpreted inside the 2nd/3rd arguments of
\if/\ifelse; it was never implemented — fragile tags are protected together with all their arguments.Fast path:
markdown_evaluate()now skips the commonmark parse when the text contains no backtick or tilde (tilde-fenced~~~{r}blocks parse and evaluate today, so~stays in the gate), so the many tags without any code don't pay for a full parse.🤖 Generated with Claude Code