@@ -2,7 +2,7 @@ import { css, html, LitElement } from 'lit';
22import { customElement , property } from 'lit/decorators.js' ;
33import { unsafeHTML } from 'lit/directives/unsafe-html.js' ;
44import { until } from 'lit/directives/until.js' ;
5- import type { RendererObject } from 'marked' ;
5+ import type { RendererObject , RendererThis , Tokens } from 'marked' ;
66import { marked } from 'marked' ;
77import type { ThemeIcon } from 'vscode' ;
88
@@ -116,34 +116,7 @@ export class GLMarkdown extends LitElement {
116116
117117function 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, '&' )
186156 . replace ( / < / g, '<' )
187157 . replace ( / > / g, '>' )
@@ -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, '<' ) ;
197- return `<pre class="language-${ infostring } "><code>${ code } </code></pre>` ;
165+ text = text . replace ( / < / g, '<' ) ;
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, '<' ) ;
203- return `<code>${ code } </code>` ;
170+ text = text . replace ( / < / g, '<' ) ;
171+ return `<code>${ text } </code>` ;
204172 } ,
205173 } ;
206174}
0 commit comments