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

Wrong VS Code slugify: Should parse heading by the same markdown-it engine as VS Code's #970

Open
iAnyKey opened this issue Jun 23, 2021 · 6 comments
Labels
Area: Link (Reserved) Markdown link processing, URI recognition, slugification. Area: Table of contents Pertaining to table of contents (TOC generation and detection, related heading operations). Issue: Bug
Milestone

Comments

@iAnyKey
Copy link

iAnyKey commented Jun 23, 2021

Problem

## [![OPC UA .NET](https://img.shields.io/badge/OPC_UA_.NET-v1.0.4-512BD4?style=flat-square&logo=csharp&color=239120)][UA.NETStandard repo] OPC UA .NET StandardLibrary
produces following caption:

[OPC UA .NET][UA.NETStandard repo] OPC UA .NET StandardLibrary

with TOC entry like:
- [!OPC UA .NET OPC UA .NET StandardLibrary](#uanetstandard-repo-opc-ua-net-standardlibrary)

which is not working properly like a hyperlink.

In a sililar way this feature does not work properly with codespan in captions:
CODE:
## [![`crc32(data)`](https://img.shields.io/badge/crc32-v1.0.0.0-blue?style=flat-square&logo=mathworks)][CRC32] CRC-32 Computation Algorithm:
HEADER:

[crc32(data)][CRC32] CRC-32 Computation Algorithm

CODE TOC (generated):
- [!`crc32(data)` CRC-32 Computation Algorithm](#crc32-crc-32-computation-algorithm)
TOC Entry:

How to reproduce

copy code sessions into VS code, generate TOC and turn on preview

Error message in the console

none

@yzhang-gh

This comment has been minimized.

@yzhang-gh yzhang-gh added Area: Table of contents Pertaining to table of contents (TOC generation and detection, related heading operations). Issue: Bug labels Jun 23, 2021
@Lemmingh
Copy link
Collaborator

  • Which version are you using?

  • What is your configuration?

This should not happen after #890, and I cannot reproduce it on the latest dev build (f560819).


My result:

[UA.NETStandard repo]: u

[CRC32]: r

## [![OPC UA .NET](https://img.shields.io/badge/OPC_UA_.NET-v1.0.4-512BD4?style=flat-square&logo=csharp&color=239120)][UA.NETStandard repo] OPC UA .NET StandardLibrary

## [![`crc32(data)`](https://img.shields.io/badge/crc32-v1.0.0.0-blue?style=flat-square&logo=mathworks)][CRC32] CRC-32 Computation Algorithm

- [ OPC UA .NET StandardLibrary](#-opc-ua-net-standardlibrary)
- [ CRC-32 Computation Algorithm](#-crc-32-computation-algorithm)

Configuration:

{
    "markdown.extension.toc.slugifyMode": "github",
    "markdown.extension.toc.unorderedList.marker": "-"
}

@Lemmingh Lemmingh added Needs Reproduction Cannot reproduce. Res: Duplicate This issue or pull request already exists. labels Jun 23, 2021
@yzhang-gh
Copy link
Owner

Oops, thought I had installed the latest one.

@iAnyKey Could you try out the dev build and see whether it works?

@iAnyKey
Copy link
Author

iAnyKey commented Jun 24, 2021

just tested it on v3.4.0 #943.

Settings(also attached as .json.txt:

"name": "markdown-all-in-one",
"displayName": "%ext.displayName%",
"description": "%ext.description%",
"icon": "images/Markdown-mark.png",
"version": "3.4.0",
"publisher": "yzhang",
"engines": {
"vscode": "^1.49.0"
...
"markdown.extension.toc.slugifyMode": {
	"type": "string",
	"default": "github",
	"markdownDescription": "%config.toc.slugifyMode.description%",
	"enum": [
		"github",
		"azureDevops",
		"bitbucketCloud",
		"gitea",
		"gitlab",
		"vscode"
	],
	"enumDescriptions": [
		"GitHub",
		"Azure DevOps",
		"Bitbucket Cloud",
		"Gitea",
		"GitLab",
		"Visual Studio Code"
	]
},
"markdown.extension.toc.unorderedList.marker": {
	"type": "string",
	"default": "-",
	"markdownDescription": "%config.toc.unorderedList.marker.description%",
	"enum": [
		"-",
		"*",
		"+"
	]
},
"markdown.extension.toc.updateOnSave": {
	"type": "boolean",
	"default": true,
	"description": "%config.toc.updateOnSave.description%"
}

package.json.txt

Result

Still the same: I can "jump" to the headers You can jump here by clicking on them in preview or in pdf, but this doesnt work on the other 2 section headers

test.pdf
test.md

@yzhang-gh
Copy link
Owner

The VS Code is using a different slugify (assign a heading an id/anchor) function which is not fully compatible with GitHub.
VS Code: opc-ua-net-opc-ua-net-standardlibrary
GitHub: -opc-ua-net-standardlibrary

image

The PDF is created by another extension. So it is quite likely that they are not compatible.

If we set the slugifyMode to github, then the links only work (guaranteed) on GitHub, the exported HTML (by this extension), and the PDF created from that HTML.

Now the problem is even if we set slugifyMode to vscode, it still doesn't work in the VS Code built-in preview...

@Lemmingh
Copy link
Collaborator

the problem is even if we set slugifyMode to vscode, it still doesn't work in the VS Code built-in preview

https://github.com/microsoft/vscode/blob/1664732e44dbdc05bfc14e594e8ab9d0d0226188/extensions/markdown-language-features/src/markdownEngine.ts#L283-L306

This part is hard to simulate. I suggest thorough redesign.

@Lemmingh Lemmingh added Issue: Bug and removed Needs Reproduction Cannot reproduce. Res: Duplicate This issue or pull request already exists. labels Jun 24, 2021
@Lemmingh Lemmingh added this to the v3.6.0 milestone Jun 24, 2021
@Lemmingh Lemmingh changed the title TOC: unsuseable section links if codespan or reference-style links are in header Wrong VS Code slugify Jun 24, 2021
@Lemmingh Lemmingh added the Area: Link (Reserved) Markdown link processing, URI recognition, slugification. label Aug 24, 2021
@Lemmingh Lemmingh changed the title Wrong VS Code slugify Wrong VS Code slugify: Should parse heading by the same markdown-it engine as VS Code's Aug 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Link (Reserved) Markdown link processing, URI recognition, slugification. Area: Table of contents Pertaining to table of contents (TOC generation and detection, related heading operations). Issue: Bug
Projects
None yet
Development

No branches or pull requests

3 participants