From: Adam Dullage Date: Tue, 7 May 2024 11:24:19 +0000 (+0100) Subject: Implement extendedAutolinks & customHTMLRenderer X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=41dc4603013c54ffff9dfb5af3964f3031f21884;p=flatnotes.git Implement extendedAutolinks & customHTMLRenderer --- diff --git a/client/components/toastui/ToastEditor.vue b/client/components/toastui/ToastEditor.vue index 0479cad..49faaab 100644 --- a/client/components/toastui/ToastEditor.vue +++ b/client/components/toastui/ToastEditor.vue @@ -4,9 +4,10 @@ diff --git a/client/components/toastui/baseOptions.js b/client/components/toastui/baseOptions.js new file mode 100644 index 0000000..60ff3ca --- /dev/null +++ b/client/components/toastui/baseOptions.js @@ -0,0 +1,130 @@ +import codeSyntaxHighlight from "@toast-ui/editor-plugin-code-syntax-highlight/dist/toastui-editor-plugin-code-syntax-highlight-all.js"; +import router from "../../router.js"; + +/* + * Sourced from toast-ui. Their autolink options are + * either override their built in functionality or + * use their built in functionality. We'd like to have + * both so this is the source of their parsers. + */ +const DOMAIN = "(?:[w-]+.)*[A-Za-z0-9-]+.[A-Za-z0-9-]+"; +const PATH = "[^<\\s]*[^ { + const text = match[1]; + return { + text, + url: `${router.resolve({ name: "note", params: { title: text.trim() } }).href}`, + range: [match.index, match.index + match[0].length - 1], + }; + }); + } + + return null; +} + +function extendedAutolinks(source) { + return [ + ...parseUrlLink(source), + ...parseEmailLink(source), + ...parseWikiLink(source), + ].sort((a, b) => a.range[0] - b.range[0]); +} + +const customHTMLRenderer = { + heading(node, { entering, getChildrenText }) { + const tagName = `h${node.level}`; + + if (entering) { + return { + type: "openTag", + tagName, + attributes: { + id: getChildrenText(node) + .toLowerCase() + .replace(/[^a-z0-9-\s]*/g, "") + .trim() + .replace(/\s/g, "-"), + }, + }; + } + return { type: "closeTag", tagName }; + }, +}; + +const baseOptions = { + height: "100%", + plugins: [codeSyntaxHighlight], + customHTMLRenderer: customHTMLRenderer, + usageStatistics: false, + extendedAutolinks, +}; + +export default baseOptions; diff --git a/client/style.css b/client/style.css index 634af87..713c238 100644 --- a/client/style.css +++ b/client/style.css @@ -13,28 +13,22 @@ body { --theme-brand: 248 166 107; - --theme-background: 255 255 255; --theme-background-elevated: 243 244 245; - --theme-text: 44 49 57; --theme-text-muted: 136 145 161; --theme-text-very-muted: 193 199 208; - --theme-shadow: 236 238 240; --theme-border: 236 238 240; } body.dark { /* --theme-brand: 248 166 107; */ - --theme-background: 34 38 44; --theme-background-elevated: 44 49 57; - --theme-text: 193 199 208; --theme-text-muted: 136 145 161; --theme-text-very-muted: 94 107 128; - --theme-shadow: none; --theme-border: 94 107 128; }