@@ -32,6 +32,7 @@ public static function fromJsx(string $jsx): string
32
32
->beforeLast (') ' )
33
33
->replace (array_keys ($ replace ), array_values ($ replace ))
34
34
->replaceMatches ('/className=\{[^}]*\}/ ' , '' )
35
+ ->replaceMatches ('/style=\{\{[^}]*\}\}/ ' , '' )
35
36
->explode (PHP_EOL )
36
37
->map (function ($ line ) use (&$ codeBlockType , &$ inFencedCodeBlock , &$ currentCodeBlockId , &$ tabbedCodeBlocks , &$ codeBlocks ) {
37
38
if (str_contains ($ line , '<TabbedCode ' )) {
@@ -56,7 +57,7 @@ public static function fromJsx(string $jsx): string
56
57
return str ($ line )->replaceMatches ('/\s+/ ' , ' ' )->replaceMatches ('/\{ \'<(.+)> \'\}/ ' , '<$1> ' )->trim ()->toString ();
57
58
}
58
59
59
- if (str_contains ($ line , '` ' )) {
60
+ if (str_contains ($ line , '` ' ) && ! str_contains ( $ line , '\\ ` ' ) ) {
60
61
$ inFencedCodeBlock = !$ inFencedCodeBlock ;
61
62
}
62
63
@@ -89,36 +90,36 @@ public function __construct(protected array $tabbedBlocks, protected array $code
89
90
90
91
public function convert (ElementInterface $ node ): string
91
92
{
92
- if ($ node ->getTagName () === 'tabbedcode ' ) {
93
- $ content = $ this ->tabbedBlocks [$ node ->getValue ()];
94
-
95
- return str ($ content )->after ('examples={ ' )->beforeLast ('} ' )->explode ('`, ' )->map (function ($ example ) {
96
- if (!str_contains ($ example , 'code: ' )) {
97
- return null ;
98
- }
93
+ if ($ node ->getTagName () === 'codeblock ' ) {
94
+ $ content = $ this ->codeBlocks [$ node ->getValue ()];
95
+ preg_match ('/language="([^"]+)"/ ' , $ content , $ matches );
96
+ $ language = $ matches [1 ];
97
+ preg_match ('/dedent`([^`]+)`/ ' , $ content , $ matches );
98
+ $ code = str ($ matches [1 ])->trim ()->replaceMatches ('/\s{7,}/ ' , PHP_EOL )->toString ();
99
+
100
+ return sprintf ("```%s \n%s \n``` " , $ language , $ code );
101
+ }
99
102
100
- preg_match ("/language: '([^']+)'/ " , $ example , $ matches );
101
- $ language = $ matches [1 ];
103
+ $ content = $ this ->tabbedBlocks [$ node ->getValue ()];
102
104
103
- preg_match ("/name: '([^']+)'/ " , $ example , $ matches );
104
- $ name = $ matches [1 ];
105
+ return str ($ content )->after ('examples={ ' )->beforeLast ('} ' )->explode ('`, ' )->map (function ($ example ) {
106
+ if (!str_contains ($ example , 'code: ' )) {
107
+ return null ;
108
+ }
105
109
106
- preg_match ("/description : '([^']+)'/m " , $ example , $ matches );
107
- $ description = $ matches [1 ] ?? null ;
110
+ preg_match ("/language : '([^']+)'/ " , $ example , $ matches );
111
+ $ language = $ matches [1 ];
108
112
109
- $ code = str ($ example )->after ('dedent` ' )->beforeLast ('`, ' )->trim ()->replaceMatches ('/\s{7,}/ ' , PHP_EOL )->toString ();
113
+ preg_match ("/name: '([^']+)'/ " , $ example , $ matches );
114
+ $ name = $ matches [1 ];
110
115
111
- return sprintf ("%s%s: \n\n```%s \n%s \n``` " , $ name , $ description ? ' ( ' . $ description . ') ' : '' , $ language , $ code );
112
- })->filter ()->implode (PHP_EOL . PHP_EOL );
113
- }
116
+ preg_match ("/description: '([^']+)'/m " , $ example , $ matches );
117
+ $ description = $ matches [1 ] ?? null ;
114
118
115
- $ content = $ this ->codeBlocks [$ node ->getValue ()];
116
- preg_match ('/language="([^"]+)"/ ' , $ content , $ matches );
117
- $ language = $ matches [1 ];
118
- preg_match ('/dedent`([^`]+)`/ ' , $ content , $ matches );
119
- $ code = str ($ matches [1 ])->trim ()->replaceMatches ('/\s{7,}/ ' , PHP_EOL )->toString ();
119
+ $ code = str ($ example )->after ('dedent` ' )->beforeLast ('`, ' )->trim ()->replaceMatches ('/\s{7,}/ ' , PHP_EOL )->toString ();
120
120
121
- return sprintf ("```%s \n%s \n``` " , $ language , $ code );
121
+ return sprintf ("%s%s: \n\n```%s \n%s \n``` " , $ name , $ description ? ' ( ' . $ description . ') ' : '' , $ language , $ code );
122
+ })->filter ()->implode (PHP_EOL . PHP_EOL );
122
123
}
123
124
124
125
public function getSupportedTags (): array
0 commit comments