mirror of
https://activitypub.software/TransFem-org/sfm-js
synced 2024-11-22 05:55:13 +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,
|
MfmCenter,
|
||||||
|
|
||||||
// inline
|
// inline
|
||||||
MfmEmoji,
|
MfmUnicodeEmoji,
|
||||||
|
MfmCustomEmoji,
|
||||||
MfmBold,
|
MfmBold,
|
||||||
MfmSmall,
|
MfmSmall,
|
||||||
MfmItalic,
|
MfmItalic,
|
||||||
|
|
20
src/node.ts
20
src/node.ts
|
@ -45,18 +45,26 @@ export type MfmCenter = {
|
||||||
children: MfmInline[];
|
children: MfmInline[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type MfmInline = MfmEmoji | MfmBold | MfmSmall | MfmItalic | MfmStrike | MfmInlineCode |
|
export type MfmInline = MfmUnicodeEmoji | MfmCustomEmoji | MfmBold | MfmSmall | MfmItalic | MfmStrike |
|
||||||
MfmMathInline | MfmMention | MfmHashtag | MfmUrl | MfmLink | MfmFn | MfmText;
|
MfmInlineCode | MfmMathInline | MfmMention | MfmHashtag | MfmUrl | MfmLink | MfmFn | MfmText;
|
||||||
|
|
||||||
export type MfmEmoji = {
|
export type MfmUnicodeEmoji = {
|
||||||
type: 'emoji';
|
type: 'unicodeEmoji';
|
||||||
props: {
|
props: {
|
||||||
emoji?: string;
|
emoji: string;
|
||||||
name?: string;
|
|
||||||
};
|
};
|
||||||
children?: [];
|
children?: [];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type MfmCustomEmoji = {
|
||||||
|
type: 'customEmoji';
|
||||||
|
props: {
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
children?: [];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
export type MfmBold = {
|
export type MfmBold = {
|
||||||
type: 'bold';
|
type: 'bold';
|
||||||
props?: { };
|
props?: { };
|
||||||
|
|
|
@ -158,7 +158,7 @@ emoji
|
||||||
customEmoji
|
customEmoji
|
||||||
= ":" name:emojiName ":"
|
= ":" name:emojiName ":"
|
||||||
{
|
{
|
||||||
return createNode('emoji', { name: name });
|
return createNode('customEmoji', { name: name });
|
||||||
}
|
}
|
||||||
|
|
||||||
emojiName
|
emojiName
|
||||||
|
@ -168,7 +168,7 @@ emojiName
|
||||||
unicodeEmoji
|
unicodeEmoji
|
||||||
= &{ return matchUnicodeEmoji(); } (&{ return consumeDynamically(); } .)+
|
= &{ return matchUnicodeEmoji(); } (&{ return consumeDynamically(); } .)+
|
||||||
{
|
{
|
||||||
return createNode('emoji', { emoji: text() });
|
return createNode('unicodeEmoji', { emoji: text() });
|
||||||
}
|
}
|
||||||
|
|
||||||
// inline: big
|
// 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>`;
|
return `<center>\n${ stringifyTree(node.children) }\n</center>`;
|
||||||
}
|
}
|
||||||
// inline
|
// inline
|
||||||
case 'emoji': {
|
case 'customEmoji': {
|
||||||
if (node.props.name) {
|
return `:${ node.props.name }:`;
|
||||||
return `:${ node.props.name }:`;
|
}
|
||||||
}
|
case 'unicodeEmoji': {
|
||||||
else if (node.props.emoji) {
|
return node.props.emoji;
|
||||||
return node.props.emoji;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case 'bold': {
|
case 'bold': {
|
||||||
return `**${ stringifyTree(node.children) }**`;
|
return `**${ stringifyTree(node.children) }**`;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import {
|
import {
|
||||||
MfmBold, MfmCenter, MfmCodeBlock, MfmEmoji, MfmFn, MfmHashtag, MfmInline,
|
MfmBold, MfmCenter, MfmCodeBlock, MfmCustomEmoji, MfmFn, MfmHashtag, MfmInline,
|
||||||
MfmInlineCode, MfmItalic, MfmLink, MfmMathBlock, MfmMathInline, MfmMention,
|
MfmInlineCode, MfmItalic, MfmLink, MfmMathBlock, MfmMathInline, MfmMention,
|
||||||
MfmNode, MfmQuote, MfmSearch, MfmSmall, MfmStrike, MfmText, MfmUrl
|
MfmNode, MfmQuote, MfmSearch, MfmSmall, MfmStrike, MfmText, MfmUnicodeEmoji, MfmUrl
|
||||||
} from '../built';
|
} from '../built';
|
||||||
|
|
||||||
export const QUOTE = (children: MfmNode[]): MfmQuote => { return { type:'quote', children }; };
|
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 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 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 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 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 } }; };
|
export const TEXT = (value: string): MfmText => { return { type:'text', props: { text: value } }; };
|
||||||
|
|
Loading…
Reference in a new issue