11import getSlug from './markdownSlug' ;
22
33const katex = require ( 'katex' ) ;
4- const markdownit = require ( 'markdown-it' ) ( ) . set ( { html : true } ) ;
4+ const markdownit = require ( 'markdown-it' ) ( { html : true } ) ;
55
66function isHeader ( line : string , context : any ) {
77 // check code block
@@ -25,29 +25,30 @@ function isHeader(line: string, context: any) {
2525 return true ;
2626}
2727
28- function renderFormula ( formula : string ) :string {
28+ function renderFormula ( formula : string ) : string {
2929 return katex . renderToString ( formula . substring ( 1 , formula . length - 1 ) , {
3030 throwOnError : false ,
3131 } ) ;
3232}
3333
3434/* eslint-disable no-constant-condition, no-useless-escape */
35- function renderInline ( line : string ) :string {
35+ function renderInline ( line : string ) : string {
3636 let html = line ;
3737 html = line . replace ( / \$ .+ ?\$ / g, renderFormula ) ;
38+ html = markdownit . renderInline ( html ) ;
3839
39- // remove HTML tags
40+ // remove HTML links
4041 while ( true ) {
41- const x = html . replace ( / \[ ( . * ? ) \] \( . * ? \) / , '$1' ) ;
42+ const x = html . replace ( / < a \s [ ^ > ] * ? > ( [ ^ < > ] * ? ) < \/ a > / , '$1' ) ;
4243 if ( x === html ) break ;
4344 html = x ;
4445 }
4546
46- return markdownit . renderInline ( html ) ;
47+ return html ;
4748}
4849
4950/* eslint-disable no-continue, no-useless-escape */
50- export default function markdownHeaders ( noteBody :string ) {
51+ export default function markdownHeaders ( noteBody : string ) {
5152 const headers = [ ] ;
5253 const slugs : any = { } ;
5354 const lines = noteBody . split ( '\n' ) . map ( ( line , index ) => ( { index, line } ) ) ;
0 commit comments