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
196a64d3
Unverified
Commit
196a64d3
authored
3 years ago
by
marihachi
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
refactor parser (#78)
parent
ce17943f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/internal/parser.pegjs
+24
-32
24 additions, 32 deletions
src/internal/parser.pegjs
with
24 additions
and
32 deletions
src/internal/parser.pegjs
+
24
−
32
View file @
196a64d3
...
...
@@ -63,13 +63,13 @@
//
fullParser
= nodes:(&.
n:
full
{ return n; }
)* { return mergeText(nodes); }
= nodes:(&.
@
full)* { return mergeText(nodes); }
plainParser
= nodes:(&.
n:
plain
{ return n; }
)* { return mergeText(nodes); }
= nodes:(&.
@
plain)* { return mergeText(nodes); }
inlineParser
= nodes:(&.
n:
inline
{ return n; }
)* { return mergeText(nodes); }
= nodes:(&.
@
inline)* { return mergeText(nodes); }
//
// syntax list
...
...
@@ -131,7 +131,7 @@ quote
= &(BEGIN ">") q:quoteInner LF? { return q; }
quoteInner
= head:quote
Multi
Line tails:quote
Multi
Line+
= head:
(
quote
Line / quoteEmpty
Line
)
tails:
(
quote
Line / quoteEmpty
Line
)
+
{
const children = applyParser([head, ...tails].join('\n'), 'fullParser');
return QUOTE(children);
...
...
@@ -142,11 +142,8 @@ quoteInner
return QUOTE(children);
}
quoteMultiLine
= quoteLine / quoteEmptyLine
quoteLine
= BEGIN ">" _? text:$
(
CHAR+
)
END { return text; }
= BEGIN ">" _? text:$CHAR+ END { return text; }
quoteEmptyLine
= BEGIN ">" _? END { return ''; }
...
...
@@ -198,7 +195,7 @@ mathBlockLine
// block: center
center
= BEGIN "<center>" LF? content:(!(LF? "</center>" END)
i:
inline
{ return i; }
)+ LF? "</center>" END
= BEGIN "<center>" LF? content:(!(LF? "</center>" END)
@
inline)+ LF? "</center>" END
{
return CENTER(mergeText(content));
}
...
...
@@ -210,14 +207,11 @@ center
// inline: emoji code
emojiCode
= ":" name:
emojiCodeName
":"
= ":" name:
$[a-z0-9_+-]i+
":"
{
return EMOJI_CODE(name);
}
emojiCodeName
= [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.
...
...
@@ -230,7 +224,7 @@ unicodeEmoji
// inline: big
big
= "***" content:(!"***"
i:
inline
{ return i; }
)+ "***"
= "***" content:(!"***"
@
inline)+ "***"
{
return FN('tada', { }, mergeText(content));
}
...
...
@@ -238,15 +232,15 @@ big
// inline: bold
bold
= "**" content:(!"**"
i:
inline
{ return i; }
)+ "**"
= "**" content:(!"**"
@
inline)+ "**"
{
return BOLD(mergeText(content));
}
/ "<b>" content:(!"</b>"
i:
inline
{ return i; }
)+ "</b>"
/ "<b>" content:(!"</b>"
@
inline)+ "</b>"
{
return BOLD(mergeText(content));
}
/ "__" content:$(!"__"
c:
([a-z0-9]i / _)
{ return c; }
)+ "__"
/ "__" content:$(!"__"
@
([a-z0-9]i / _))+ "__"
{
const parsedContent = applyParser(content, 'inlineParser');
return BOLD(parsedContent);
...
...
@@ -255,7 +249,7 @@ bold
// inline: small
small
= "<small>" content:(!"</small>"
i:
inline
{ return i; }
)+ "</small>"
= "<small>" content:(!"</small>"
@
inline)+ "</small>"
{
return SMALL(mergeText(content));
}
...
...
@@ -267,7 +261,7 @@ italic
/ italicAlt
italicTag
= "<i>" content:(!"</i>"
i:
inline
{ return i; }
)+ "</i>"
= "<i>" content:(!"</i>"
@
inline)+ "</i>"
{
return ITALIC(mergeText(content));
}
...
...
@@ -287,11 +281,11 @@ italicAlt
// inline: strike
strike
= "~~" content:(!("~" / LF)
i:
inline
{ return i; }
)+ "~~"
= "~~" content:(!("~" / LF)
@
inline)+ "~~"
{
return STRIKE(mergeText(content));
}
/ "<s>" content:(!("</s>" / LF)
i:
inline
{ return i; }
)+ "</s>"
/ "<s>" content:(!("</s>" / LF)
@
inline)+ "</s>"
{
return STRIKE(mergeText(content));
}
...
...
@@ -299,7 +293,7 @@ strike
// inline: inlineCode
inlineCode
= "`" content:$(![`´]
c:
CHAR
{ return c; }
)+ "`"
= "`" content:$(![`´] CHAR)+ "`"
{
return INLINE_CODE(content);
}
...
...
@@ -307,7 +301,7 @@ inlineCode
// inline: mathInline
mathInline
= "\\(" content:$(!"\\)"
c:
CHAR
{ return c; }
)+ "\\)"
= "\\(" content:$(!"\\)" CHAR)+ "\\)"
{
return MATH_INLINE(content);
}
...
...
@@ -315,7 +309,7 @@ mathInline
// inline: mention
mention
= "@" name:mentionName host:("@"
host:
mentionHost
{ return host; }
)?
= "@" name:mentionName host:("@"
@
mentionHost)?
{
return MENTION(name, host, text());
}
...
...
@@ -355,7 +349,8 @@ invalidHashtagContent
= [0-9]+
hashtagContentPart
= hashtagBracketPair / hashtagChar
= hashtagBracketPair
/ hashtagChar
hashtagBracketPair
= "(" hashtagContent* ")"
...
...
@@ -407,16 +402,13 @@ link
}
linkLabel
= parts:linkLabelPart+
{
return parts;
}
= linkLabelPart+
linkLabelPart
= url { return text(); /* text node */ }
/ link { return text(); /* text node */ }
/ mention { return text(); /* text node */ }
/ !"]"
n:
inline
{ return n; }
/ !"]"
@
inline
linkUrl
= url { return text(); }
...
...
@@ -438,7 +430,7 @@ fnVer2
}
fnArgs
= "." head:fnArg tails:(","
arg:
fnArg
{ return arg; }
)*
= "." head:fnArg tails:(","
@
fnArg)*
{
const args = { };
for (const pair of [head, ...tails]) {
...
...
@@ -458,7 +450,7 @@ fnArg
}
fnContentPart
= !("]")
i:
inline
{ return i; }
= !("]")
@
inline
// inline: text
...
...
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