feat(#169): add emoji support for markdown

This commit is contained in:
tdurieux
2023-04-21 13:23:34 +02:00
parent 3627096e63
commit 8ac3a66a30
5 changed files with 1951 additions and 0 deletions
File diff suppressed because it is too large Load Diff
+57
View File
@@ -0,0 +1,57 @@
const defaultOptions = {
// emojis: {}, required
unicode: false,
};
function markedEmoji(options) {
options = {
...defaultOptions,
...options,
};
if (!options.emojis) {
throw new Error("Must provide emojis to markedEmoji");
}
return {
extensions: [
{
name: "emoji",
level: "inline",
start(src) {
return src.indexOf(":");
},
tokenizer(src, tokens) {
const rule = /^:(.+?):/;
const match = rule.exec(src);
if (!match) {
return;
}
const name = match[1];
const emoji = options.emojis[name];
if (!emoji) {
return;
}
return {
type: "emoji",
raw: match[0],
name,
emoji,
};
},
renderer(token) {
if (options.unicode) {
return token.emoji;
} else {
return `<img class="emoji" alt="${token.name}" src="${
token.emoji
}"${this.parser.options.xhtml ? " /" : ""}>`;
}
},
},
],
};
}
+7
View File
@@ -110,6 +110,13 @@ function parseGithubUrl(url) {
}
}
marked.use(
markedEmoji({
emojis: githubEmojis,
unicode: false,
})
);
function renderMD(md, baseUrl) {
md = contentAbs2Relative(md);
const renderer = new marked.Renderer();