Skip to content

πŸ“š The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.

feat(markdown): support github emoji syntax (#689)

Osheune7a6b66f07f0
diff --git a/frontend/app/components/MarkdownEditor/emoji-snippets.ts b/frontend/app/components/MarkdownEditor/emoji-snippets.ts
new file mode 100644
index 00000000..a3ed220d
--- /dev/null
+++ b/frontend/app/components/MarkdownEditor/emoji-snippets.ts
@@ -0,0 +1,8 @@
+// @ts-expect-error no types provided
+import emojiData from 'markdown-it-emoji/lib/data/full.mjs';
+
+export const emojiSnippets = Object.entries(emojiData as Record<string, string>).map(([name, char]) => ({
+ id: `:${name}:`,
+ label: `:${name}: `,
+ emoji: char,
+}));
diff --git a/frontend/app/components/MarkdownEditor/modules/editorUtils.ts b/frontend/app/components/MarkdownEditor/modules/editorUtils.ts
index 39798d3f..c3d792a8 100644
--- a/frontend/app/components/MarkdownEditor/modules/editorUtils.ts
+++ b/frontend/app/components/MarkdownEditor/modules/editorUtils.ts
@@ -1,5 +1,13 @@
import { snippet, type CompletionContext } from '@codemirror/autocomplete';
import { katexSnippets } from '../katex-snippets';
+import { emojiSnippets } from '../emoji-snippets';
+
+const emojiOptions = emojiSnippets.map(s => ({
+ label: s.id,
+ detail: s.emoji,
+ type: 'text',
+ apply: snippet(s.label),
+}));
function isInsideMath(context: CompletionContext): boolean {
const doc = context.state.doc.toString();
@@ -54,9 +62,12 @@ export function createSnippetSource(enabled: Ref<boolean>, snippets: Ref<ANode<s
const word = inMath ? context.matchBefore(/\\?[\w!:*]+/) : context.matchBefore(/[\w!:]+/);
if (!word && !context.explicit) return null;
+ const typingEmoji = !inMath && word?.text.startsWith(':');
+
return {
from: word ? word.from : context.pos,
options: [
+ ...(typingEmoji ? emojiOptions : []),
...allSnippets.map(s => ({
label: s.id,
detail: 'Snippet',
diff --git a/frontend/app/helpers/markdown/index.ts b/frontend/app/helpers/markdown/index.ts
index 91f35403..e8d7057b 100644
--- a/frontend/app/helpers/markdown/index.ts
+++ b/frontend/app/helpers/markdown/index.ts
@@ -16,6 +16,7 @@ import { markdownItKatexPlugin } from './katex';
import { sourceMapPlugin } from './source-map';
import { internalLinkPlugin } from './internal-links';
import { tooltipPlugin } from './tooltip';
+import { full as emojiPlugin } from 'markdown-it-emoji';
const md = new MarkdownIt({ html: true, linkify: true });
md.use(containerPlugin);
@@ -37,6 +38,7 @@ md.use(colorPlugin, {
allowHex: true, // allow #rgb and #rrggbb
});
md.use(tooltipPlugin);
+md.use(emojiPlugin);
md.use(html5MediaPlugin);
md.use(svgObjectPlugin);
md.use(internalLinkPlugin);
diff --git a/frontend/bun.lock b/frontend/bun.lock
index c055700a..94ede642 100644
--- a/frontend/bun.lock
+++ b/frontend/bun.lock
@@ -24,6 +24,7 @@
"markdown-it": "^15.0.0",
"markdown-it-anchor": "^9.2.1",
"markdown-it-container": "^4.0.0",
+ "markdown-it-emoji": "^3.1.0",
"markdown-it-highlightjs": "^4.3.0",
"markdown-it-mark": "^4.0.0",
"mermaid": "^11.16.1",
@@ -47,6 +48,7 @@
"@types/katex": "^0.16.8",
"@types/markdown-it": "^14.2.0",
"@types/markdown-it-container": "^4.0.0",
+ "@types/markdown-it-emoji": "^3.0.1",
"@types/node": "^26.2.0",
"@vite-pwa/nuxt": "^1.1.1",
"eslint": "^10.8.1",
@@ -872,6 +874,8 @@
"@types/markdown-it-container": ["@types/[email protected]", "", { "dependencies": { "@types/markdown-it": ">=14" } }, "sha512-GmD8OECLfzPHv8VyvFRzslqdwXoDBJ2H40fxXFjrarbqvJZSB/BJKZXN5e3k7Mx7GQanSNzTYhzeS3H9o0gAOw=="],
+ "@types/markdown-it-emoji": ["@types/[email protected]", "", { "dependencies": { "@types/markdown-it": "^14" } }, "sha512-cz1j8R35XivBqq9mwnsrP2fsz2yicLhB8+PDtuVkKOExwEdsVBNI+ROL3sbhtR5occRZ66vT0QnwFZCqdjf3pA=="],
+
"@types/mdurl": ["@types/[email protected]", "", {}, "sha512-RGdgjQUZba5p6QEFAVx2OGb8rQDL/cPRG7GiedRzMcJ1tYnUANBncjbSB1NRGwbvjcPeikRABz2nshyPk1bhWg=="],
"@types/node": ["@types/[email protected]", "", { "dependencies": { "undici-types": "~8.3.0" } }, "sha512-5IviulTZeRNp2vAJ514cc/HUlY5nZ9fCbq9DMyC52BrhFZACo3nI0R7qBxhQmo/d27NFe96ur/b7Wwxklda+kg=="],
@@ -1944,6 +1948,8 @@
"markdown-it-container": ["[email protected]", "", {}, "sha512-HaNccxUH0l7BNGYbFbjmGpf5aLHAMTinqRZQAEQbMr2cdD3z91Q6kIo1oUn1CQndkT03jat6ckrdRYuwwqLlQw=="],
+ "markdown-it-emoji": ["[email protected]", "", {}, "sha512-NhmMEH2ywduD4Nty1E8uB5NqfLhAT1VR0dyvoJyStKOqCzbZmVdn/+8wj7zpDsb/fLBikpCPsWwxqKlvMmbz4g=="],
+
"markdown-it-highlightjs": ["[email protected]", "", { "dependencies": { "highlight.js": "^11.9.0" } }, "sha512-dTEXpTV2J9WJiO8TA/FJ4DxidrYtTNcfBAdl+CLjQ3UFWj8s4dJyCPTcvoXNLmN5U5ZTCGu7TSkSvBvi4fUqkQ=="],
"markdown-it-mark": ["[email protected]", "", {}, "sha512-YLhzaOsU9THO/cal0lUjfMjrqSMPjjyjChYM7oyj4DnyaXEzA8gnW6cVJeyCrCVeyesrY2PlEdUYJSPFYL4Nkg=="],
diff --git a/frontend/package.json b/frontend/package.json
index a6c1206a..8768025c 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -21,6 +21,7 @@
"markdown-it": "^15.0.0",
"markdown-it-anchor": "^9.2.1",
"markdown-it-container": "^4.0.0",
+ "markdown-it-emoji": "^3.1.0",
"markdown-it-highlightjs": "^4.3.0",
"markdown-it-mark": "^4.0.0",
"mermaid": "^11.16.1",
@@ -58,6 +59,7 @@
"@types/katex": "^0.16.8",
"@types/markdown-it": "^14.2.0",
"@types/markdown-it-container": "^4.0.0",
+ "@types/markdown-it-emoji": "^3.0.1",
"@types/node": "^26.2.0",
"@vite-pwa/nuxt": "^1.1.1",
"eslint": "^10.8.1",