Skip to content

Commit 056daa5

Browse files
committed
fix(#72): issue with link as a heading
1 parent 46f796d commit 056daa5

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/markdownHeaders.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import getSlug from './markdownSlug';
22

33
const katex = require('katex');
4-
const markdownit = require('markdown-it')().set({ html: true });
4+
const markdownit = require('markdown-it')({ html: true });
55

66
function 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

Comments
 (0)