From f7241a4bfbb31177ef781142d4a9079509ce337a Mon Sep 17 00:00:00 2001 From: linonetwo Date: Mon, 16 Oct 2023 03:21:03 +0800 Subject: [PATCH] feat: only show asset table when necessary --- src/popup/Popup.tsx | 4 +++- src/popup/hooks/useTransformFormat.ts | 23 ++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/popup/Popup.tsx b/src/popup/Popup.tsx index c46987a..71c136b 100644 --- a/src/popup/Popup.tsx +++ b/src/popup/Popup.tsx @@ -38,7 +38,9 @@ export function Popup() { />
- + {assets.length > 0 && ( + + )} ); } diff --git a/src/popup/hooks/useTransformFormat.ts b/src/popup/hooks/useTransformFormat.ts index d71993e..6937c7f 100644 --- a/src/popup/hooks/useTransformFormat.ts +++ b/src/popup/hooks/useTransformFormat.ts @@ -35,14 +35,23 @@ export function useTransformFormat( * Including all type of transformation of HTML, for preview */ const newContent = { ...contentReference.current }; - if (options.toMd && newContent.html) { - const file = await html2mdParser.process(newContent.html); - const newMarkdown = String(file); - newContent.markdown = newMarkdown; + try { + if (options.toMd && newContent.html) { + // FIXME: Cannot handle unknown node `table` + const file = await html2mdParser.process(newContent.html); + const newMarkdown = String(file); + newContent.markdown = newMarkdown; + } + } catch (error) { + console.error(`html2md error ${(error as Error).message}`); } - if (newContent.markdown && options.toTid) { - const newTid = await md2tid(newContent.markdown); - newContent.wikitext = newTid; + try { + if (newContent.markdown && options.toTid) { + const newTid = await md2tid(newContent.markdown); + newContent.wikitext = newTid; + } + } catch (error) { + console.error(`md2tid error ${(error as Error).message}`); } if (!isEqual(newContent, content)) { setContent(newContent);