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

Bump marked to ^13.0.0 #42665

Merged
merged 3 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
"chai": "^4.4.1",
"cross-fetch": "^4.0.0",
"gm": "^1.25.0",
"marked": "^5.1.2",
"marked": "^13.0.0",
"playwright": "^1.44.1",
"prettier": "^3.3.2",
"tailwindcss": "^3.4.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/markdown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"@babel/runtime": "^7.24.7",
"lodash": "^4.17.21",
"marked": "^5.1.2",
"marked": "^13.0.0",
"prismjs": "^1.29.0"
},
"devDependencies": {
Expand Down
24 changes: 13 additions & 11 deletions packages/markdown/parseMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,13 @@ function createRender(context) {
*/
function render(markdown) {
const renderer = new marked.Renderer();
renderer.heading = (headingHtml, level) => {
renderer.heading = function heading({ tokens, depth: level }) {
// Main title, no need for an anchor.
// It adds noises to the URL.
//
// Small title, no need for an anchor.
// It reduces the risk of duplicated id and it's fewer elements in the DOM.
const headingHtml = this.parser.parseInline(tokens);
if (level === 1 || level >= 4) {
return `<h${level}>${headingHtml}</h${level}>`;
}
Expand Down Expand Up @@ -372,11 +373,12 @@ function createRender(context) {
`</h${level}>`,
].join('');
};
renderer.link = (href, linkTitle, linkText) => {
renderer.link = function link({ href, title, tokens }) {
const linkText = this.parser.parseInline(tokens);
let more = '';

if (linkTitle) {
more += ` title="${linkTitle}"`;
if (title) {
more += ` title="${title}"`;
}

if (noSEOadvantage.some((domain) => href.indexOf(domain) !== -1)) {
Expand Down Expand Up @@ -404,17 +406,17 @@ function createRender(context) {

return `<a href="${finalHref}"${more}>${linkText}</a>`;
};
renderer.code = (code, infostring, escaped) => {
renderer.code = ({ lang, text, escaped }) => {
// https://github.com/markedjs/marked/blob/30e90e5175700890e6feb1836c57b9404c854466/src/Renderer.js#L15
const lang = (infostring || '').match(/\S*/)[0];
const title = (infostring || '').match(/title="([^"]*)"/)?.[1];
const out = prism(code, lang);
if (out != null && out !== code) {
const langString = (lang || '').match(/\S*/)[0];
const title = (lang || '').match(/title="([^"]*)"/)?.[1];
const out = prism(text, langString);
if (out != null && out !== text) {
escaped = true;
code = out;
text = out;
}

code = `${code.replace(/\n$/, '')}\n`;
const code = `${text.replace(/\n$/, '')}\n`;

if (!lang) {
return `<pre><code>${escaped ? code : escape(code, true)}</code></pre>\n`;
Expand Down
16 changes: 8 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.