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

fix link label

parent c60ba229
No related branches found
No related tags found
No related merge requests found
......@@ -30,11 +30,17 @@
consumeDynamically
} = require('./util');
function applyParser(input, startRule) {
let parseFunc = peg$parse;
return parseFunc(input, startRule ? { startRule } : { });
function applyParser(input, startRule, opts) {
const parseFunc = peg$parse;
const parseOpts = { ...(opts || {}) };
if (startRule) parseOpts.startRule = startRule;
return parseFunc(input, parseOpts);
}
// link
const linkLabel = options.linkLabel || false;
// emoji
const emojiRegex = require('twemoji-parser/dist/lib/regex').default;
......@@ -355,7 +361,7 @@ mathInline
// inline: mention
mention
= "@" name:mentionName host:("@" @mentionHost)?
= &{ return !linkLabel; } "@" name:mentionName host:("@" @mentionHost)?
{
return MENTION(name, host, text());
}
......@@ -397,11 +403,11 @@ hashPairInner
// inline: URL
url
= "<" url:$("http" "s"? "://" (!(">" / _) CHAR)+) ">"
= &{ return !linkLabel; } "<" url:$("http" "s"? "://" (!(">" / _) CHAR)+) ">"
{
return N_URL(url, true);
}
/ "http" "s"? "://" (&([.,]+ urlContentPart) . / urlContentPart)+
/ &{ return !linkLabel; } "http" "s"? "://" (&([.,]+ urlContentPart) . / urlContentPart)+
{
// NOTE: last char is neither "." nor ",".
return N_URL(text());
......@@ -418,27 +424,19 @@ urlPairInner
// inline: link
link
= silent:"?"? "[" label:linkLabel "](" url:url ")"
= &{ return !linkLabel; } silent:"?"? "[" label:linkLabel "](" url:url ")"
{
return LINK((silent != null), url.props.url, mergeText(label));
}
linkLabel
= (!"]" @linkLabelPart)+
linkLabelPart
= emojiCode
/ unicodeEmoji
/ big
/ bold
/ small
/ italic
/ strike
/ inlineCode
/ mathInline
/ hashtag
/ fn
/ inlineText
= (!"](" CHAR)+
{
const label = applyParser(text(), 'inlineParser', {
linkLabel: true
});
return label;
}
// inline: fn
......
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