Skip to content
Snippets Groups Projects
Commit c9758200 authored by marihachi's avatar marihachi
Browse files

Isolate node of unicode emoji and custom emoji.

parent f59529ff
No related branches found
No related tags found
No related merge requests found
......@@ -46,7 +46,8 @@ export {
MfmCenter,
// inline
MfmEmoji,
MfmUnicodeEmoji,
MfmCustomEmoji,
MfmBold,
MfmSmall,
MfmItalic,
......
......@@ -45,18 +45,26 @@ export type MfmCenter = {
children: MfmInline[];
};
export type MfmInline = MfmEmoji | MfmBold | MfmSmall | MfmItalic | MfmStrike | MfmInlineCode |
MfmMathInline | MfmMention | MfmHashtag | MfmUrl | MfmLink | MfmFn | MfmText;
export type MfmInline = MfmUnicodeEmoji | MfmCustomEmoji | MfmBold | MfmSmall | MfmItalic | MfmStrike |
MfmInlineCode | MfmMathInline | MfmMention | MfmHashtag | MfmUrl | MfmLink | MfmFn | MfmText;
export type MfmEmoji = {
type: 'emoji';
export type MfmUnicodeEmoji = {
type: 'unicodeEmoji';
props: {
emoji?: string;
name?: string;
emoji: string;
};
children?: [];
};
export type MfmCustomEmoji = {
type: 'customEmoji';
props: {
name: string;
};
children?: [];
};
export type MfmBold = {
type: 'bold';
props?: { };
......
......@@ -158,7 +158,7 @@ emoji
customEmoji
= ":" name:emojiName ":"
{
return createNode('emoji', { name: name });
return createNode('customEmoji', { name: name });
}
emojiName
......@@ -168,7 +168,7 @@ emojiName
unicodeEmoji
= &{ return matchUnicodeEmoji(); } (&{ return consumeDynamically(); } .)+
{
return createNode('emoji', { emoji: text() });
return createNode('unicodeEmoji', { emoji: text() });
}
// inline: big
......
......@@ -60,16 +60,11 @@ export function stringifyNode(node: MfmNode): string {
return `<center>\n${ stringifyTree(node.children) }\n</center>`;
}
// inline
case 'emoji': {
if (node.props.name) {
return `:${ node.props.name }:`;
}
else if (node.props.emoji) {
return node.props.emoji;
}
else {
return '';
}
case 'customEmoji': {
return `:${ node.props.name }:`;
}
case 'unicodeEmoji': {
return node.props.emoji;
}
case 'bold': {
return `**${ stringifyTree(node.children) }**`;
......
import {
MfmBold, MfmCenter, MfmCodeBlock, MfmEmoji, MfmFn, MfmHashtag, MfmInline,
MfmBold, MfmCenter, MfmCodeBlock, MfmCustomEmoji, MfmFn, MfmHashtag, MfmInline,
MfmInlineCode, MfmItalic, MfmLink, MfmMathBlock, MfmMathInline, MfmMention,
MfmNode, MfmQuote, MfmSearch, MfmSmall, MfmStrike, MfmText, MfmUrl
MfmNode, MfmQuote, MfmSearch, MfmSmall, MfmStrike, MfmText, MfmUnicodeEmoji, MfmUrl
} from '../built';
export const QUOTE = (children: MfmNode[]): MfmQuote => { return { type:'quote', children }; };
......@@ -20,7 +20,7 @@ export const MENTION = (username: string, host: string | null, acct: string): Mf
export const HASHTAG = (value: string): MfmHashtag => { return { type:'hashtag', props: { hashtag: value } }; };
export const N_URL = (value: string): MfmUrl => { return { type:'url', props: { url: value } }; };
export const LINK = (silent: boolean, url: string, children: MfmInline[]): MfmLink => { return { type:'link', props: { silent, url }, children }; };
export const CUSTOM_EMOJI = (name: string): MfmEmoji => { return { type:'emoji', props: { name: name } }; };
export const CUSTOM_EMOJI = (name: string): MfmCustomEmoji => { return { type:'customEmoji', props: { name: name } }; };
export const FN = (name: string, args: MfmFn['props']['args'], children: MfmFn['children']): MfmFn => { return { type:'fn', props: { name, args }, children }; };
export const UNI_EMOJI = (value: string): MfmEmoji => { return { type:'emoji', props: { emoji: value } }; };
export const UNI_EMOJI = (value: string): MfmUnicodeEmoji => { return { type:'unicodeEmoji', props: { emoji: value } }; };
export const TEXT = (value: string): MfmText => { return { type:'text', props: { text: value } }; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment