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

Incorrect TOC for reference link #515

Closed
JounQin opened this issue Sep 1, 2019 · 11 comments · Fixed by #890
Closed

Incorrect TOC for reference link #515

JounQin opened this issue Sep 1, 2019 · 11 comments · Fixed by #890
Labels
Area: Table of contents Pertaining to table of contents (TOC generation and detection, related heading operations). Issue: Bug Res: Fixed Fix is checked in, but it might be a few weeks until a release.

Comments

@JounQin
Copy link

JounQin commented Sep 1, 2019

What is the problem?

### Via [remark-cli][]

[remark-cli]: https://github.com/remarkjs/remark/tree/master/packages/remark-cli
<!-- output -->
- [Via [remark-cli][]](#via-remark-cli)
<!-- expected -->
- [Via remark-cli](#via-remark-cli)

How can I reproduce it?

Is there any error message in the console?

@yzhang-gh
Copy link
Owner

Thanks for the feedback. (related #494)

We need an efficient way to strip off the Markdown syntax in the headings.

@yzhang-gh
Copy link
Owner

It should be fixed in the dev build.

@BeeeWall
Copy link
Contributor

BeeeWall commented Apr 9, 2020

Using both the latest version (2.7.0) and the latest dev build, this is broken for me.

Screenshot:
Screenshot

It also doesn't remove bold or italics, but that may be intended, I'm not sure.

@BeeeWall
Copy link
Contributor

Out of curiosity, why was my comment marked as off-topic? It was about the issue no longer being fixed (at least for me).

@yzhang-gh
Copy link
Owner

I was misled by the image. Thought it was another issue 😅.

I remember I have reverted the fix of this issue but cannot remember the reason now.

@yzhang-gh yzhang-gh reopened this Apr 14, 2020
@yzhang-gh yzhang-gh added the Area: Table of contents Pertaining to table of contents (TOC generation and detection, related heading operations). label Apr 14, 2020
@yzhang-gh
Copy link
Owner

Looks like this issue has been considered in the code. In case someone would like to have a look.

vscode-markdown/src/util.ts

Lines 111 to 113 in c83296e

export function extractText(text: string) {
//// Issue #515
text = text.replace(/\[([^\]]*)\]\[[^\]]*\]/, (_, g1) => g1);

@yzhang-gh yzhang-gh added the Help wanted Looking for help. label Apr 14, 2020
@BeeeWall
Copy link
Contributor

Think I figured it out, it looks like extractText isn't actually being called when creating the entry text.

vscode-markdown/src/toc.ts

Lines 136 to 137 in c83296e

let entryText = entry.text.replace(/\[([^\]]*)\]\([^\)]*\)/, (_, g1) => g1);
let slug = slugify(extractText(entryText));

Looks like it was changed in fe6a14f#diff-3a050df20b3a1c2ba3272cb808d6ab8b.

I've tested just moving the regex in line 136 to extractText and just calling that for entryTest and it (with some very quick testing) appears to fix it and doesn't seem to break anything.

I'll be creating a pull request for that in a minute.

@yzhang-gh
Copy link
Owner

It looks like some tests failed.

image

Let's remove Markdown syntax like [](), [][] but keep the bold, italic, inline code etc.
#584 (comment)

@BeeeWall
Copy link
Contributor

Done.

yzhang-gh pushed a commit that referenced this issue Apr 14, 2020
@yzhang-gh
Copy link
Owner

It should be fixed in the dev build.

@yzhang-gh yzhang-gh added Res: Fixed Fix is checked in, but it might be a few weeks until a release. and removed Help wanted Looking for help. labels Apr 14, 2020
@BeeeWall
Copy link
Contributor

Thanks for fixing it!

One small problem still: the regex does NOT match shortcut-style links ([this] vs [this][0]), so those are left.

It looks like changing the regex to make the second set of brackets optional fixes that (\[([^\]]*)\](?:\[[^\]]*\])*). I've gone ahead and done this in #655

@Lemmingh Lemmingh changed the title bug: incorrect TOC for link reference Incorrect TOC for reference link Aug 16, 2021
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). Issue: Bug Res: Fixed Fix is checked in, but it might be a few weeks until a release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants