Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/message-parser/src/grammar.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
strike,
task,
tasks,
unnest,
unorderedList,
} = require('./utils');
}}
Expand Down Expand Up @@ -227,8 +228,10 @@ InlineItem = Whitespace
*
*/
References
= "[" title:LinkTitle* "](" href:LinkRef ")" { return title.length ? link(href, reducePlainTexts(title)) : link(href); }
= "[" title:LinkTitle* "](" href:LinkRef ")" { return title.length ? link(href, reducePlainTexts(flatten(title))) : link(href); }
/ "<" href:LinkRef "|" title:LinkTitle2 ">" { return link(href, [plain(title)]); }
LinkTitle = (Whitespace / Emphasis) / balanced / anyTitle:$[^\[\]] { return plain(anyTitle) }
balanced = "[" t:LinkTitle* "]" { return reducePlainTexts([plain("["), ...(t || []), plain("]")]) }

LinkTitle = (Whitespace / EmphasisForReferences) / anyTitle:$(!("](" .) .) { return plain(anyTitle) }

Expand Down
8 changes: 8 additions & 0 deletions packages/message-parser/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ const joinEmoji = (

return current;
};
export const unnest = (inputValues: Paragraph['value']): Paragraph['value'] =>
inputValues.reduce(
(accumulator, currentValue) => [
...accumulator,
...(Array.isArray(currentValue) ? currentValue : [currentValue]),
],
[] as Paragraph['value']
);

export const reducePlainTexts = (
values: Paragraph['value']
Expand Down