@@ -23,42 +23,21 @@ public function __construct(array $shortcodes)
2323
2424 public function getMatchDefinition (): InlineParserMatch
2525 {
26- foreach ( \array_keys ( $ this -> shortcodes ) as $ code ) {
27- return InlineParserMatch::join (
28- InlineParserMatch::string ( ' { ' . $ code ),
29- InlineParserMatch::regex ('.*?\} ' )
30- );
31- }
26+ return InlineParserMatch:: join (
27+ InlineParserMatch::string ( ' { ' ),
28+ InlineParserMatch::oneOf (... \array_keys ( $ this -> shortcodes ) ),
29+ InlineParserMatch::regex ('.*? ' ),
30+ InlineParserMatch:: string ( ' } ' )
31+ );
3232 }
3333
3434 public function parse (InlineParserContext $ inlineContext ): bool
3535 {
36- $ shortcode = new Shortcode (\substr ($ inlineContext ->getMatches ()[1 ], 1 ));
37- $ shortcode ->loadAttrsFromString (\substr ($ inlineContext ->getMatches ()[2 ], 0 , -1 ));
38- // $doc = new DOMDocument();
39- // $doc->loadHTML('<body ' . \substr($inlineContext->getMatches()[2], 0, -1) . ' />');
40- // $body = $doc->getElementsByTagName('body')[0];
41- // for ($i = 0; $i < $body->attributes->length; ++$i) {
42- // $name = $body->attributes->item($i)->name;
43- // $value = $body->getAttribute($name);
44- // $shortcode->setAttr($name, $value);
45- // }
36+ $ shortcode = new Shortcode ($ inlineContext ->getMatches ()[2 ]);
37+ $ shortcode ->loadAttrsFromString ($ inlineContext ->getMatches ()[3 ]);
4638 $ inlineContext ->getCursor ()->advanceBy ($ inlineContext ->getFullMatchLength ());
4739 $ inlineContext ->getContainer ()->appendChild ($ shortcode );
4840
4941 return true ;
5042 }
51-
52- // /**
53- // * @inheritdoc
54- // */
55- // public function tryStart(Cursor $cursor, MarkdownParserStateInterface $parserState): ?BlockStart {
56-
57- // $opening = $cursor->match('/^\{([^ ]+)/');
58- // dump(array_keys($this->shortcodes), $opening, $cursor);
59- // if ($opening === null) {
60- // return BlockStart::none();
61- // }
62- // return BlockStart::of(new ShortcodeParser(substr($opening, 1)))->at($cursor);
63- // }
6443}
0 commit comments