55use Thunder \Shortcode \Parser \ParserInterface ;
66use Thunder \Shortcode \Shortcode \ParsedShortcodeInterface ;
77use Thunder \Shortcode \Shortcode \ProcessedShortcode ;
8+ use Thunder \Shortcode \Shortcode \ShortcodeInterface ;
89
910/**
1011 * @author Tomasz Kowalczyk <tomasz@kowalczyk.cc>
@@ -39,7 +40,7 @@ public function process($text)
3940
4041 while ($ iterations --) {
4142 $ context ->iterationNumber ++;
42- $ newText = $ this ->processIteration ($ text , $ context );
43+ $ newText = $ this ->processIteration ($ text , $ context, null );
4344 if ($ newText === $ text ) {
4445 break ;
4546 }
@@ -50,7 +51,7 @@ public function process($text)
5051 return $ text ;
5152 }
5253
53- private function processIteration ($ text , ProcessorContext $ context )
54+ private function processIteration ($ text , ProcessorContext $ context, ShortcodeInterface $ parent = null )
5455 {
5556 if (null !== $ this ->recursionDepth && $ context ->recursionLevel > $ this ->recursionDepth ) {
5657 return $ text ;
@@ -60,6 +61,7 @@ private function processIteration($text, ProcessorContext $context)
6061 $ shortcodes = $ this ->parser ->parse ($ text );
6162 $ replaces = array ();
6263 foreach ($ shortcodes as $ shortcode ) {
64+ $ context ->parent = $ parent ;
6365 $ this ->prepareHandlerContext ($ shortcode , $ context );
6466 $ handler = $ this ->handlers ->get ($ shortcode ->getName ());
6567 $ replace = $ this ->processHandler ($ shortcode , $ context , $ handler );
@@ -83,6 +85,7 @@ private function prepareHandlerContext(ParsedShortcodeInterface $shortcode, Proc
8385 $ context ->shortcodeText = $ shortcode ->getText ();
8486 $ context ->offset = $ shortcode ->getOffset ();
8587 $ context ->shortcode = $ shortcode ;
88+ $ context ->originalContent = $ shortcode ->getContent ();
8689 }
8790
8891 private function processHandler (ParsedShortcodeInterface $ parsed , ProcessorContext $ context , $ handler )
@@ -99,10 +102,8 @@ private function processRecursion(ParsedShortcodeInterface $shortcode, Processor
99102 {
100103 if ($ this ->autoProcessContent && null !== $ shortcode ->getContent ()) {
101104 $ context ->recursionLevel ++;
102- $ context ->parent = $ shortcode ;
103105 // this is safe from using max iterations value because it's manipulated in process() method
104- $ content = $ this ->processIteration ($ shortcode ->getContent (), $ context );
105- $ context ->parent = null ;
106+ $ content = $ this ->processIteration ($ shortcode ->getContent (), $ context , $ shortcode );
106107 $ context ->recursionLevel --;
107108
108109 return $ shortcode ->withContent ($ content );
0 commit comments