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

Remove shortcut-style links from headers in ToC #655

Closed
wants to merge 4 commits into from

Conversation

BeeeWall
Copy link
Contributor

Currently, the regex used to match links does not match shortcut-style reference links (ones with no reference after them, such as [link]). This PR fixes that, by making the second set of brackets optional in the regex.

This also adds tests for those and collapsed-style links ([link][]).

Note: for whatever reason, the tests won't run for me (even before I added the new ones, so I don't believe it's an issue caused by my changes), so I can't run the tests locally. But since the PR will automatically run them that should work out still.

@BeeeWall
Copy link
Contributor Author

How did changing the comments cause it to fail-

The test failure just says it timed out (and on a test unrelated to where the comments are located, I think). So maybe that's a one-time failure? Because I can't see how a comment change like that would actually break it.

@yzhang-gh
Copy link
Owner

yzhang-gh commented Apr 15, 2020

Thanks. But I am wondering whether we should do this as [] is more likely to be literally just square brackets rather than a reference link when it appears in a heading. An example is, when people use 1. in a heading, they don't mean it being a Markdown list.

image


The test failure just says it timed out

It is not a problem with your code. From time to time it fails.

@yzhang-gh yzhang-gh added Area: Table of contents Pertaining to table of contents (TOC generation and detection, related heading operations). Needs Discussion We haven't decided what to do. labels Apr 15, 2020
@BeeeWall
Copy link
Contributor Author

I thought about that, but it looks like brackets being in the headers breaks them. Tested using both Markdown Preview Advanced and the default Markdown previewer.

image

image

@yzhang-gh
Copy link
Owner

I see. If you have reference link definitions (e.g. [Test]: example.com), the [Test] in the heading will be rendered by the Markdown parser, otherwise it is left as is ([Test]).

So what we can do is to only remove brackets of [foo] if there exists [foo]: bar.

Personally, I would suggest not using the shortcut syntax. It is prone to cause problems.

@yzhang-gh
Copy link
Owner

Thanks for your contribution. For now, let's just keep it simple (doesn't recognize shortcut-style reference links).

@yzhang-gh yzhang-gh closed this May 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Table of contents Pertaining to table of contents (TOC generation and detection, related heading operations). Needs Discussion We haven't decided what to do.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants