Skip to content

Commit 52d0b0d

Browse files
Merge pull request #434 from inertiajs/llsm-txt
md fixes
2 parents 48bc41d + 04411c1 commit 52d0b0d

File tree

4 files changed

+62
-44
lines changed

4 files changed

+62
-44
lines changed

app/Support/Markdown.php

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public static function fromJsx(string $jsx): string
3232
->beforeLast(')')
3333
->replace(array_keys($replace), array_values($replace))
3434
->replaceMatches('/className=\{[^}]*\}/', '')
35+
->replaceMatches('/style=\{\{[^}]*\}\}/', '')
3536
->explode(PHP_EOL)
3637
->map(function ($line) use (&$codeBlockType, &$inFencedCodeBlock, &$currentCodeBlockId, &$tabbedCodeBlocks, &$codeBlocks) {
3738
if (str_contains($line, '<TabbedCode')) {
@@ -56,7 +57,7 @@ public static function fromJsx(string $jsx): string
5657
return str($line)->replaceMatches('/\s+/', ' ')->replaceMatches('/\{\'<(.+)>\'\}/', '&lt;$1&gt;')->trim()->toString();
5758
}
5859

59-
if (str_contains($line, '`')) {
60+
if (str_contains($line, '`') && !str_contains($line, '\\`')) {
6061
$inFencedCodeBlock = !$inFencedCodeBlock;
6162
}
6263

@@ -89,36 +90,36 @@ public function __construct(protected array $tabbedBlocks, protected array $code
8990

9091
public function convert(ElementInterface $node): string
9192
{
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+
}
99102

100-
preg_match("/language: '([^']+)'/", $example, $matches);
101-
$language = $matches[1];
103+
$content = $this->tabbedBlocks[$node->getValue()];
102104

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+
}
105109

106-
preg_match("/description: '([^']+)'/m", $example, $matches);
107-
$description = $matches[1] ?? null;
110+
preg_match("/language: '([^']+)'/", $example, $matches);
111+
$language = $matches[1];
108112

109-
$code = str($example)->after('dedent`')->beforeLast('`,')->trim()->replaceMatches('/\s{7,}/', PHP_EOL)->toString();
113+
preg_match("/name: '([^']+)'/", $example, $matches);
114+
$name = $matches[1];
110115

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;
114118

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();
120120

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);
122123
}
123124

124125
public function getSupportedTags(): array

resources/js/Components/Layout.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ export default function Layout({ meta, children }) {
239239
<div className="relative -mt-8 hidden w-44 flex-shrink-0 xl:block">
240240
<div className="sticky top-0 pt-8">
241241
{meta.links && (
242-
<div className="mb-12">
242+
<div className="mb-8">
243243
<div className="text-xs font-bold uppercase tracking-widest text-gray-500">On this page</div>
244244
<ul>
245245
{meta.links.map((link, index) => (
@@ -252,6 +252,13 @@ export default function Layout({ meta, children }) {
252252
</ul>
253253
</div>
254254
)}
255+
<a
256+
href={window.location.pathname + '.md'}
257+
target="_blank"
258+
class="mb-12 inline-block rounded border border-gray-400 px-2 py-1 text-xs font-medium uppercase hover:border-gray-500"
259+
>
260+
View as Markdown
261+
</a>
255262
<div className="mb-6 text-xs font-bold uppercase tracking-widest text-gray-500">Our partners</div>
256263
<a className="block w-3/4" href="https://forge.laravel.com" title="Laravel Forge">
257264
<svg className="h-auto w-full" viewBox="0 0 217.38 39.97">

resources/js/Pages/the-protocol.jsx

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ export default function () {
3131
<Code>data-page</Code> attribute with a JSON encoded <A href="#the-page-object">page object</A> for the initial
3232
page. Inertia uses this information to boot your client-side framework and display the initial page component.
3333
</P>
34-
<div className="overflow-hidden rounded" style={{ background: '#202e59' }}>
35-
<div className="px-6 pt-6 font-mono text-sm text-white">
34+
<div className="mb-6 overflow-hidden rounded" style={{ background: '#202e59' }}>
35+
<div className="p-6 font-mono text-sm text-white">
3636
<div className="text-xs font-bold uppercase text-gray-600">Request</div>
3737
<div className="mt-1">
3838
<span className="text-blue-400">GET:</span> http://example.com/events/80
@@ -46,8 +46,11 @@ export default function () {
4646
<span className="text-blue-400">Content-Type:</span> text/html; charset=utf-8
4747
</div>
4848
</div>
49-
<CodeBlock className="p-6 leading-normal" language="html">
50-
{dedent`
49+
</div>
50+
<CodeBlock
51+
className="p-6 leading-normal"
52+
language="html"
53+
children={dedent`
5154
<html>
5255
<head>
5356
<title>My app</title>
@@ -61,8 +64,7 @@ export default function () {
6164
</body>
6265
</html>
6366
`}
64-
</CodeBlock>
65-
</div>
67+
/>
6668
<Notice>
6769
While the initial response is HTML, Inertia does not server-side render the JavaScript page components.
6870
</Notice>
@@ -76,8 +78,8 @@ export default function () {
7678
When the server detects the <Code>X-Inertia</Code> header, instead of responding with a full HTML document, it
7779
returns a JSON response with an encoded <A href="#the-page-object">page object</A>.
7880
</P>
79-
<div className="overflow-hidden rounded" style={{ background: '#202e59' }}>
80-
<div className="px-6 pt-6 font-mono text-sm text-white">
81+
<div className="mb-6 overflow-hidden rounded" style={{ background: '#202e59' }}>
82+
<div className="p-6 font-mono text-sm text-white">
8183
<div className="text-xs font-bold uppercase text-gray-600">Request</div>
8284
<div className="mt-1">
8385
<span className="text-blue-400">GET:</span> http://example.com/events/80
@@ -106,8 +108,11 @@ export default function () {
106108
<span className="text-blue-400">X-Inertia:</span> true
107109
</div>
108110
</div>
109-
<CodeBlock className="p-6 leading-normal" language="json">
110-
{dedent`
111+
</div>
112+
<CodeBlock
113+
className="p-6 leading-normal"
114+
language="json"
115+
children={dedent`
111116
{
112117
"component": "Event",
113118
"props": {
@@ -124,8 +129,7 @@ export default function () {
124129
"clearHistory": false
125130
}
126131
`}
127-
</CodeBlock>
128-
</div>
132+
/>
129133
<H2>The page object</H2>
130134
<P>
131135
Inertia shares data between the server and client via a page object. This object includes the necessary
@@ -188,7 +192,7 @@ export default function () {
188192
If "flash" session data exists when a <Code>409 Conflict</Code> response occurs, Inertia's server-side framework
189193
adapters will automatically reflash this data.
190194
</P>
191-
<div className="overflow-hidden rounded" style={{ background: '#202e59' }}>
195+
<div className="mb-6 overflow-hidden rounded" style={{ background: '#202e59' }}>
192196
<div className="p-6 font-mono text-sm text-white">
193197
<div className="text-xs font-bold uppercase text-gray-600">Request</div>
194198
<div className="mt-1">
@@ -236,8 +240,8 @@ export default function () {
236240
the final destination is different for some reason (eg. the user was logged out and is now on the login page),
237241
then no partial reloading will occur.
238242
</P>
239-
<div className="overflow-hidden rounded" style={{ background: '#202e59' }}>
240-
<div className="px-6 pt-6 font-mono text-sm text-white">
243+
<div className="mb-6 overflow-hidden rounded" style={{ background: '#202e59' }}>
244+
<div className="p-6 font-mono text-sm text-white">
241245
<div className="text-xs font-bold uppercase text-gray-600">Request</div>
242246
<div className="mt-1">
243247
<span className="text-blue-400">GET:</span> http://example.com/events
@@ -266,8 +270,11 @@ export default function () {
266270
<span className="text-blue-400">Content-Type:</span> application/json
267271
</div>
268272
</div>
269-
<CodeBlock className="p-6 leading-normal" language="json">
270-
{dedent`
273+
</div>
274+
<CodeBlock
275+
className="p-6 leading-normal"
276+
language="json"
277+
children={dedent`
271278
{
272279
"component": "Events",
273280
"props": {
@@ -279,8 +286,7 @@ export default function () {
279286
"version": "6b16b94d7c51cbe5b1fa42aac98241d5"
280287
}
281288
`}
282-
</CodeBlock>
283-
</div>
289+
/>
284290
</>
285291
)
286292
}

routes/web.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
*/
1818

1919
Route::get('{page?}', function ($page = 'index') {
20+
if ($page === '.md') {
21+
$page = 'index.md';
22+
}
23+
2024
$template = str($page)->before('.md')->toString();
2125
$templatePath = resource_path("js/Pages/$template.jsx");
2226

0 commit comments

Comments
 (0)