Skip to content

Commit

Permalink
🗜️ build [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
CI Build committed Jun 12, 2024
1 parent 3abf8e1 commit 3f9fd69
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
25 changes: 23 additions & 2 deletions lib/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@ let slugger = new BananaSlug();

let headings = [];

// unescape from marked helpers
const unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
/* istanbul ignore next */
function unescape(html) {
// explicitly match decimal, hex, and named HTML entities
return html.replace(unescapeTest, (_, n) => {
n = n.toLowerCase();
if (n === 'colon') return ':';
if (n.charAt(0) === '#') {
return n.charAt(1) === 'x'
? String.fromCharCode(parseInt(n.substring(2), 16))
: String.fromCharCode(+n.substring(1));
}
return '';
});
}

function gfmHeadingId({ prefix = '', globalSlugs = false } = {}) {
return {
headerIds: false, // prevent deprecation warning; remove this once headerIds option is removed
Expand All @@ -95,12 +112,15 @@ function gfmHeadingId({ prefix = '', globalSlugs = false } = {}) {
return src;
}
},
useNewRenderer: true,
renderer: {
heading(text, level, raw) {
raw = raw
heading({ tokens, depth }) {
const text = this.parser.parseInline(tokens);
const raw = unescape(this.parser.parseInline(tokens, this.parser.textRenderer))
.toLowerCase()
.trim()
.replace(/<[!\/a-z].*?>/gi, '');
const level = depth;
const id = `${prefix}${slugger.slug(raw)}`;
const heading = { level, text, id };
headings.push(heading);
Expand All @@ -123,3 +143,4 @@ function resetHeadings() {
exports.getHeadingList = getHeadingList;
exports.gfmHeadingId = gfmHeadingId;
exports.resetHeadings = resetHeadings;
exports.unescape = unescape;
25 changes: 23 additions & 2 deletions lib/index.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@

let headings = [];

// unescape from marked helpers
const unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
/* istanbul ignore next */
function unescape(html) {
// explicitly match decimal, hex, and named HTML entities
return html.replace(unescapeTest, (_, n) => {
n = n.toLowerCase();
if (n === 'colon') return ':';
if (n.charAt(0) === '#') {
return n.charAt(1) === 'x'
? String.fromCharCode(parseInt(n.substring(2), 16))
: String.fromCharCode(+n.substring(1));
}
return '';
});
}

function gfmHeadingId({ prefix = '', globalSlugs = false } = {}) {
return {
headerIds: false, // prevent deprecation warning; remove this once headerIds option is removed
Expand All @@ -99,12 +116,15 @@
return src;
}
},
useNewRenderer: true,
renderer: {
heading(text, level, raw) {
raw = raw
heading({ tokens, depth }) {
const text = this.parser.parseInline(tokens);
const raw = unescape(this.parser.parseInline(tokens, this.parser.textRenderer))
.toLowerCase()
.trim()
.replace(/<[!\/a-z].*?>/gi, '');
const level = depth;
const id = `${prefix}${slugger.slug(raw)}`;
const heading = { level, text, id };
headings.push(heading);
Expand All @@ -127,5 +147,6 @@
exports.getHeadingList = getHeadingList;
exports.gfmHeadingId = gfmHeadingId;
exports.resetHeadings = resetHeadings;
exports.unescape = unescape;

}));

0 comments on commit 3f9fd69

Please sign in to comment.