📚 The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.
Vue dockergolangkanbanknowledge-baseknowledge-managementmarkdownnote-takingnotesnotes-appnotionnuxtnuxtjsoffline-firstoidcpwaselfhostedssovuevuejswiki
katex full support !
Veauville Raphael249a00d08148
diff --git a/dashboard/bun.lockb b/dashboard/bun.lockbindex 60cd2135..c032cabf 100755Binary files a/dashboard/bun.lockb and b/dashboard/bun.lockb differdiff --git a/dashboard/components/sidebar/helpers.ts b/dashboard/components/sidebar/helpers.tsindex ae286afb..182b41a0 100644--- a/dashboard/components/sidebar/helpers.ts+++ b/dashboard/components/sidebar/helpers.ts@@ -43,7 +43,7 @@ export const navigationItems: DefaultItem[] = [];export const icons = {draft:- '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path style="fill:var(--yellow)" d="M240-80q-33 0-56.5-23.5T160-160v-640q0-33 23.5-56.5T240-880h320l240 240v480q0 33-23.5 56.5T720-80H240Zm280-520v-200H240v640h480v-440H520ZM240-800v200-200 640-640Z"/></svg>',+ '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path style="fill:var(--turquoise)" d="M240-80q-33 0-56.5-23.5T160-160v-640q0-33 23.5-56.5T240-880h320l240 240v480q0 33-23.5 56.5T720-80H240Zm280-520v-200H240v640h480v-440H520ZM240-800v200-200 640-640Z"/></svg>',folder:'<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path style="fill:var(--yellow);" d="M160-160q-33 0-56.5-23.5T80-240v-480q0-33 23.5-56.5T160-800h240l80 80h320q33 0 56.5 23.5T880-640H447l-80-80H160v480l96-320h684L837-217q-8 26-29.5 41.5T760-160H160Zm84-80h516l72-240H316l-72 240Zm0 0 72-240-72 240Zm-84-400v-80 80Z"/></svg>',file: '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path style="fill:var(--pink);" d="M320-240h320v-80H320v80Zm0-160h320v-80H320v80ZM240-80q-33 0-56.5-23.5T160-160v-640q0-33 23.5-56.5T240-880h320l240 240v480q0 33-23.5 56.5T720-80H240Zm280-520v-200H240v640h480v-440H520ZM240-800v200-200 640-640Z"/></svg>',diff --git a/dashboard/helpers/markdown/index.ts b/dashboard/helpers/markdown/index.tsindex f7bddba6..64342379 100644--- a/dashboard/helpers/markdown/index.ts+++ b/dashboard/helpers/markdown/index.ts@@ -14,13 +14,58 @@ md.use(anchorPlugin);md.use(containerSvg);md.use(underline);md.use(mark);+md.use(markdownItKatexPlugin);++function markdownItKatexPlugin(md: any) {+ // Nous ajoutons une règle en ligne (inline) après la règle 'escape' (qui échappe les caractères spéciaux)+ md.inline.ruler.after('escape', 'katex', (state: any, silent: any) => {+ if (silent) return false; // Si le mode silencieux est activé, nous arrêtons ici++ const startMathPos = state.pos; // Nous stockons la position du début de l'expression mathématique+ if (state.src.charCodeAt(startMathPos) !== 0x24 /* $ */) {+ // Nous vérifions si le caractère à la position de départ est un dollar sign ($)+ return false;+ }+ const endMarker = '$'; // Le délimiteur de fin pour l'expression mathématique+ let found = false; // Variable pour savoir si nous avons trouvé le délimiteur de fin+ let endMathPos = -1; // Position du délimiteur de fin dans la chaîne++ // Nous parcourons la chaîne à partir de la position de départ pour trouver le délimiteur de fin+ for (let i = startMathPos + 1; i < state.src.length; i++) {+ if (state.src.charCodeAt(i) === 0x24 /* $ */) {+ // Si nous trouvons un dollar sign ($)+ if (state.src.charCodeAt(i - 1) !== 0x5c /* \ */) {+ // Et qu'il n'est pas précédé d'un backslash (\)+ found = true; // Nous avons trouvé le délimiteur de fin+ endMathPos = i; // Nous stockons sa position+ break; // Nous arrêtons la recherche+ }+ }+ }++ if (!found) return false; // Si nous n'avons pas trouvé le délimiteur de fin, nous arrêtons ici++ // Nous ajoutons un token de type 'katex_inline' à la liste des tokens+ const token = state.push('katex_inline', '', 0);+ token.markup = endMarker; // Le délimiteur de fin pour ce token+ token.content = state.src.slice(startMathPos + 1, endMathPos); // Le contenu entre les délimiteurs de début et de fin+ state.pos = endMathPos + 1; // Nous mettons à jour la position de l'analyseur pour passer après le délimiteur de fin++ return true; // Nous signalons que nous avons traité un token avec succès+ });++ // Nous définissons la méthode de rendu pour les tokens de type 'katex_inline'+ md.renderer.rules.katex_inline = (tokens: any, idx: any) => {+ return mdTokatex(tokens[idx].content); // Nous utilisons notre fonction mdTokatex pour rendre le contenu mathématique+ };+}export default function compile(str: string = '', plugins: boolean = true): string {let render = str;if (plugins) {// KATEX (math)- const results = matchText(render);- render = replaceText(render, results);+ //const results = matchText(render);+ // render = replaceText(render, results);render = md.render(render, {html: true,});@@ -32,43 +77,12 @@ export default function compile(str: string = '', plugins: boolean = true): strireturn render;}-// A function for matching $<sequence>$ without regex.-interface Result {- start: number;- end: number;-}-function matchText(text: string) {- let i = 0;- let possible_start = -1;- const results: Result[] = [];- while (i < text.length) {- const character = text[i];- if (character === '$') {- if (possible_start == -1) {- possible_start = i;- } else {- results.push({- start: possible_start,- end: i,- });- possible_start = -1;- }- }- i++;- }- return results;-}-function replaceText(text: string, results: Result[]): string {- const copy = text;- for (const result of results) {- const expression = copy.substring(result.start, result.end + 1);- const expressionWithoutDollar = expression.slice(1, -1);- const render = katex.renderToString(expressionWithoutDollar, {- throwOnError: false,- displayMode: true,- trust: true,- });- text = text.replace(expression, `<span class="katex-container"><i>${render}</i></span>`);- }- return text;+function mdTokatex(text: string): string {+ const expressionWithoutDollar = text;+ const render = katex.renderToString(expressionWithoutDollar, {+ throwOnError: false,+ displayMode: true,+ trust: true,+ });+ return `<span class="katex-container"><i>${render}</i></span>`;}diff --git a/dashboard/package.json b/dashboard/package.jsonindex 33b1c46b..3023e2b5 100644--- a/dashboard/package.json+++ b/dashboard/package.json@@ -18,6 +18,7 @@"@types/markdown-it": "^13.0.4","@types/markdown-it-container": "^2.0.8","@types/node": "^20.8.5",+ "@types/prismjs": "^1.26.3","katex": "^0.16.10","markdown-it": "^14.1.0","markdown-it-anchor": "^8.6.7",@@ -30,5 +31,8 @@"sass": "^1.69.3","vue": "^3.3.4","vue-router": "^4.2.5"+ },+ "dependencies": {+ "prismjs": "^1.29.0"}}