Skip to content

Commit d853780

Browse files
authored
feat: convert writer to HTML5 (#253)
1 parent 3f28634 commit d853780

10 files changed

+129
-144
lines changed

readme_renderer/clean.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"br", "caption", "cite", "col", "colgroup", "dd", "del", "details", "div",
3131
"dl", "dt", "h1", "h2", "h3", "h4", "h5", "h6", "hr", "img", "p", "pre",
3232
"span", "sub", "summary", "sup", "table", "tbody", "td", "th", "thead",
33-
"tr", "tt", "kbd", "var", "input",
33+
"tr", "tt", "kbd", "var", "input", "section", "aside",
3434
]
3535

3636
ALLOWED_ATTRIBUTES = {
@@ -44,7 +44,7 @@
4444
"hr": ["class"],
4545
"img": ["src", "width", "height", "alt", "align", "class"],
4646
"span": ["class"],
47-
"th": ["align"],
47+
"th": ["align", "class"],
4848
"td": ["align", "colspan", "rowspan"],
4949
"div": ["align", "class"],
5050
"h1": ["align"],
@@ -58,6 +58,11 @@
5858
"pre": ["lang"],
5959
"ol": ["start"],
6060
"input": ["type", "checked", "disabled"],
61+
"aside": ["class"],
62+
"dd": ["class"],
63+
"dl": ["class"],
64+
"dt": ["class"],
65+
"ul": ["class"],
6166
}
6267

6368

readme_renderer/rst.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from docutils.core import publish_parts
1919
from docutils.nodes import colspec, image
20-
from docutils.writers.html4css1 import HTMLTranslator, Writer
20+
from docutils.writers.html5_polyglot import HTMLTranslator, Writer
2121
from docutils.utils import SystemMessage
2222

2323
from .clean import clean

tests/fixtures/test_rst_003.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<div class="section" id="required-packages">
1+
<section id="required-packages">
22
<h2>Required packages</h2>
33
<p>To run the PyPI software, you need Python 2.5+ and PostgreSQL</p>
4-
</div>
5-
<div class="section" id="quick-development-setup">
4+
</section>
5+
<section id="quick-development-setup">
66
<h2>Quick development setup</h2>
77
<p>Make sure you are sitting</p>
8-
</div>
8+
</section>

tests/fixtures/test_rst_008.html

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
<p>Here is some Python code for a <tt>Dog</tt>:</p>
2-
<pre><span class="k">class</span> <span class="nc">Dog</span><span class="p">(</span><span class="n">Animal</span><span class="p">):</span>
1+
<p>Here is some Python code for a <span class="docutils literal">Dog</span>:</p>
2+
<pre><code><span class="k">class</span> <span class="nc">Dog</span><span class="p">(</span><span class="n">Animal</span><span class="p">):</span>
33
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
44
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>
55

66
<span class="k">def</span> <span class="nf">make_sound</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
77
<span class="nb">print</span><span class="p">(</span><span class="s1">'Ruff!'</span><span class="p">)</span>
88

9-
<span class="n">dog</span> <span class="o">=</span> <span class="n">Dog</span><span class="p">(</span><span class="s1">'Fido'</span><span class="p">)</span>
10-
</pre>
9+
<span class="n">dog</span> <span class="o">=</span> <span class="n">Dog</span><span class="p">(</span><span class="s1">'Fido'</span><span class="p">)</span></code></pre>
1110
<p>and then here is some bash:</p>
12-
<pre><span class="k">if</span> <span class="o">[</span> <span class="s2">&quot;</span><span class="nv">$1</span><span class="s2">&quot;</span> <span class="o">=</span> <span class="s2">&quot;--help&quot;</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
11+
<pre><code><span class="k">if</span> <span class="o">[</span> <span class="s2">&quot;</span><span class="nv">$1</span><span class="s2">&quot;</span> <span class="o">=</span> <span class="s2">&quot;--help&quot;</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
1312
<span class="nb">echo</span> <span class="s2">&quot;OK&quot;</span>
14-
<span class="k">fi</span>
15-
</pre>
13+
<span class="k">fi</span></code></pre>
1614
<p>or click <a href="http://www.surveymonkey.com" rel="nofollow">SurveyMonkey</a></p>
+12-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
<div class="admonition danger">
2-
<p class="first admonition-title">!DANGER!</p>
3-
<p class="last">Will Robinson</p>
4-
</div>
5-
<div class="admonition note">
6-
<p class="first admonition-title">Note</p>
7-
<p class="last">F Sharp is a note, right?</p>
8-
</div>
9-
<div class="admonition admonition-see-also">
10-
<p class="first admonition-title">See also</p>
11-
<p class="last">A customized admonition.
1+
<aside class="admonition danger">
2+
<p class="admonition-title">!DANGER!</p>
3+
<p>Will Robinson</p>
4+
</aside>
5+
<aside class="admonition note">
6+
<p class="admonition-title">Note</p>
7+
<p>F Sharp is a note, right?</p>
8+
</aside>
9+
<aside class="admonition admonition-see-also">
10+
<p class="admonition-title">See also</p>
11+
<p>A customized admonition.
1212
Read more at <a href="https://docutils.sourceforge.io/docs/ref/rst/directives.html#admonitions" rel="nofollow">docutils</a></p>
13-
</div>
13+
</aside>

tests/fixtures/test_rst_caption.html

+30-37
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,43 @@
11
<table>
22
<caption>Multiplication</caption>
3-
<colgroup>
4-
<col>
5-
<col>
6-
<col>
7-
<col>
8-
<col>
9-
</colgroup>
103
<thead>
11-
<tr><th>1</th>
12-
<th>2</th>
13-
<th>3</th>
14-
<th>4</th>
15-
<th>5</th>
4+
<tr><th class="head"><p>1</p></th>
5+
<th class="head"><p>2</p></th>
6+
<th class="head"><p>3</p></th>
7+
<th class="head"><p>4</p></th>
8+
<th class="head"><p>5</p></th>
169
</tr>
1710
</thead>
1811
<tbody>
19-
<tr><td>1</td>
20-
<td>2</td>
21-
<td>3</td>
22-
<td>4</td>
23-
<td>5</td>
12+
<tr><td><p>1</p></td>
13+
<td><p>2</p></td>
14+
<td><p>3</p></td>
15+
<td><p>4</p></td>
16+
<td><p>5</p></td>
2417
</tr>
25-
<tr><td>2</td>
26-
<td>4</td>
27-
<td>6</td>
28-
<td>8</td>
29-
<td>10</td>
18+
<tr><td><p>2</p></td>
19+
<td><p>4</p></td>
20+
<td><p>6</p></td>
21+
<td><p>8</p></td>
22+
<td><p>10</p></td>
3023
</tr>
31-
<tr><td>3</td>
32-
<td>6</td>
33-
<td>9</td>
34-
<td>12</td>
35-
<td>15</td>
24+
<tr><td><p>3</p></td>
25+
<td><p>6</p></td>
26+
<td><p>9</p></td>
27+
<td><p>12</p></td>
28+
<td><p>15</p></td>
3629
</tr>
37-
<tr><td>4</td>
38-
<td>8</td>
39-
<td>12</td>
40-
<td>16</td>
41-
<td>20</td>
30+
<tr><td><p>4</p></td>
31+
<td><p>8</p></td>
32+
<td><p>12</p></td>
33+
<td><p>16</p></td>
34+
<td><p>20</p></td>
4235
</tr>
43-
<tr><td>5</td>
44-
<td>10</td>
45-
<td>15</td>
46-
<td>20</td>
47-
<td>25</td>
36+
<tr><td><p>5</p></td>
37+
<td><p>10</p></td>
38+
<td><p>15</p></td>
39+
<td><p>20</p></td>
40+
<td><p>25</p></td>
4841
</tr>
4942
</tbody>
5043
</table>

tests/fixtures/test_rst_docinfo.html

+17-18
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
<table>
2-
<colgroup><col>
3-
<col>
4-
</colgroup><tbody>
5-
<tr><th>Project:</th><td>pg_query – Pythonic wrapper around libpg_query</td>
6-
</tr>
7-
<tr><th>Created:</th><td>mer 02 ago 2017 14:49:24 CEST</td>
8-
</tr>
9-
<tr><th>Author:</th>
10-
<td>Lele Gaifax &lt;<a href="mailto:lele&#37;&#52;&#48;metapensiero&#46;it">lele<span>&#64;</span>metapensiero<span>&#46;</span>it</a>&gt;</td></tr>
11-
<tr><th>License:</th><td>GNU General Public License version 3 or later</td>
12-
</tr>
13-
<tr><th>Copyright:</th>
14-
<td>© 2017, 2018 Lele Gaifax</td></tr>
15-
</tbody>
16-
</table>
17-
<div class="section" id="pg-query">
1+
<dl class="docinfo simple">
2+
<dt class="project">Project<span class="colon">:</span></dt>
3+
<dd class="project"><p>pg_query – Pythonic wrapper around libpg_query</p>
4+
</dd>
5+
<dt class="created">Created<span class="colon">:</span></dt>
6+
<dd class="created"><p>mer 02 ago 2017 14:49:24 CEST</p>
7+
</dd>
8+
<dt class="author">Author<span class="colon">:</span></dt>
9+
<dd class="author"><p>Lele Gaifax &lt;<a href="mailto:lele&#37;&#52;&#48;metapensiero&#46;it">lele<span>&#64;</span>metapensiero<span>&#46;</span>it</a>&gt;</p></dd>
10+
<dt class="license">License<span class="colon">:</span></dt>
11+
<dd class="license"><p>GNU General Public License version 3 or later</p>
12+
</dd>
13+
<dt class="copyright">Copyright<span class="colon">:</span></dt>
14+
<dd class="copyright">© 2017, 2018 Lele Gaifax</dd>
15+
</dl>
16+
<section id="pg-query">
1817
<h2>pg_query</h2>
19-
</div>
18+
</section>

tests/fixtures/test_rst_linkify.html

+21-21
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<p>It requires a spatial databases compatible with <a href="https://docs.djangoproject.com/en/dev/ref/contrib/gis/" rel="nofollow">GeoDjango</a>. <a href="http://www.postgresql.org" rel="nofollow">PostgreSQL</a> 9.x
88
and <a href="http://postgis.refractions.net" rel="nofollow">PostGIS</a> 2.x are recommended for development and production, since these
99
support all the GeoDjango features.</p>
10-
<div class="section" id="status">
10+
<section id="status">
1111
<h2>Status</h2>
1212
<p>multigtfs is ready for your GTFS project.</p>
1313
<p>Point releases (0.4.1 to 0.4.2) should be safe, only adding features or fixing
@@ -21,28 +21,28 @@ <h2>Status</h2>
2121
release.</p>
2222
<p>All valid GTFS feeds are supported for import and export. This includes
2323
feeds with extra columns not yet included in the GTFS spec, and feeds that
24-
omit <tt>calendar.txt</tt> in favor of <tt>calendar_dates.txt</tt> (such as the TriMet
24+
omit <span class="docutils literal">calendar.txt</span> in favor of <span class="docutils literal">calendar_dates.txt</span> (such as the TriMet
2525
archive feeds). If you find a feed that doesn’t work, <a href="https://github.com/tulsawebdevs/django-multi-gtfs/issues" rel="nofollow">file a bug</a>!</p>
2626
<p>See the <a href="https://github.com/tulsawebdevs/django-multi-gtfs/issues?state=open" rel="nofollow">issues list</a> for more details on bugs and feature requests.</p>
27-
</div>
28-
<div class="section" id="example-project">
27+
</section>
28+
<section id="example-project">
2929
<h2>Example project</h2>
3030
<p>Check out the <a href="examples/explore/README.md" rel="nofollow">example project</a>.</p>
31-
</div>
32-
<div class="section" id="development">
31+
</section>
32+
<section id="development">
3333
<h2>Development</h2>
34-
<table>
35-
<colgroup><col>
36-
<col>
37-
</colgroup><tbody>
38-
<tr><th>Code:</th><td><a href="https://github.com/tulsawebdevs/django-multi-gtfs" rel="nofollow">https://github.com/tulsawebdevs/django-multi-gtfs</a></td>
39-
</tr>
40-
<tr><th>Issues:</th><td><a href="https://github.com/tulsawebdevs/django-multi-gtfs/issues" rel="nofollow">https://github.com/tulsawebdevs/django-multi-gtfs/issues</a></td>
41-
</tr>
42-
<tr><th>Dev Docs:</th><td><a href="http://multigtfs.readthedocs.org/" rel="nofollow">http://multigtfs.readthedocs.org/</a></td>
43-
</tr>
44-
<tr><th>IRC:</th><td><a>irc://irc.freenode.net/tulsawebdevs</a></td>
45-
</tr>
46-
</tbody>
47-
</table>
48-
</div>
34+
<dl class="field-list simple">
35+
<dt>Code<span class="colon">:</span></dt>
36+
<dd><p><a href="https://github.com/tulsawebdevs/django-multi-gtfs" rel="nofollow">https://github.com/tulsawebdevs/django-multi-gtfs</a></p>
37+
</dd>
38+
<dt>Issues<span class="colon">:</span></dt>
39+
<dd><p><a href="https://github.com/tulsawebdevs/django-multi-gtfs/issues" rel="nofollow">https://github.com/tulsawebdevs/django-multi-gtfs/issues</a></p>
40+
</dd>
41+
<dt>Dev Docs<span class="colon">:</span></dt>
42+
<dd><p><a href="http://multigtfs.readthedocs.org/" rel="nofollow">http://multigtfs.readthedocs.org/</a></p>
43+
</dd>
44+
<dt>IRC<span class="colon">:</span></dt>
45+
<dd><p><a>irc://irc.freenode.net/tulsawebdevs</a></p>
46+
</dd>
47+
</dl>
48+
</section>

tests/fixtures/test_rst_math.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<p>A <tt>math</tt> directive:</p>
1+
<p>A <span class="docutils literal">math</span> directive:</p>
22
<div class="math">
33
\begin{equation*}
44
\alpha _t(i) = P(O_1, O_2, \ldots O_t, q_t = S_i \lambda )
55
\end{equation*}
66
</div>
7-
<p>A <tt>:math:</tt> role:</p>
7+
<p>A <span class="docutils literal">:math:</span> role:</p>
88
<p>The area of a circle is <span class="math">\(A_\text{c} = (\pi/4) d^2\)</span>.</p>

tests/fixtures/test_rst_tables.html

+30-40
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,52 @@
11
<table>
2-
<colgroup>
3-
<col>
4-
<col>
5-
<col>
6-
<col>
7-
</colgroup>
82
<thead>
9-
<tr><th>Header row, column 1
10-
(header rows optional)</th>
11-
<th>Header 2</th>
12-
<th>Header 3</th>
13-
<th>Header 4</th>
3+
<tr><th class="head"><p>Header row, column 1
4+
(header rows optional)</p></th>
5+
<th class="head"><p>Header 2</p></th>
6+
<th class="head"><p>Header 3</p></th>
7+
<th class="head"><p>Header 4</p></th>
148
</tr>
159
</thead>
1610
<tbody>
17-
<tr><td>body row 1, column 1</td>
18-
<td>column 2</td>
19-
<td>column 3</td>
20-
<td>column 4</td>
21-
</tr>
22-
<tr><td>body row 2</td>
23-
<td colspan="3">Cells may span columns.</td>
24-
</tr>
25-
<tr><td>body row 3</td>
26-
<td rowspan="2">Cells may
27-
span rows.</td>
28-
<td colspan="2" rowspan="2"><ul>
29-
<li>Table cells</li>
30-
<li>contain</li>
31-
<li>body elements.</li>
11+
<tr><td><p>body row 1, column 1</p></td>
12+
<td><p>column 2</p></td>
13+
<td><p>column 3</p></td>
14+
<td><p>column 4</p></td>
15+
</tr>
16+
<tr><td><p>body row 2</p></td>
17+
<td colspan="3"><p>Cells may span columns.</p></td>
18+
</tr>
19+
<tr><td><p>body row 3</p></td>
20+
<td rowspan="2"><p>Cells may
21+
span rows.</p></td>
22+
<td colspan="2" rowspan="2"><ul class="simple">
23+
<li><p>Table cells</p></li>
24+
<li><p>contain</p></li>
25+
<li><p>body elements.</p></li>
3226
</ul>
3327
</td>
3428
</tr>
35-
<tr><td>body row 4</td>
29+
<tr><td><p>body row 4</p></td>
3630
</tr>
3731
</tbody>
3832
</table>
3933
<table>
40-
<colgroup>
41-
<col>
42-
<col>
43-
</colgroup>
4434
<thead>
45-
<tr><th>title1</th>
46-
<th>title2</th>
35+
<tr><th class="head"><p>title1</p></th>
36+
<th class="head"><p>title2</p></th>
4737
</tr>
4838
</thead>
4939
<tbody>
50-
<tr><td>col1</td>
51-
<td>col2</td>
40+
<tr><td><p>col1</p></td>
41+
<td><p>col2</p></td>
5242
</tr>
53-
<tr><td rowspan="2">mutirow</td>
54-
<td>cell1</td>
43+
<tr><td rowspan="2"><p>mutirow</p></td>
44+
<td><p>cell1</p></td>
5545
</tr>
56-
<tr><td>cell2</td>
46+
<tr><td><p>cell2</p></td>
5747
</tr>
58-
<tr><td>singlerow</td>
59-
<td>cell3</td>
48+
<tr><td><p>singlerow</p></td>
49+
<td><p>cell3</p></td>
6050
</tr>
6151
</tbody>
6252
</table>

0 commit comments

Comments
 (0)