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

customEmoji -> emojiCode

parent c9758200
No related branches found
No related tags found
No related merge requests found
...@@ -47,7 +47,7 @@ export { ...@@ -47,7 +47,7 @@ export {
// inline // inline
MfmUnicodeEmoji, MfmUnicodeEmoji,
MfmCustomEmoji, MfmEmojiCode,
MfmBold, MfmBold,
MfmSmall, MfmSmall,
MfmItalic, MfmItalic,
......
...@@ -45,7 +45,7 @@ export type MfmCenter = { ...@@ -45,7 +45,7 @@ export type MfmCenter = {
children: MfmInline[]; children: MfmInline[];
}; };
export type MfmInline = MfmUnicodeEmoji | MfmCustomEmoji | MfmBold | MfmSmall | MfmItalic | MfmStrike | export type MfmInline = MfmUnicodeEmoji | MfmEmojiCode | MfmBold | MfmSmall | MfmItalic | MfmStrike |
MfmInlineCode | MfmMathInline | MfmMention | MfmHashtag | MfmUrl | MfmLink | MfmFn | MfmText; MfmInlineCode | MfmMathInline | MfmMention | MfmHashtag | MfmUrl | MfmLink | MfmFn | MfmText;
export type MfmUnicodeEmoji = { export type MfmUnicodeEmoji = {
...@@ -56,15 +56,14 @@ export type MfmUnicodeEmoji = { ...@@ -56,15 +56,14 @@ export type MfmUnicodeEmoji = {
children?: []; children?: [];
}; };
export type MfmCustomEmoji = { export type MfmEmojiCode = {
type: 'customEmoji'; type: 'emojiCode';
props: { props: {
name: string; name: string;
}; };
children?: []; children?: [];
}; };
export type MfmBold = { export type MfmBold = {
type: 'bold'; type: 'bold';
props?: { }; props?: { };
......
...@@ -42,7 +42,7 @@ fullParser ...@@ -42,7 +42,7 @@ fullParser
= nodes:(&. n:(block / inline) { return n; })* { return mergeText(nodes); } = nodes:(&. n:(block / inline) { return n; })* { return mergeText(nodes); }
plainParser plainParser
= nodes:(&. n:(emoji / text) { return n; })* { return mergeText(nodes); } = nodes:(&. n:(emojiCode / unicodeEmoji / text) { return n; })* { return mergeText(nodes); }
inlineParser inlineParser
= nodes:(&. n:inline { return n; })* { return mergeText(nodes); } = nodes:(&. n:inline { return n; })* { return mergeText(nodes); }
...@@ -135,7 +135,8 @@ center ...@@ -135,7 +135,8 @@ center
// //
inline inline
= emoji = emojiCode
/ unicodeEmoji
/ big / big
/ bold / bold
/ small / small
...@@ -150,20 +151,19 @@ inline ...@@ -150,20 +151,19 @@ inline
/ fn / fn
/ text / text
// inline: emoji // inline: emoji code
emoji emojiCode
= customEmoji / unicodeEmoji = ":" name:emojiCodeName ":"
customEmoji
= ":" name:emojiName ":"
{ {
return createNode('customEmoji', { name: name }); return createNode('emojiCode', { name: name });
} }
emojiName emojiCodeName
= [a-z0-9_+-]i+ { return text(); } = [a-z0-9_+-]i+ { return text(); }
// inline: unicode emoji
// NOTE: if the text matches one of the emojis, it will count the length of the emoji sequence and consume it. // NOTE: if the text matches one of the emojis, it will count the length of the emoji sequence and consume it.
unicodeEmoji unicodeEmoji
= &{ return matchUnicodeEmoji(); } (&{ return consumeDynamically(); } .)+ = &{ return matchUnicodeEmoji(); } (&{ return consumeDynamically(); } .)+
......
...@@ -60,7 +60,7 @@ export function stringifyNode(node: MfmNode): string { ...@@ -60,7 +60,7 @@ 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 'customEmoji': { case 'emojiCode': {
return `:${ node.props.name }:`; return `:${ node.props.name }:`;
} }
case 'unicodeEmoji': { case 'unicodeEmoji': {
......
...@@ -2,7 +2,7 @@ import assert from 'assert'; ...@@ -2,7 +2,7 @@ import assert from 'assert';
import { inspect, parse, parsePlain, toString } from '../built/index'; import { inspect, parse, parsePlain, toString } from '../built/index';
import { createNode } from '../built/util'; import { createNode } from '../built/util';
import { import {
TEXT, CENTER, FN, UNI_EMOJI, MENTION, CUSTOM_EMOJI, HASHTAG, N_URL, BOLD, SMALL, ITALIC, STRIKE, QUOTE, MATH_BLOCK, SEARCH, CODE_BLOCK TEXT, CENTER, FN, UNI_EMOJI, MENTION, EMOJI_CODE, HASHTAG, N_URL, BOLD, SMALL, ITALIC, STRIKE, QUOTE, MATH_BLOCK, SEARCH, CODE_BLOCK
} from './node'; } from './node';
describe('text', () => { describe('text', () => {
...@@ -210,10 +210,10 @@ describe('center', () => { ...@@ -210,10 +210,10 @@ describe('center', () => {
}); });
}); });
describe('custom emoji', () => { describe('emoji code', () => {
it('basic', () => { it('basic', () => {
const input = ':abc:'; const input = ':abc:';
const output = [CUSTOM_EMOJI('abc')]; const output = [EMOJI_CODE('abc')];
assert.deepStrictEqual(parse(input), output); assert.deepStrictEqual(parse(input), output);
}); });
}); });
......
import { import {
MfmBold, MfmCenter, MfmCodeBlock, MfmCustomEmoji, MfmFn, MfmHashtag, MfmInline, MfmBold, MfmCenter, MfmCodeBlock, MfmEmojiCode, MfmFn, MfmHashtag, MfmInline,
MfmInlineCode, MfmItalic, MfmLink, MfmMathBlock, MfmMathInline, MfmMention, MfmInlineCode, MfmItalic, MfmLink, MfmMathBlock, MfmMathInline, MfmMention,
MfmNode, MfmQuote, MfmSearch, MfmSmall, MfmStrike, MfmText, MfmUnicodeEmoji, MfmUrl MfmNode, MfmQuote, MfmSearch, MfmSmall, MfmStrike, MfmText, MfmUnicodeEmoji, MfmUrl
} from '../built'; } from '../built';
...@@ -20,7 +20,7 @@ export const MENTION = (username: string, host: string | null, acct: string): Mf ...@@ -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): MfmCustomEmoji => { return { type:'customEmoji', props: { name: name } }; }; export const EMOJI_CODE = (name: string): MfmEmojiCode => { return { type:'emojiCode', 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): MfmUnicodeEmoji => { return { type:'unicodeEmoji', 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 } }; };
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