Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions app/src/markdownit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { default as MarkdownItTexmath } from 'https://esm.sh/markdown-it-texmath
import Katex from 'https://esm.sh/katex@0.16.9';

const __args = parseArgs(Deno.args);
const app = __args['app'] ? JSON.parse(__args['app']) : 'webview';

const md = new MarkdownIt('default', {
html: true,
Expand Down Expand Up @@ -44,12 +45,14 @@ md.renderer.rules.link_open = (tokens, idx, options) => {
const token = tokens[idx];
const href = token.attrGet('href');

if (href && href.startsWith('#')) {
if (href?.startsWith('#')) {
token.attrSet('onclick', `location.hash='${href}'`);
token.attrSet('href', 'javascript:return');
} else {
const link = app === 'webview' ? 'javascript:return' : href;
token.attrSet('href', link || 'javascript:return');
}

token.attrSet('href', 'javascript:return');

return md.renderer.renderToken(tokens, idx, options);
};

Expand Down