Skip to content

Commit

Permalink
[FEATURE] Create a rst theme to convert markdown
Browse files Browse the repository at this point in the history
Convert basic mark-down into restructured Text

* blockquote
  • Loading branch information
linawolf committed Oct 11, 2024
1 parent 2622c79 commit aefca48
Show file tree
Hide file tree
Showing 20 changed files with 144 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.. code-block:: plaintext

{{ renderRstIndent(node.value|raw, 1)|raw }}
{{ "\n" }}
{{ "\n" }}

Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{{ "\n" }}
{% if node.isOrdered -%}
{%- for item in node.value -%}
#. {{ renderNode(item.value)|raw }}{{ "\n\n" }}
#. {{ renderNode(item.value)|raw }}{{ "\n" }}
{% endfor -%}
{%- else -%}
{%- for item in node.value -%}
* {{ renderNode(item.value)|raw }}{{ "\n" }}
{%- endfor -%}
{%- endif -%}
{%- endif %}
{{ "\n" }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{%- set text = renderNode(node.value)|raw -%}
{% set text = renderNode(node.value)|raw -%}
{%- if text|trim %}
{{- text|raw -}}
{% endif -%}
{{ "\n" }}
{{ "\n" }}
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{{ renderNode(node.value) }}
{{ renderRstIndent(renderNode(node.value)|raw, 1)|raw }}
{{ "\n" }}
{{ "\n" }}
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.. figure:: {{ node.url }}
:alt: {{ node.altText }}
{{ "\n" }}
.. figure:: {{ node.url|raw }}
:alt: {{ node.altText|raw }}
{{ "\n" }}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{%- for child in node.children -%}
{{- renderNode(child) -}}
{{- renderNode(child)|raw -}}
{%- endfor -%}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{%- if node.value matches '/`/' -%}
``{{- node.value -}}``
``{{- node.value|raw -}}``
{%- else -%}
`{{- node.value -}}`
`{{- node.value|raw -}}`
{%- endif -%}
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{% for child in node.children -%}
{{- renderNode(child) -}}
{%- endfor %}
{%- set renderedContent -%}
{%- for child in node.children -%}
{{- renderNode(child) -}}
{%- endfor -%}
{%- endset -%}

{{- renderedContent | clean_content | raw -}}
19 changes: 19 additions & 0 deletions packages/guides-theme-rst/src/RstTheme/Twig/RstExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use phpDocumentor\Guides\RstTheme\Configuration\HeaderSyntax;
use phpDocumentor\Guides\Twig\GlobalMenuExtension;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;

use function min;
Expand All @@ -43,6 +44,24 @@ public function getFunctions(): array
];
}

/** @return TwigFilter[] */
public function getFilters(): array
{
return [
new TwigFilter('clean_content', [$this, 'cleanContent']),
];
}

public function cleanContent(string $content): string
{
$lines = explode("\n", $content);

Check failure on line 57 in packages/guides-theme-rst/src/RstTheme/Twig/RstExtension.php

View workflow job for this annotation

GitHub Actions / Coding Standards

Function explode() should not be referenced via a fallback global name, but via a use statement.
$lines = array_map('rtrim', $lines);

Check failure on line 58 in packages/guides-theme-rst/src/RstTheme/Twig/RstExtension.php

View workflow job for this annotation

GitHub Actions / Coding Standards

Function array_map() should not be referenced via a fallback global name, but via a use statement.
$content = implode("\n", $lines);

Check failure on line 59 in packages/guides-theme-rst/src/RstTheme/Twig/RstExtension.php

View workflow job for this annotation

GitHub Actions / Coding Standards

Function implode() should not be referenced via a fallback global name, but via a use statement.

$content = preg_replace('/(\n){2,}/', "\n\n", $content);

Check failure on line 61 in packages/guides-theme-rst/src/RstTheme/Twig/RstExtension.php

View workflow job for this annotation

GitHub Actions / Coding Standards

Function preg_replace() should not be referenced via a fallback global name, but via a use statement.
return rtrim($content)."\n";

Check failure on line 62 in packages/guides-theme-rst/src/RstTheme/Twig/RstExtension.php

View workflow job for this annotation

GitHub Actions / Coding Standards

Expected 1 line before "return", found 0.

Check failure on line 62 in packages/guides-theme-rst/src/RstTheme/Twig/RstExtension.php

View workflow job for this annotation

GitHub Actions / Coding Standards

Function rtrim() should not be referenced via a fallback global name, but via a use statement.

Check failure on line 62 in packages/guides-theme-rst/src/RstTheme/Twig/RstExtension.php

View workflow job for this annotation

GitHub Actions / Coding Standards

Expected at least 1 space before "."; 0 found

Check failure on line 62 in packages/guides-theme-rst/src/RstTheme/Twig/RstExtension.php

View workflow job for this annotation

GitHub Actions / Coding Standards

Expected at least 1 space after "."; 0 found

Check failure on line 62 in packages/guides-theme-rst/src/RstTheme/Twig/RstExtension.php

View workflow job for this annotation

GitHub Actions / Coding Standards

Concat operator must be surrounded by a single space
}

public function renderRstIndent(string $text, int $indentNr): string
{
$indent = str_repeat(' ', $indentNr*4);

Check failure on line 67 in packages/guides-theme-rst/src/RstTheme/Twig/RstExtension.php

View workflow job for this annotation

GitHub Actions / Coding Standards

Expected at least 1 space before "*"; 0 found
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
====================
Markdown Blockquotes
====================

This is a blockquote. It can span multiple lines.

Blockquotes with Multiple Paragraphs
====================================

Dorothy followed her through many of the beautiful rooms in her castle.

The Witch bade her clean the pots and kettles and sweep the floor and keep the fire fed with wood.

Blockquotes with Other Elements
===============================

The quarterly results look great!

* Revenue was off the chart.

* Profits were higher than ever.

*Everything* is going according to **plan**.

Blockquotes Best Practices
==========================

Try to put a blank line before...

This is a blockquote

...and after a blockquote.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<guides xmlns="https://www.phpdoc.org/guides"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.phpdoc.org/guides packages/guides-cli/resources/schema/guides.xsd"
input-format="md"
theme="rst"
>
<project title="Project Title" version="6.4"/>
<extension class="phpDocumentor\Guides\RstTheme"/>
<output-format>rst</output-format>
</guides>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Markdown Blockquotes

> This is a blockquote.
> It can span multiple lines.
## Blockquotes with Multiple Paragraphs

> Dorothy followed her through many of the beautiful rooms in her castle.
>
> The Witch bade her clean the pots and kettles and sweep the floor and keep the fire fed with wood.
## Blockquotes with Other Elements

> The quarterly results look great!
>
> - Revenue was off the chart.
> - Profits were higher than ever.
>
> *Everything* is going according to **plan**.
## Blockquotes Best Practices

Try to put a blank line before...

> This is a blockquote
...and after a blockquote.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Markdown with Code Blocks
</head>
</html>
Fenced Code Blocks
==================

Expand All @@ -21,9 +20,6 @@ Fenced Code Blocks
"age": 25
}
Fenced Code Block with caption
==============================

Expand All @@ -35,7 +31,3 @@ Fenced Code Block with caption
waitForNextIteration()
end while
end procedure
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ Markdown with emphasis
======================

*Italic* or *Italic* **Bold** or **Bold**

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,3 @@ Headings
You can create headings using hash symbols.

This text is part of a paragraph under the "Headings" heading.



Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ Markdown with inline Code
Lorem Ipsum Dolor: `$dolor`...

``Use `code` in your Markdown file.``

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ TYPO3 Extension powermail - Documentation
This documentation helps

* Administrators to install and configure powermail

* Editors to use powermail
* Developers to extend powermail

* Developers to extend powermail

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

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



Frontend: Multistep Form
------------------------

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

Example Multistep Form with clientside validation



Backend: Mail Listing
---------------------

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

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



Backend: Reporting
------------------

Expand All @@ -50,16 +45,9 @@ Backend: Reporting

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





Documentation overview
======================

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




* `Documentation for editors <https://github.com/in2code-de/powermail/blob/develop/Documentation/ForEditors/Readme.md>`__
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<!-- content start -->
<div class="section" id="directive-tests">
<h1>Directive tests</h1>
<p>Lorem Ipsum Dolor</p>
<p>Dolor sit!</p>
</div>
<div class="section" id="directive-tests">
<h1>Directive tests</h1>


<p>Lorem Ipsum Dolor</p>

<p>Dolor sit!</p>

</div>
<!-- content end -->
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<!-- content start -->
<div class="section" id="directive-tests">
<h1>Directive tests</h1>
<div>
<p>Lorem Ipsum Dolor</p>
<h2>Some Rubric</h2>
<p>Dolor sit!</p>
</div>
<div class="section" id="directive-tests">
<h1>Directive tests</h1>
<div>

<p>Lorem Ipsum Dolor</p>
<h2>Some Rubric</h2>
<p>Dolor sit!</p>
</div>
</div>
<!-- content end -->
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!-- content start -->
<div class="section" id="directive-tests">
<h1>Directive tests</h1>
<div class="someClass">
<script>alert('XSS');</script>
<p>Lorem Ipsum Dolor</p>
<h2>Some Rubric</h2>
<p>Dolor sit!</p>
</div>
<div class="section" id="directive-tests">
<h1>Directive tests</h1>
<div class="someClass">
<script>alert('XSS');</script>
<p>Lorem Ipsum Dolor</p>
<h2>Some Rubric</h2>
<p>Dolor sit!</p>
</div>
</div>
<!-- content end -->

0 comments on commit aefca48

Please sign in to comment.