support for block & inline tags

This commit is contained in:
Guilhem Fauré 2023-05-02 10:56:28 +02:00
parent d1702d6d19
commit c0a7bc0f29
2 changed files with 39 additions and 24 deletions

View File

@ -1,12 +1,12 @@
// Flexible SPIP Markup grammar for Lark parser // Flexible SPIP Markup grammar for Lark parser
start: _N* block ( _N+ block )* _N* start: _N* block ( _N+ block )* _N*
?block: paragraph ?block: HORIZONTAL_RULE -> horizontal_rule
| heading | heading
| list | list
| table | table
| tag | _block_tag
| HORIZONTAL_RULE -> horizontal_rule | paragraph
HORIZONTAL_RULE: /----+/ HORIZONTAL_RULE: /----+/
@ -31,42 +31,55 @@ _TBL.1: "|"
heading: _H _inline{MARKED_TEXT}+ "}}}" heading: _H _inline{MARKED_TEXT}+ "}}}"
_H: "{{{" _H: "{{{"
_block_tag.1: pair_block_tag
| orphan_block_tag
pair_block_tag: _PAIR_TAG_ANGLE TAG_NAME ( "|" TAG_OPTION )* ">" start "</" _PURE_TEXT ">" -> tag
orphan_block_tag: _ORPHAN_TAG_ANGLE "/"? TAG_NAME ( "|" TAG_OPTION )* ">" -> orphan_tag
_PAIR_TAG_ANGLE: /\<(?=([0-9A-Za-z_:\/\-\.]+)(?:\|[0-9A-Za-z_:\/\-\.]+)*\>[\s\S]+\<\/\1\>)/
_ORPHAN_TAG_ANGLE: /\<(?=([0-9A-Za-z_:\/\-\.]+)(?:\|[0-9A-Za-z_:\/\-\.]+)*\>)(?![\s\S]+\<\/\1\>)/
paragraph.-1: ( _inline{TEXT} _N? )+ paragraph.-1: ( _inline{TEXT} _N? )+
_inline{text}: text _inline{text}: _inline_tag
| _link
| emphasis | emphasis
| strong | strong
| anchor | text
| tag
TEXT.-1: /(?:[^\r\n\{](?![^\[\n\r]*->))+/ _inline_tag.1: pair_inline_tag
TABLE_TEXT.-1: /[^\|\r\n\{]+/ | orphan_inline_tag
MARKED_TEXT.-1: /[^\}\r\n\{]+/
strong: _B ( _inline{MARKED_TEXT} )+ ( "}}" | _N ) pair_inline_tag: _PAIR_INLINE_TAG_ANGLE TAG_NAME ( "|" TAG_OPTION )* ">" paragraph ( "</" _PURE_TEXT ">" | _N ) -> tag
emphasis: _I ( _inline{MARKED_TEXT} )+ ( "}" | _N ) orphan_inline_tag: _INLINE_TAG_ANGLE "/"? TAG_NAME ( "|" TAG_OPTION )* ">" -> orphan_tag
_B: /{{(?=[^\{])/
_I: /{(?=[^\{])/
?anchor: anchor_footnote _PAIR_INLINE_TAG_ANGLE: /\<(?=(?:quote|section|div|cadre|frame|code|poesie)(?:\|[0-9A-Za-z_:\/\-\.]+)*\>)/
| anchor_wikipedia _INLINE_TAG_ANGLE: /\<(?=([0-9A-Za-z_:\/\-\.]+)(?:\|[0-9A-Za-z_:\/\-\.]+)*\>)/
| anchor_normal -> anchor
anchor_footnote: _FOOT HREF "]]" _link: footnote
anchor_wikipedia: _WIKI HREF "]" | wikilink
anchor_normal: _A A_TEXT "->" HREF "]" | anchor
footnote: _FOOT HREF "]]"
wikilink: _WIKI HREF "]"
anchor: _A A_TEXT "->" HREF "]"
_FOOT: /\[\[/ _FOOT: /\[\[/
_WIKI: /\[\?/ _WIKI: /\[\?/
_A: /\[(?=[^\[\n\r]+->)/ _A: /\[(?=[^\[\n\r]+->)/
HREF: _PURE_TEXT HREF: _PURE_TEXT
A_TEXT: /[^\r\n\{]+?(?=->)/ A_TEXT: /[^\r\n\{]+?(?=->)/
tag.1: start_tag block? end_tag? strong: _B ( _inline{MARKED_TEXT} )+ ( "}}" | _N )
emphasis: _I ( _inline{MARKED_TEXT} )+ ( "}" | _N )
_B: /{{(?=[^\{])/
_I: /{(?=[^\{])/
start_tag: _STAG TAG_NAME ( "|" TAG_OPTION )* ">" TEXT.-1: / (?:[^\r\n\{\<](?![^\[\n\r]*->))+
end_tag: _ETAG TAG_NAME ( "|" TAG_OPTION )* ">" | (?:\<(?![0-9A-Za-z_:\/\-\.]+\>))+
_ETAG.1: /<\/(?=[0-9A-Za-z_:\|\/\-\.]+>)/ /x
_STAG.1: /<(?=[0-9A-Za-z_:\|\/\-\.]+>)/ TABLE_TEXT.-1: /(?:[^\|\r\n\{](?![^\[\n\r]*->))+/
MARKED_TEXT.-1: /(?:[^\}\r\n\{](?![^\[\n\r]*->))+/
TAG_NAME: _PURE_TEXT TAG_NAME: _PURE_TEXT
TAG_OPTION: _PURE_TEXT TAG_OPTION: _PURE_TEXT

View File

@ -62,8 +62,10 @@ Lorem ipsum dolor sit amet, officia excepteur ex fugiat reprehenderit enim labor
{{{Cadre de code}}} {{{Cadre de code}}}
<cadre> <cadre>
def spipParser(): def spipParser():
return False return False
</cadre> </cadre>
{{{Citation sans balise fermante}}} {{{Citation sans balise fermante}}}