Skip to content
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

Add support for tildes in attributes of fenced code block #127

Merged
merged 6 commits into from
Jan 11, 2023

Conversation

a-stewart
Copy link
Contributor

This fixes #126.

Fenced code blocks fail if there is a tilde (or backtick) in the attributes of a fenced codeblock.

For example, the following markdown highlights as expected.

```sh {higlight="content:/$foo"}
cd ~/$foo
```

But as soon as you add a tilde to the filepath, syntax highlighting stops working:

```sh {higlight="content:~/$foo"}
cd ~/$foo
```

@a-stewart
Copy link
Contributor Author

Running the tests pulls in changes unrelated to this change, I think perhaps because the VS Code theme has changed the colours?

I've run the tests against main, and included that as a separate PR if that is preferred:
#128

@a-stewart a-stewart marked this pull request as ready for review January 10, 2023 17:07
build.js Outdated
@@ -85,7 +85,7 @@ const fencedCodeBlockDefinition = (name, identifiers, sourceScope, language, add

return `fenced_code_block_${name}:
begin:
(^|\\G)(\\s*)(\`{3,}|~{3,})\\s*(?i:(${identifiers.join('|')})((\\s+|:|,|\\{|\\?)[^\`~]*)?$)
(^|\\G)(\\s*)(\`{3,}|~{3,})\\s*(?i:(${identifiers.join('|')})((\\s+|:|,|\\{|\\?)(?:(?!\`{3}|~{3}).)*)?$)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's try to align this with the markdown spec: https://spec.commonmark.org/0.30/#fenced-code-blocks Here's the relevant section:

If the info string comes after a backtick fence, it may not contain any backtick characters. (The reason for this restriction is that otherwise some inline code would be incorrectly interpreted as the beginning of a fenced code block.)

Github doesn't do the same for fetched code blocks starting with ~. As far as I can tell, the info string in those can contain as many ~ as you want

Copy link
Contributor Author

@a-stewart a-stewart Jan 11, 2023

Choose a reason for hiding this comment

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

I think the difficulty with Markdown is that there are so many different flavours, Commonmark is just one spec.

What would you recommend doing here? Since common mark only references backticks, we could potentially, be more or less strict.

What do you reckon to doing [^\`]* which would allow as many tildes as desired whilst keeping the restriction on backticks?

This would cause issues with ~~~foo~~~ but I can't find anything that supports using tildes like that.

@mjbvz mjbvz merged commit bb112b5 into microsoft:main Jan 11, 2023
@mjbvz
Copy link
Contributor

mjbvz commented Jan 11, 2023

Thanks!

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.

Tildes in attributes of fenced code block break highlighting for the rest of the file
2 participants