Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sfm-js
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dakkar
sfm-js
Commits
c9758200
Commit
c9758200
authored
3 years ago
by
marihachi
Browse files
Options
Downloads
Patches
Plain Diff
Isolate node of unicode emoji and custom emoji.
parent
f59529ff
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
src/index.ts
+2
-1
2 additions, 1 deletion
src/index.ts
src/node.ts
+14
-6
14 additions, 6 deletions
src/node.ts
src/parser.pegjs
+2
-2
2 additions, 2 deletions
src/parser.pegjs
src/util.ts
+5
-10
5 additions, 10 deletions
src/util.ts
test/node.ts
+4
-4
4 additions, 4 deletions
test/node.ts
with
27 additions
and
23 deletions
src/index.ts
+
2
−
1
View file @
c9758200
...
...
@@ -46,7 +46,8 @@ export {
MfmCenter
,
// inline
MfmEmoji
,
MfmUnicodeEmoji
,
MfmCustomEmoji
,
MfmBold
,
MfmSmall
,
MfmItalic
,
...
...
This diff is collapsed.
Click to expand it.
src/node.ts
+
14
−
6
View file @
c9758200
...
...
@@ -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
=
Mfm
UnicodeEmoji
|
MfmCustom
Emoji
|
MfmBold
|
MfmSmall
|
MfmItalic
|
MfmStrike
|
MfmInlineCode
|
MfmMathInline
|
MfmMention
|
MfmHashtag
|
MfmUrl
|
MfmLink
|
MfmFn
|
MfmText
;
export
type
MfmEmoji
=
{
type
:
'
e
moji
'
;
export
type
Mfm
Unicode
Emoji
=
{
type
:
'
unicodeE
moji
'
;
props
:
{
emoji
?:
string
;
name
?:
string
;
emoji
:
string
;
};
children
?:
[];
};
export
type
MfmCustomEmoji
=
{
type
:
'
customEmoji
'
;
props
:
{
name
:
string
;
};
children
?:
[];
};
export
type
MfmBold
=
{
type
:
'
bold
'
;
props
?:
{
};
...
...
This diff is collapsed.
Click to expand it.
src/parser.pegjs
+
2
−
2
View file @
c9758200
...
...
@@ -158,7 +158,7 @@ emoji
customEmoji
= ":" name:emojiName ":"
{
return createNode('
e
moji', { name: name });
return createNode('
customE
moji', { name: name });
}
emojiName
...
...
@@ -168,7 +168,7 @@ emojiName
unicodeEmoji
= &{ return matchUnicodeEmoji(); } (&{ return consumeDynamically(); } .)+
{
return createNode('
e
moji', { emoji: text() });
return createNode('
unicodeE
moji', { emoji: text() });
}
// inline: big
...
...
This diff is collapsed.
Click to expand it.
src/util.ts
+
5
−
10
View file @
c9758200
...
...
@@ -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
)
}
**`
;
...
...
This diff is collapsed.
Click to expand it.
test/node.ts
+
4
−
4
View file @
c9758200
import
{
MfmBold
,
MfmCenter
,
MfmCodeBlock
,
MfmEmoji
,
MfmFn
,
MfmHashtag
,
MfmInline
,
MfmBold
,
MfmCenter
,
MfmCodeBlock
,
Mfm
Custom
Emoji
,
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
:
'
e
moji
'
,
props
:
{
name
:
name
}
};
};
export
const
CUSTOM_EMOJI
=
(
name
:
string
):
Mfm
Custom
Emoji
=>
{
return
{
type
:
'
customE
moji
'
,
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
:
'
e
moji
'
,
props
:
{
emoji
:
value
}
};
};
export
const
UNI_EMOJI
=
(
value
:
string
):
Mfm
Unicode
Emoji
=>
{
return
{
type
:
'
unicodeE
moji
'
,
props
:
{
emoji
:
value
}
};
};
export
const
TEXT
=
(
value
:
string
):
MfmText
=>
{
return
{
type
:
'
text
'
,
props
:
{
text
:
value
}
};
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment