mirror of
https://github.com/outline/outline.git
synced 2026-11-26 07:33:19 +03:00
serialize custom emojis like regular images
This commit is contained in:
1 parent
44f84ff4a5
commit
ef2ea41d63
4 files changed
+11
-53
No files matched your search
@@ -45,7 +45,6 @@ const EmojiMenu = (props: Props) => {
|
||||
markup: shortcode,
|
||||
"data-name": !isInternalUrl(emoji) ? shortcode : item.name,
|
||||
"data-url": isInternalUrl(emoji) ? emoji : undefined,
|
||||
type: isInternalUrl(emoji) ? "custom" : "emoji",
|
||||
},
|
||||
};
|
||||
})
|
||||
|
||||
@@ -828,6 +828,13 @@ h6:not(.placeholder)::before {
|
||||
margin-${props.rtl ? "right" : "left"}: -1em;
|
||||
}
|
||||
|
||||
.emoji.custom-emoji {
|
||||
width: 1.2em;
|
||||
height: 1.2em;
|
||||
vertical-align: text-bottom;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.heading-anchor,
|
||||
.heading-fold {
|
||||
display: inline-block;
|
||||
|
||||
@@ -33,7 +33,6 @@ export default class Emoji extends Extension {
|
||||
default: null,
|
||||
validate: (url: string) => !url || isInternalUrl(url),
|
||||
},
|
||||
type: { default: "emoji", validate: "string" },
|
||||
},
|
||||
inline: true,
|
||||
content: "text*",
|
||||
@@ -55,17 +54,14 @@ export default class Emoji extends Extension {
|
||||
toDOM: (node) => {
|
||||
const name = node.attrs["data-name"];
|
||||
const url = node.attrs["data-url"];
|
||||
const type = node.attrs.type;
|
||||
|
||||
if (type === "custom" && !!url) {
|
||||
if (url) {
|
||||
return [
|
||||
"img",
|
||||
{
|
||||
class: `emoji custom-emoji ${name}`,
|
||||
"data-name": name,
|
||||
src: url,
|
||||
style:
|
||||
"width: 1.2em; height: 1.2em; vertical-align: text-bottom; display: inline-block;",
|
||||
},
|
||||
];
|
||||
} else {
|
||||
@@ -117,7 +113,7 @@ export default class Emoji extends Extension {
|
||||
const escapedAlt = state.esc(alt, false);
|
||||
const escapedUrl = state.esc(url, false);
|
||||
|
||||
const markdown = `${prefix}`;
|
||||
const markdown = `${prefix}`;
|
||||
state.write(markdown);
|
||||
} else if (name) {
|
||||
state.write(`:${name}:`);
|
||||
@@ -127,17 +123,7 @@ export default class Emoji extends Extension {
|
||||
parseMarkdown() {
|
||||
return {
|
||||
node: "emoji",
|
||||
getAttrs: (tok: Token) => {
|
||||
const url = tok.attrGet("data-url");
|
||||
if (url && isInternalUrl(url)) {
|
||||
return {
|
||||
"data-name": tok.markup.trim(),
|
||||
"data-url": tok.attrGet("data-url"),
|
||||
type: "custom",
|
||||
};
|
||||
}
|
||||
return { "data-name": tok.markup.trim() };
|
||||
},
|
||||
getAttrs: (tok: Token) => ({ "data-name": tok.markup.trim() }),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import MarkdownIt, { StateCore } from "markdown-it";
|
||||
import MarkdownIt from "markdown-it";
|
||||
import { full as emojiPlugin } from "markdown-it-emoji";
|
||||
import { nameToEmoji } from "../lib/emoji";
|
||||
|
||||
@@ -6,41 +6,7 @@ type Options = MarkdownIt.Options & {
|
||||
emoji: boolean;
|
||||
};
|
||||
|
||||
function customEmojiRule(state: StateCore) {
|
||||
const tokens = state.tokens;
|
||||
|
||||
for (let i = 0; i < tokens.length; i++) {
|
||||
const token = tokens[i];
|
||||
|
||||
if (token.type === "inline" && token.children) {
|
||||
for (let j = 0; j < token.children.length; j++) {
|
||||
const childToken = token.children[j];
|
||||
|
||||
if (childToken.type === "image") {
|
||||
const title = childToken.attrGet("title");
|
||||
|
||||
if (title === "custom-emoji") {
|
||||
const emojiName = childToken.content || "";
|
||||
const emojiUrl = childToken.attrGet("src") || "";
|
||||
|
||||
const emojiToken = new state.Token("emoji", "", 0);
|
||||
emojiToken.markup = emojiName;
|
||||
emojiToken.attrSet("data-name", emojiName);
|
||||
emojiToken.attrSet("data-url", emojiUrl);
|
||||
|
||||
token.children[j] = emojiToken;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export default function emoji(md: MarkdownIt) {
|
||||
md.core.ruler.after("inline", "custom_emoji", customEmojiRule);
|
||||
|
||||
// Ideally this would be an empty object, but due to a bug in markdown-it-emoji
|
||||
// passing an empty object results in newlines becoming emojis. Until this is
|
||||
// fixed at least one key is required. See:
|
||||
|
||||
Reference in new issue
Block a user