mirror of
https://activitypub.software/TransFem-org/sfm-js
synced 2024-11-21 21:55:09 +00:00
Isolate node of unicode emoji and custom emoji.
This commit is contained in:
parent
f59529ffde
commit
c975820083
5 changed files with 27 additions and 23 deletions
|
@ -46,7 +46,8 @@ export {
|
|||
MfmCenter,
|
||||
|
||||
// inline
|
||||
MfmEmoji,
|
||||
MfmUnicodeEmoji,
|
||||
MfmCustomEmoji,
|
||||
MfmBold,
|
||||
MfmSmall,
|
||||
MfmItalic,
|
||||
|
|
20
src/node.ts
20
src/node.ts
|
@ -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
|
||||
|
|
15
src/util.ts
15
src/util.ts
|
@ -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) }**`;
|
||||
|
|
|
@ -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 } }; };
|
||||
|
|
Loading…
Reference in a new issue