Skip to content

Commit 619936e

Browse files
committed
[FEATURE] Create a rst theme to convert markdown
Convert basic mark-down into restructured Text * code-blocks
1 parent 7dc8588 commit 619936e

File tree

5 files changed

+88
-3
lines changed

5 files changed

+88
-3
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
```
2-
{{ node.value|raw }}
3-
```
1+
.. code-block:: plaintext
2+
3+
{{ renderRstIndent(node.value|raw, 1)|raw }}

packages/guides-theme-rst/src/RstTheme/Twig/RstExtension.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,16 @@ public function getFunctions(): array
3939
{
4040
return [
4141
new TwigFunction('renderRstTitle', $this->renderRstTitle(...), ['is_safe' => ['rst'], 'needs_context' => false]),
42+
new TwigFunction('renderRstIndent', $this->renderRstIndent(...), ['is_safe' => ['rst'], 'needs_context' => false]),
4243
];
4344
}
4445

46+
public function renderRstIndent(string $text, int $indentNr): string
47+
{
48+
$indent = str_repeat(' ', $indentNr*4);
49+
return preg_replace('/^/m', $indent, $text);
50+
}
51+
4552
public function renderRstTitle(TitleNode $node, string $content): string
4653
{
4754
$headerSyntax = HeaderSyntax::from(min($node->getLevel(), 6));
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
=========================
2+
Markdown with Code Blocks
3+
=========================
4+
5+
.. code-block:: plaintext
6+
7+
<html>
8+
<head>
9+
</head>
10+
</html>
11+
12+
13+
Fenced Code Blocks
14+
==================
15+
16+
.. code-block:: plaintext
17+
18+
{
19+
"firstName": "John",
20+
"lastName": "Smith",
21+
"age": 25
22+
}
23+
24+
25+
26+
27+
Fenced Code Block with caption
28+
==============================
29+
30+
.. code-block:: plaintext
31+
32+
procedure startSwinging(swing, child)
33+
while child.isComfortable()
34+
swing.giveGentlePush()
35+
waitForNextIteration()
36+
end while
37+
end procedure
38+
39+
40+
41+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<guides xmlns="https://www.phpdoc.org/guides"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="https://www.phpdoc.org/guides packages/guides-cli/resources/schema/guides.xsd"
5+
input-format="md"
6+
theme="rst"
7+
>
8+
<project title="Project Title" version="6.4"/>
9+
<extension class="phpDocumentor\Guides\RstTheme"/>
10+
<output-format>rst</output-format>
11+
</guides>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Markdown with Code Blocks
2+
3+
<html>
4+
<head>
5+
</head>
6+
</html>
7+
8+
## Fenced Code Blocks
9+
10+
```
11+
{
12+
"firstName": "John",
13+
"lastName": "Smith",
14+
"age": 25
15+
}
16+
```
17+
18+
## Fenced Code Block with caption
19+
20+
```pseudocode
21+
procedure startSwinging(swing, child)
22+
while child.isComfortable()
23+
swing.giveGentlePush()
24+
waitForNextIteration()
25+
end while
26+
end procedure

0 commit comments

Comments
 (0)