Skip to content

support exit from nested state in chunk - #14558

Merged
kevinushey merged 2 commits into
rel-chocolate-cosmosfrom
bugfix/chunk-nested-states
Apr 18, 2024
Merged

kevinushey merged 2 commits into
rel-chocolate-cosmosfrom
bugfix/chunk-nested-states

Conversation

@kevinushey

@kevinushey kevinushey commented Apr 17, 2024 •

Copy link
Copy Markdown
Collaborator

Intent

Addresses #14544.
Addresses #14545.

Approach

For R Markdown documents (and other multi-mode documents), when we embed the highlight rules for a particular language in a chunk, we did so under the assumption that only one single set of language highlight rules could exist in that chunk. This was no longer true with some of the changes we made to support Quarto YAML highlight rules, since we now have:

Markdown => R => YAML

And so if we encountered a chunk end marker while we were in the YAML highlight state, we would only pop a single state, hence placing us back into the R state (rather than the top-level Markdown state).

The fix here is fortunately straightforward: save the state we were in when we entered the chunk, and restore that state when we leave, regardless of how many inner language states were pushed while highlighting the inner chunk.

Automated Tests

N/A, but I intend to take a look at this after fixing the other highlight-related bug.

QA Notes

Test that highlighting in the following document works as expected:


```{r}
#| message: false
```

This is Markdown, so don't highlight this: 1 + 1

You should see something like:

Screenshot 2024-04-17 at 3 26 13 PM

Documentation

Specify which documentation has been added or modified and why (User Guide? Admin Guide?). If no documentation was added for a new feature, indicate why.

Checklist

  • If this PR adds a new feature, or fixes a bug in a previously released version, it includes an entry in NEWS.md
  • If this PR adds or changes UI, the updated UI meets accessibility standards
  • A reviewer is assigned to this PR (if unsure who to assign, check Area Owners list)
  • This PR passes all local unit tests

@kevinushey
kevinushey requested a review from gtritchie April 17, 2024 22:43
{
// (package) (::) (function) (:)
token: ["meta.tag", "keyword", "meta.tag", "keyword.operator"],
regex: /^(\s*[\w\-].*?)(:{2,3})(\s*[\w\-].*?)(:(?:\s+|$))/

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fairly certain the use of .* here was a typo; I can't imagine why we'd want to a catch-all regular expression here? That seems too permissive?

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Agree we should try to get some automation around this before we touch it again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants