Skip to content

Commit

Permalink
Bump marked to ^13.0.0 (#42665)
Browse files Browse the repository at this point in the history
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: ZeeshanTamboli <zeeshan.tamboli@gmail.com>
  • Loading branch information
renovate[bot] and ZeeshanTamboli authored Jun 21, 2024
1 parent a6ecef3 commit e8abc17
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
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.

0 comments on commit e8abc17

Please sign in to comment.