Skip to content

Commit 4a1c96c

Browse files
committed
Updates to latest marked
1 parent 533bce4 commit 4a1c96c

File tree

4 files changed

+20
-52
lines changed

4 files changed

+20
-52
lines changed

ThirdPartyNotices.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ This project incorporates components from the projects listed below.
2323
18. https-proxy-agent version 5.0.1 (https://github.com/TooTallNate/node-https-proxy-agent)
2424
19. iconv-lite version 0.6.3 (https://github.com/ashtuchkin/iconv-lite)
2525
20. lit version 3.2.0 (https://github.com/lit/lit)
26-
21. marked version 12.0.2 (https://github.com/markedjs/marked)
26+
21. marked version 14.1.2 (https://github.com/markedjs/marked)
2727
22. microsoft/vscode (https://github.com/microsoft/vscode)
2828
23. node-fetch version 2.7.0 (https://github.com/bitinn/node-fetch)
2929
24. os-browserify version 0.3.0 (https://github.com/CoderPuppy/os-browserify)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18000,7 +18000,7 @@
1800018000
"https-proxy-agent": "5.0.1",
1800118001
"iconv-lite": "0.6.3",
1800218002
"lit": "3.2.0",
18003-
"marked": "12.0.2",
18003+
"marked": "14.1.2",
1800418004
"node-fetch": "2.7.0",
1800518005
"os-browserify": "0.3.0",
1800618006
"path-browserify": "1.0.1",

src/webviews/apps/plus/graph/hover/markdown.ts

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { css, html, LitElement } from 'lit';
22
import { customElement, property } from 'lit/decorators.js';
33
import { unsafeHTML } from 'lit/directives/unsafe-html.js';
44
import { until } from 'lit/directives/until.js';
5-
import type { RendererObject } from 'marked';
5+
import type { RendererObject, RendererThis, Tokens } from 'marked';
66
import { marked } from 'marked';
77
import type { ThemeIcon } from 'vscode';
88

@@ -116,34 +116,7 @@ export class GLMarkdown extends LitElement {
116116

117117
function getMarkdownRenderer(): RendererObject {
118118
return {
119-
// heading: function (text: string, level: number, raw: string, slugger: any): string {
120-
// level = Math.min(6, level);
121-
// const id = slugger.slug(text);
122-
// const hlinks = null;
123-
124-
// let content;
125-
126-
// if (hlinks === null) {
127-
// // No heading links
128-
// content = text;
129-
// } else {
130-
// content = `<a href="#${id}" class="anchor">`;
131-
132-
// if (hlinks === '') {
133-
// // Heading content is the link
134-
// content += `${text}</a>`;
135-
// } else {
136-
// // Headings are prepended with a linked symbol
137-
// content += `${hlinks}</a>${text}`;
138-
// }
139-
// }
140-
141-
// return `
142-
// <h${level} id="${id}">
143-
// ${content}
144-
// </h${level}>`;
145-
// },
146-
image: (href: string | null, title: string | null, text: string): string => {
119+
image: function (this: RendererThis, { href, title, text }: Tokens.Image): string {
147120
let dimensions: string[] = [];
148121
let attributes: string[] = [];
149122
if (href) {
@@ -161,27 +134,24 @@ function getMarkdownRenderer(): RendererObject {
161134
}
162135
return `<img ${attributes.join(' ')}>`;
163136
},
164-
165-
paragraph: (text: string): string => {
137+
paragraph: function (this: RendererThis, { tokens }: Tokens.Paragraph): string {
138+
const text = this.parser.parseInline(tokens);
166139
return `<p>${text}</p>`;
167140
},
168-
169-
link: (href: string, title: string | null | undefined, text: string): string | false => {
170-
if (typeof href !== 'string') {
171-
return '';
172-
}
141+
link: function (this: RendererThis, { href, title, tokens }: Tokens.Link): string | false {
142+
if (typeof href !== 'string') return '';
173143

174144
// Remove markdown escapes. Workaround for https://github.com/chjj/marked/issues/829
145+
let text = this.parser.parseInline(tokens);
175146
if (href === text) {
176147
// raw link case
177148
text = removeMarkdownEscapes(text);
178149
}
179150

180151
title = typeof title === 'string' ? escapeDoubleQuotes(removeMarkdownEscapes(title)) : '';
181-
href = removeMarkdownEscapes(href);
182152

183153
// HTML Encode href
184-
href = href
154+
href = removeMarkdownEscapes(href)
185155
.replace(/&/g, '&amp;')
186156
.replace(/</g, '&lt;')
187157
.replace(/>/g, '&gt;')
@@ -190,17 +160,15 @@ function getMarkdownRenderer(): RendererObject {
190160

191161
return `<a href="${href}" title="${title || href}" draggable="false">${text}</a>`;
192162
},
193-
194-
code: function (code: string, infostring: string | undefined, _escaped: boolean): string {
163+
code: function (this: RendererThis, { text, lang }: Tokens.Code): string {
195164
// Remote code may include characters that need to be escaped to be visible in HTML
196-
code = code.replace(/</g, '&lt;');
197-
return `<pre class="language-${infostring}"><code>${code}</code></pre>`;
165+
text = text.replace(/</g, '&lt;');
166+
return `<pre class="language-${lang}"><code>${text}</code></pre>`;
198167
},
199-
200-
codespan: function (code: string): string {
168+
codespan: function (this: RendererThis, { text }: Tokens.Codespan): string {
201169
// Remote code may include characters that need to be escaped to be visible in HTML
202-
code = code.replace(/</g, '&lt;');
203-
return `<code>${code}</code>`;
170+
text = text.replace(/</g, '&lt;');
171+
return `<code>${text}</code>`;
204172
},
205173
};
206174
}

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4951,10 +4951,10 @@ markdown-it@^14.1.0:
49514951
punycode.js "^2.3.1"
49524952
uc.micro "^2.1.0"
49534953

4954-
marked@12.0.2:
4955-
version "12.0.2"
4956-
resolved "https://registry.yarnpkg.com/marked/-/marked-12.0.2.tgz#b31578fe608b599944c69807b00f18edab84647e"
4957-
integrity sha512-qXUm7e/YKFoqFPYPa3Ukg9xlI5cyAtGmyEIzMfW//m6kXwCy2Ps9DYf5ioijFKQ8qyuscrHoY04iJGctu2Kg0Q==
4954+
marked@14.1.2:
4955+
version "14.1.2"
4956+
resolved "https://registry.yarnpkg.com/marked/-/marked-14.1.2.tgz#3cbc26b2d6832be32b75ae0746e0968c781b6156"
4957+
integrity sha512-f3r0yqpz31VXiDB/wj9GaOB0a2PRLQl6vJmXiFrniNwjkKdvakqJRULhjFKJpxOchlCRiG5fcacoUZY5Xa6PEQ==
49584958

49594959
49604960
version "2.0.28"

0 commit comments

Comments
 (0)