mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Update MD051/link-fragments to use the same character classes as GitHub, encode unprintable characters from emojii.
This commit is contained in:
parent
db5d9f6dbb
commit
9a5e7e42ef
3 changed files with 34 additions and 7 deletions
|
|
@ -4408,10 +4408,14 @@ var identifierRe = /(?:id|name)\s*=\s*['"]?([^'"\s>]+)/iu;
|
||||||
*/
|
*/
|
||||||
function convertHeadingToHTMLFragment(inline) {
|
function convertHeadingToHTMLFragment(inline) {
|
||||||
var inlineText = inline.children.map(function (token) { return token.content; }).join("");
|
var inlineText = inline.children.map(function (token) { return token.content; }).join("");
|
||||||
return "#" + inlineText
|
return "#" + encodeURIComponent(inlineText
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.replace(/ /g, "-")
|
// RegExp source with Ruby's \p{Word} expanded into its General Categories
|
||||||
.replace(/[^-_a-z0-9]/g, "");
|
// eslint-disable-next-line max-len
|
||||||
|
// https://github.com/gjtorikian/html-pipeline/blob/main/lib/html/pipeline/toc_filter.rb
|
||||||
|
// https://ruby-doc.org/core-3.0.2/Regexp.html
|
||||||
|
.replace(/[^\p{Letter}\p{Mark}\p{Number}\p{Connector_Punctuation}\- ]/gu, "")
|
||||||
|
.replace(/ /gu, "-"));
|
||||||
}
|
}
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"names": ["MD051", "link-fragments"],
|
"names": ["MD051", "link-fragments"],
|
||||||
|
|
|
||||||
15
lib/md051.js
15
lib/md051.js
|
|
@ -18,10 +18,19 @@ const identifierRe = /(?:id|name)\s*=\s*['"]?([^'"\s>]+)/iu;
|
||||||
*/
|
*/
|
||||||
function convertHeadingToHTMLFragment(inline) {
|
function convertHeadingToHTMLFragment(inline) {
|
||||||
const inlineText = inline.children.map((token) => token.content).join("");
|
const inlineText = inline.children.map((token) => token.content).join("");
|
||||||
return "#" + inlineText
|
return "#" + encodeURIComponent(
|
||||||
|
inlineText
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.replace(/ /g, "-")
|
// RegExp source with Ruby's \p{Word} expanded into its General Categories
|
||||||
.replace(/[^-_a-z0-9]/g, "");
|
// eslint-disable-next-line max-len
|
||||||
|
// https://github.com/gjtorikian/html-pipeline/blob/main/lib/html/pipeline/toc_filter.rb
|
||||||
|
// https://ruby-doc.org/core-3.0.2/Regexp.html
|
||||||
|
.replace(
|
||||||
|
/[^\p{Letter}\p{Mark}\p{Number}\p{Connector_Punctuation}\- ]/gu,
|
||||||
|
""
|
||||||
|
)
|
||||||
|
.replace(/ /gu, "-")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,10 @@
|
||||||
|
|
||||||
[Valid](#valid-heading--with-emoji-2)
|
[Valid](#valid-heading--with-emoji-2)
|
||||||
|
|
||||||
|
[Valid](#valid-heading-2010-)
|
||||||
|
|
||||||
|
[Valid](#valid-heading-2004-%EF%B8%8F)
|
||||||
|
|
||||||
[Valid](#valid-closed-atx-heading)
|
[Valid](#valid-closed-atx-heading)
|
||||||
|
|
||||||
[Valid](#valid-setext-heading)
|
[Valid](#valid-setext-heading)
|
||||||
|
|
@ -56,6 +60,14 @@ Text
|
||||||
|
|
||||||
Text
|
Text
|
||||||
|
|
||||||
|
### Valid Heading 20.10 ❌
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
### Valid Heading 20.04 ✔️
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
### Valid Closed ATX Heading ###
|
### Valid Closed ATX Heading ###
|
||||||
|
|
||||||
Text
|
Text
|
||||||
|
|
@ -77,6 +89,8 @@ Text
|
||||||
|
|
||||||
## Invalid Fragments
|
## Invalid Fragments
|
||||||
|
|
||||||
|
[Inalid](#valid-heading-2004-) {MD051}
|
||||||
|
|
||||||
[Invalid](#invalid-fragment) {MD051}
|
[Invalid](#invalid-fragment) {MD051}
|
||||||
|
|
||||||
[Invalid](#myname) {MD051}
|
[Invalid](#myname) {MD051}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue