From ccb8dcd156c88be6db21844063e55631b4bb7ca3 Mon Sep 17 00:00:00 2001 From: Franco Morroni Date: Sun, 4 Aug 2024 02:12:41 -0300 Subject: [PATCH] feat: proper hyperlinks on browser --- app/src/markdownit.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/markdownit.ts b/app/src/markdownit.ts index 204845b..0fd1f53 100644 --- a/app/src/markdownit.ts +++ b/app/src/markdownit.ts @@ -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, @@ -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); };