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

handle backticks within inline code blocks #172

Merged
merged 4 commits into from
Aug 11, 2024
Merged

handle backticks within inline code blocks #172

merged 4 commits into from
Aug 11, 2024

Conversation

yshavit
Copy link
Owner

@yshavit yshavit commented Aug 11, 2024

An inline code block starts with a string of at least one backtick, but possibly more: `, ``, etc. It then continues until that same sting again.

The actual surrounding backticks don't matter, as long as they don't appear in the contents. The following are equivalent, and both produce a``b:

`a``b`
```a``b```

The easiest way to handle this is to count the longest stretch of backticks in the contents, and then use a string of N+1 backticks for the inline code markers. So, that's what this PR does.

I can imagine nicer formatting, like finding the first available empty spot; or maybe just special-casing ``. But for now, I'm keeping things simple.

If the contents start or end with backspace, we add a single space on either side of the contents (between it and the backticks). The CommonMark spec says these should be stripped on parse; they're currently not, because of newly-filed #171.

This PR resolves #157.

The surrounding backticks should be N+1, where N is the longest stretch
of backticks within the string.
This isn't quite working, because of #171, which is due to upstream.
But I have the tests now, and this is good enough.
@yshavit yshavit merged commit b6287f6 into main Aug 11, 2024
4 checks passed
@yshavit yshavit deleted the 157.backticks branch August 11, 2024 06:09
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.

fmt_md needs better handling of backticks in inline code
1 participant