Skip to content

Commit 4249c13

Browse files
committed
[FEATURE] Create a rst theme to convert markdown
Convert basic mark-down into restructured Text * blockquote
1 parent 619936e commit 4249c13

File tree

20 files changed

+144
-60
lines changed

20 files changed

+144
-60
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
.. code-block:: plaintext
22

33
{{ renderRstIndent(node.value|raw, 1)|raw }}
4+
{{ "\n" }}
5+
{{ "\n" }}
6+
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
{{ "\n" }}
12
{% if node.isOrdered -%}
23
{%- for item in node.value -%}
3-
#. {{ renderNode(item.value)|raw }}{{ "\n\n" }}
4+
#. {{ renderNode(item.value)|raw }}{{ "\n" }}
45
{% endfor -%}
56
{%- else -%}
67
{%- for item in node.value -%}
78
* {{ renderNode(item.value)|raw }}{{ "\n" }}
89
{%- endfor -%}
9-
{%- endif -%}
10+
{%- endif %}
11+
{{ "\n" }}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
{%- set text = renderNode(node.value)|raw -%}
1+
{% set text = renderNode(node.value)|raw -%}
22
{%- if text|trim %}
33
{{- text|raw -}}
44
{% endif -%}
5+
{{ "\n" }}
6+
{{ "\n" }}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
{{ renderNode(node.value) }}
1+
{{ renderRstIndent(renderNode(node.value)|raw, 1)|raw }}
2+
{{ "\n" }}
3+
{{ "\n" }}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
.. figure:: {{ node.url }}
2-
:alt: {{ node.altText }}
1+
{{ "\n" }}
2+
.. figure:: {{ node.url|raw }}
3+
:alt: {{ node.altText|raw }}
4+
{{ "\n" }}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{%- for child in node.children -%}
2-
{{- renderNode(child) -}}
2+
{{- renderNode(child)|raw -}}
33
{%- endfor -%}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{%- if node.value matches '/`/' -%}
2-
``{{- node.value -}}``
2+
``{{- node.value|raw -}}``
33
{%- else -%}
4-
`{{- node.value -}}`
4+
`{{- node.value|raw -}}`
55
{%- endif -%}
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
{% for child in node.children -%}
2-
{{- renderNode(child) -}}
3-
{%- endfor %}
1+
{%- set renderedContent -%}
2+
{%- for child in node.children -%}
3+
{{- renderNode(child) -}}
4+
{%- endfor -%}
5+
{%- endset -%}
6+
7+
{{- renderedContent | clean_content | raw -}}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use phpDocumentor\Guides\RstTheme\Configuration\HeaderSyntax;
2020
use phpDocumentor\Guides\Twig\GlobalMenuExtension;
2121
use Twig\Extension\AbstractExtension;
22+
use Twig\TwigFilter;
2223
use Twig\TwigFunction;
2324

2425
use function min;
@@ -43,6 +44,24 @@ public function getFunctions(): array
4344
];
4445
}
4546

47+
/** @return TwigFilter[] */
48+
public function getFilters(): array
49+
{
50+
return [
51+
new TwigFilter('clean_content', [$this, 'cleanContent']),
52+
];
53+
}
54+
55+
public function cleanContent(string $content): string
56+
{
57+
$lines = explode("\n", $content);
58+
$lines = array_map('rtrim', $lines);
59+
$content = implode("\n", $lines);
60+
61+
$content = preg_replace('/(\n){2,}/', "\n\n", $content);
62+
return rtrim($content)."\n";
63+
}
64+
4665
public function renderRstIndent(string $text, int $indentNr): string
4766
{
4867
$indent = str_repeat(' ', $indentNr*4);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
====================
2+
Markdown Blockquotes
3+
====================
4+
5+
This is a blockquote. It can span multiple lines.
6+
7+
Blockquotes with Multiple Paragraphs
8+
====================================
9+
10+
Dorothy followed her through many of the beautiful rooms in her castle.
11+
12+
The Witch bade her clean the pots and kettles and sweep the floor and keep the fire fed with wood.
13+
14+
Blockquotes with Other Elements
15+
===============================
16+
17+
The quarterly results look great!
18+
19+
* Revenue was off the chart.
20+
21+
* Profits were higher than ever.
22+
23+
*Everything* is going according to **plan**.
24+
25+
Blockquotes Best Practices
26+
==========================
27+
28+
Try to put a blank line before...
29+
30+
This is a blockquote
31+
32+
...and after a blockquote.
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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Markdown Blockquotes
2+
3+
> This is a blockquote.
4+
> It can span multiple lines.
5+
6+
## Blockquotes with Multiple Paragraphs
7+
8+
> Dorothy followed her through many of the beautiful rooms in her castle.
9+
>
10+
> The Witch bade her clean the pots and kettles and sweep the floor and keep the fire fed with wood.
11+
12+
## Blockquotes with Other Elements
13+
14+
> The quarterly results look great!
15+
>
16+
> - Revenue was off the chart.
17+
> - Profits were higher than ever.
18+
>
19+
> *Everything* is going according to **plan**.
20+
21+
## Blockquotes Best Practices
22+
23+
Try to put a blank line before...
24+
25+
> This is a blockquote
26+
27+
...and after a blockquote.

tests/Integration/tests-full/md-to-rst/code-md-to-rst/expected/index.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Markdown with Code Blocks
99
</head>
1010
</html>
1111
12-
1312
Fenced Code Blocks
1413
==================
1514

@@ -21,9 +20,6 @@ Fenced Code Blocks
2120
"age": 25
2221
}
2322
24-
25-
26-
2723
Fenced Code Block with caption
2824
==============================
2925

@@ -35,7 +31,3 @@ Fenced Code Block with caption
3531
waitForNextIteration()
3632
end while
3733
end procedure
38-
39-
40-
41-

tests/Integration/tests-full/md-to-rst/emphasis-md-to-rst/expected/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ Markdown with emphasis
33
======================
44

55
*Italic* or *Italic* **Bold** or **Bold**
6-

tests/Integration/tests-full/md-to-rst/index-md-to-rst/expected/index.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,3 @@ Headings
1010
You can create headings using hash symbols.
1111

1212
This text is part of a paragraph under the "Headings" heading.
13-
14-
15-

tests/Integration/tests-full/md-to-rst/inline-code-md-to-rst/expected/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ Markdown with inline Code
55
Lorem Ipsum Dolor: `$dolor`...
66

77
``Use `code` in your Markdown file.``
8-

tests/Integration/tests-full/md-to-rst/md-to-rst-list-link/expected/index.rst

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ TYPO3 Extension powermail - Documentation
55
This documentation helps
66

77
* Administrators to install and configure powermail
8+
89
* Editors to use powermail
9-
* Developers to extend powermail
1010

11+
* Developers to extend powermail
1112

1213
Example Screenshots
1314
===================
@@ -20,8 +21,6 @@ Frontend: Show a form with different field types
2021

2122
Example Form with Input, Textarea, Select, Multiselect, Checkboxes, Radiobuttons, and Submit
2223

23-
24-
2524
Frontend: Multistep Form
2625
------------------------
2726

@@ -30,8 +29,6 @@ Frontend: Multistep Form
3029

3130
Example Multistep Form with clientside validation
3231

33-
34-
3532
Backend: Mail Listing
3633
---------------------
3734

@@ -40,8 +37,6 @@ Backend: Mail Listing
4037

4138
Manage the delivered mails with a fulltext search and some export possibilities
4239

43-
44-
4540
Backend: Reporting
4641
------------------
4742

@@ -50,16 +45,9 @@ Backend: Reporting
5045

5146
See the reporting about the delivered mails (Form or Marketing Data Analyses are possible)
5247

53-
54-
55-
56-
5748
Documentation overview
5849
======================
5950

6051
* `Introduction <https://github.com/in2code-de/powermail/blob/develop/Documentation/Readme.md>`__
61-
* `Documentation for editors <https://github.com/in2code-de/powermail/blob/develop/Documentation/ForEditors/Readme.md>`__
62-
63-
64-
6552

53+
* `Documentation for editors <https://github.com/in2code-de/powermail/blob/develop/Documentation/ForEditors/Readme.md>`__
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<!-- content start -->
2-
<div class="section" id="directive-tests">
3-
<h1>Directive tests</h1>
4-
<p>Lorem Ipsum Dolor</p>
5-
<p>Dolor sit!</p>
6-
</div>
2+
<div class="section" id="directive-tests">
3+
<h1>Directive tests</h1>
4+
5+
6+
<p>Lorem Ipsum Dolor</p>
7+
8+
<p>Dolor sit!</p>
9+
10+
</div>
711
<!-- content end -->
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<!-- content start -->
2-
<div class="section" id="directive-tests">
3-
<h1>Directive tests</h1>
4-
<div>
5-
<p>Lorem Ipsum Dolor</p>
6-
<h2>Some Rubric</h2>
7-
<p>Dolor sit!</p>
8-
</div>
2+
<div class="section" id="directive-tests">
3+
<h1>Directive tests</h1>
4+
<div>
5+
6+
<p>Lorem Ipsum Dolor</p>
7+
<h2>Some Rubric</h2>
8+
<p>Dolor sit!</p>
99
</div>
10+
</div>
1011
<!-- content end -->
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<!-- content start -->
2-
<div class="section" id="directive-tests">
3-
<h1>Directive tests</h1>
4-
<div class="someClass">
5-
<script>alert('XSS');</script>
6-
<p>Lorem Ipsum Dolor</p>
7-
<h2>Some Rubric</h2>
8-
<p>Dolor sit!</p>
9-
</div>
2+
<div class="section" id="directive-tests">
3+
<h1>Directive tests</h1>
4+
<div class="someClass">
5+
<script>alert('XSS');</script>
6+
<p>Lorem Ipsum Dolor</p>
7+
<h2>Some Rubric</h2>
8+
<p>Dolor sit!</p>
109
</div>
10+
</div>
1111
<!-- content end -->

0 commit comments

Comments
 (0)