Skip to content

Commit 38247d4

Browse files
committed
[FEATURE] Render tables to rst
1 parent b867d5e commit 38247d4

File tree

6 files changed

+97
-0
lines changed

6 files changed

+97
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
{{ renderRstTable(node) }}

packages/guides-theme-rst/resources/template/rst/template.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
use phpDocumentor\Guides\Nodes\QuoteNode;
5252
use phpDocumentor\Guides\Nodes\SectionNode;
5353
use phpDocumentor\Guides\Nodes\SeparatorNode;
54+
use phpDocumentor\Guides\Nodes\TableNode;
5455
use phpDocumentor\Guides\Nodes\TitleNode;
5556

5657
return [
@@ -74,6 +75,7 @@
7475
CitationNode::class => 'body/citation.rst.twig',
7576
FootnoteNode::class => 'body/footnote.rst.twig',
7677
AnnotationListNode::class => 'body/annotation-list.rst.twig',
78+
TableNode::class => 'body/table.rst.twig',
7779
// Inline
7880
ImageInlineNode::class => 'inline/image.rst.twig',
7981
AbbreviationInlineNode::class => 'inline/textroles/abbreviation.rst.twig',

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace phpDocumentor\Guides\RstTheme\Twig;
1515

16+
use phpDocumentor\Guides\Nodes\TableNode;
1617
use phpDocumentor\Guides\Nodes\TitleNode;
1718
use phpDocumentor\Guides\RstTheme\Configuration\HeaderSyntax;
1819
use Twig\Extension\AbstractExtension;
@@ -35,6 +36,7 @@ public function getFunctions(): array
3536
{
3637
return [
3738
new TwigFunction('renderRstTitle', $this->renderRstTitle(...), ['is_safe' => ['rst'], 'needs_context' => false]),
39+
new TwigFunction('renderRstTable', $this->renderRstTable(...), ['is_safe' => ['rst'], 'needs_context' => false]),
3840
new TwigFunction('renderRstIndent', $this->renderRstIndent(...), ['is_safe' => ['rst'], 'needs_context' => false]),
3941
];
4042
}
@@ -77,4 +79,21 @@ public function renderRstTitle(TitleNode $node, string $content): string
7779

7880
return $ret;
7981
}
82+
83+
public function renderRstTable(TableNode $node): string
84+
{
85+
$ret = '';
86+
87+
foreach ($node->getHeaders() as $header) {
88+
foreach ($header->getColumns() as $column) {
89+
$ret .= $column->getContent() . ' ';
90+
}
91+
$ret .= "header \n";
92+
}
93+
foreach ($node->getData() as $row) {
94+
$ret .= 'row'. "\n";
95+
}
96+
97+
return $ret;
98+
}
8099
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
* Profits were higher than ever.
21+
22+
*Everything* is going according to **plan**.
23+
24+
Blockquotes Best Practices
25+
==========================
26+
27+
Try to put a blank line before...
28+
29+
This is a blockquote
30+
31+
...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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Markdown Tables
2+
3+
## Simple Table
4+
5+
| Name | Age | City |
6+
|------------|-----|--------------|
7+
| John Doe | 29 | New York |
8+
| Jane Smith | 34 | San Francisco|
9+
| Sam Green | 22 | Boston |
10+
11+
## Table 1
12+
13+
| Method name | Description | Parameters | Default |
14+
| ----------- | ----------- | ---------- | ---------- |
15+
| `setIcon` | icon file, or existing icon identifier | `string $icon` | `'EXT:container/Resources/Public/Icons/Extension.svg'` |
16+
| `setBackendTemplate` | Template for backend view| `string $backendTemplate` | `null'` |
17+
| `setGridTemplate` | Template for grid | `string $gridTemplate` | `'EXT:container/Resources/Private/Templates/Container.html'` |
18+
| `setGridPartialPaths` / `addGridPartialPath` | Partial root paths for grid | `array $gridPartialPaths` / `string $gridPartialPath` | `['EXT:backend/Resources/Private/Partials/', 'EXT:container/Resources/Private/Partials/']` |
19+
| `setGridLayoutPaths` | Layout root paths for grid | `array $gridLayoutPaths` | `[]` |
20+
| `setSaveAndCloseInNewContentElementWizard` | saveAndClose for new content element wizard | `bool $saveAndCloseInNewContentElementWizard` | `true` |
21+
| `setRegisterInNewContentElementWizard` |register in new content element wizard | `bool $registerInNewContentElementWizard` | `true` |
22+
| `setGroup` | Custom Group (used as optgroup for CType select, and as tab in New Content Element Wizard). If empty "container" is used as tab and no optgroup in CType is used. | `string $group` | `'container'` |
23+
| `setDefaultValues` | Default values for the newContentElement.wizardItems | `array $defaultValues` | `[]` |
24+
25+
## Table 2
26+
27+
| Option | Description | Default | Parameter |
28+
|-----------------------------|------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------|-------------|
29+
| `contentId` | id of container to to process | current uid of content element ``$cObj->data['uid']`` | ``?int`` |
30+
| `colPos` | colPos of children to to process | empty, all children are processed (as ``children_<colPos>``) | ``?int`` |
31+
| `as` | variable to use for proceesedData (only if ``colPos`` is set) | ``children`` | ``?string`` |
32+
| `skipRenderingChildContent` | do not call ``ContentObjectRenderer->render()`` for children, (``renderedContent`` in child will not exist) | empty | ``?int`` |

0 commit comments

Comments
 (0)