Isolate node of unicode emoji and custom emoji.

This commit is contained in:
marihachi 2021-03-28 13:29:07 +09:00
parent f59529ffde
commit c975820083
5 changed files with 27 additions and 23 deletions

View file

@ -46,7 +46,8 @@ export {
MfmCenter,
// inline
MfmEmoji,
MfmUnicodeEmoji,
MfmCustomEmoji,
MfmBold,
MfmSmall,
MfmItalic,

View file

@ -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?: { };

View file

@ -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

View file

@ -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) }**`;

View file

@ -1,7 +1,7 @@
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 } }; };