Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sfm-js
Manage
Activity
Members
Labels
Plan
Issues
2
Issue boards
Milestones
Iterations
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
TransFem.org
sfm-js
Commits
6ac576b7
Commit
6ac576b7
authored
3 years ago
by
marihachi
Browse files
Options
Downloads
Patches
Plain Diff
improve hashtag detection (#43)
parent
63997204
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/parser.pegjs
+10
-4
10 additions, 4 deletions
src/parser.pegjs
test/parser.ts
+51
-4
51 additions, 4 deletions
test/parser.ts
with
61 additions
and
8 deletions
src/parser.pegjs
+
10
−
4
View file @
6ac576b7
...
...
@@ -66,7 +66,7 @@ fullParser
= nodes:(&. n:(block / inline) { return n; })* { return mergeText(nodes); }
plainParser
= nodes:(&. n:(emojiCode / unicodeEmoji /
t
ext) { return n; })* { return mergeText(nodes); }
= nodes:(&. n:(emojiCode / unicodeEmoji /
plainT
ext) { return n; })* { return mergeText(nodes); }
inlineParser
= nodes:(&. n:inline { return n; })* { return mergeText(nodes); }
...
...
@@ -165,7 +165,7 @@ inline
/ url
/ link
/ fn
/
t
ext
/
inlineT
ext
// inline: emoji code
...
...
@@ -289,7 +289,7 @@ mentionHostPart
// inline: hashtag
hashtag
= "#" content:hashtagContent
= "#"
!("\uFE0F"? "\u20E3")
content:hashtagContent
{
return HASHTAG(content);
}
...
...
@@ -382,7 +382,13 @@ fnArg
// inline: text
text
inlineText
= !(LF / _) . &hashtag . { return text(); } // hashtag ignore
/ . /* text node */
// inline: text (for plainParser)
plainText
= . /* text node */
//
...
...
This diff is collapsed.
Click to expand it.
test/parser.ts
+
51
−
4
View file @
6ac576b7
...
...
@@ -4,7 +4,29 @@ import {
TEXT
,
CENTER
,
FN
,
UNI_EMOJI
,
MENTION
,
EMOJI_CODE
,
HASHTAG
,
N_URL
,
BOLD
,
SMALL
,
ITALIC
,
STRIKE
,
QUOTE
,
MATH_BLOCK
,
SEARCH
,
CODE_BLOCK
,
LINK
}
from
'
../built/index
'
;
describe
(
'
parser
'
,
()
=>
{
describe
(
'
PlainParser
'
,
()
=>
{
describe
(
'
text
'
,
()
=>
{
it
(
'
basic
'
,
()
=>
{
const
input
=
'
abc
'
;
const
output
=
[
TEXT
(
'
abc
'
)];
assert
.
deepStrictEqual
(
mfm
.
parsePlain
(
input
),
output
);
});
it
(
'
ignore hashtag
'
,
()
=>
{
const
input
=
'
abc#abc
'
;
const
output
=
[
TEXT
(
'
abc#abc
'
)];
assert
.
deepStrictEqual
(
mfm
.
parsePlain
(
input
),
output
);
});
it
(
'
keycap number sign
'
,
()
=>
{
const
input
=
'
abc#️⃣abc
'
;
const
output
=
[
TEXT
(
'
abc
'
),
UNI_EMOJI
(
'
#️⃣
'
),
TEXT
(
'
abc
'
)];
assert
.
deepStrictEqual
(
mfm
.
parsePlain
(
input
),
output
);
});
});
});
describe
(
'
FullParser
'
,
()
=>
{
describe
(
'
text
'
,
()
=>
{
it
(
'
普通のテキストを入力すると1つのテキストノードが返される
'
,
()
=>
{
const
input
=
'
abc
'
;
...
...
@@ -222,6 +244,12 @@ describe('parser', () => {
const
output
=
[
TEXT
(
'
今起きた
'
),
UNI_EMOJI
(
'
😇
'
)];
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
keycap number sign
'
,
()
=>
{
const
input
=
'
abc#️⃣123
'
;
const
output
=
[
TEXT
(
'
abc
'
),
UNI_EMOJI
(
'
#️⃣
'
),
TEXT
(
'
123
'
)];
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
});
describe
(
'
big
'
,
()
=>
{
...
...
@@ -397,9 +425,28 @@ describe('parser', () => {
// mention
describe
(
'
hashtag
'
,
()
=>
{
it
(
'
and unicode emoji
'
,
()
=>
{
const
input
=
'
#️⃣abc123#abc
'
;
const
output
=
[
UNI_EMOJI
(
'
#️⃣
'
),
TEXT
(
'
abc123
'
),
HASHTAG
(
'
abc
'
)];
it
(
'
basic
'
,
()
=>
{
const
input
=
'
before #abc after
'
;
const
output
=
[
TEXT
(
'
before
'
),
HASHTAG
(
'
abc
'
),
TEXT
(
'
after
'
)];
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
with keycap number sign
'
,
()
=>
{
const
input
=
'
#️⃣abc123 #abc
'
;
const
output
=
[
UNI_EMOJI
(
'
#️⃣
'
),
TEXT
(
'
abc123
'
),
HASHTAG
(
'
abc
'
)];
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
with keycap number sign 2
'
,
()
=>
{
const
input
=
`abc
#️⃣abc`
;
const
output
=
[
TEXT
(
'
abc
\n
'
),
UNI_EMOJI
(
'
#️⃣
'
),
TEXT
(
'
abc
'
)];
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
ignore a hashtag if the before char is neither a space nor an LF
'
,
()
=>
{
const
input
=
'
abc#abc
'
;
const
output
=
[
TEXT
(
'
abc#abc
'
)];
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
});
...
...
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