mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-07-07 22:28:01 +02:00
feat(#169): add emoji support for markdown
This commit is contained in:
@@ -133,6 +133,12 @@ a:hover {
|
|||||||
color: var(--link-hover-color);
|
color: var(--link-hover-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.markdown-body .emoji {
|
||||||
|
height: 1.3em;
|
||||||
|
margin: 0;
|
||||||
|
vertical-align: -0.1em;
|
||||||
|
}
|
||||||
|
|
||||||
.navbar {
|
.navbar {
|
||||||
background: var(--header-bg-color) !important;
|
background: var(--header-bg-color) !important;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,6 +66,8 @@
|
|||||||
<script src="/script/langColors.js"></script>
|
<script src="/script/langColors.js"></script>
|
||||||
|
|
||||||
<!-- Notebook -->
|
<!-- Notebook -->
|
||||||
|
<script src="/script/external/github-emojis.js"></script>
|
||||||
|
<script src="/script/external/marked-emoji.js"></script>
|
||||||
<script src="/script/external/marked.min.js"></script>
|
<script src="/script/external/marked.min.js"></script>
|
||||||
<script src="/script/external/purify.min.js"></script>
|
<script src="/script/external/purify.min.js"></script>
|
||||||
<script src="/script/external/ansi_up.min.js"></script>
|
<script src="/script/external/ansi_up.min.js"></script>
|
||||||
|
|||||||
+1879
File diff suppressed because it is too large
Load Diff
+57
@@ -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 ? " /" : ""}>`;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -110,6 +110,13 @@ function parseGithubUrl(url) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
marked.use(
|
||||||
|
markedEmoji({
|
||||||
|
emojis: githubEmojis,
|
||||||
|
unicode: false,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
function renderMD(md, baseUrl) {
|
function renderMD(md, baseUrl) {
|
||||||
md = contentAbs2Relative(md);
|
md = contentAbs2Relative(md);
|
||||||
const renderer = new marked.Renderer();
|
const renderer = new marked.Renderer();
|
||||||
|
|||||||
Reference in New Issue
Block a user