New markdown parsing tools. Labels decorator and extension parser.
This MR is a part of issue #87.
What's changed:
- Added
MarkdownDecorator
interface for decorating markdown nodes with our custom delimiters to process them later. - Added
ExtensionProcessor
interface. You can override it to process your own type of Markdown extension. All processors are defined as arguments toGitlabExtensionsDelimiterProcessor
- There are also
CompositeMarkdownDecorator
andCompositeVisitor
which are convenient way to provide our decorators and visitors to parser.
To be able to parse nodes where first-only delimiter is existent, we are decorating each of such nodes with out custom project-specific extension syntax.
Extension syntax looks like this: %%%%%${EXTENSION_TYPE}_${EXTENSION_ARGUMENTS}%%%%%
For example:
We have label ~single
defined in markdown.
We are making custom LabelDecorator that replaces such nodes to our custom extension:
%%%%%LABEL_SINGLE_single%%%%%
In this case out LABEL extension provides its own arguments string which have its own syntax:
SINGLE_single
where SINGLE
is node type (nodes can be single-word, multi-word and id-based) and single
is node name.
After decorating, markdown parser can detect our custom nodes using delimiters %%%%%
and launches our GitlabExtensionsDelimiterProcessor
It is detecting type of extension based on substring before the first _
symbol and decides which extension processor to launch, and propagates arguments to it.
Custom extension processor converts current Text
node to its own type.
After all, our custom nodes can be processed using Visitor.