Skip to content

Commit

Permalink
feat: convert writer to HTML5 (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
miketheman authored Aug 17, 2022
1 parent 3f28634 commit d853780
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 144 deletions.
9 changes: 7 additions & 2 deletions readme_renderer/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"br", "caption", "cite", "col", "colgroup", "dd", "del", "details", "div",
"dl", "dt", "h1", "h2", "h3", "h4", "h5", "h6", "hr", "img", "p", "pre",
"span", "sub", "summary", "sup", "table", "tbody", "td", "th", "thead",
"tr", "tt", "kbd", "var", "input",
"tr", "tt", "kbd", "var", "input", "section", "aside",
]

ALLOWED_ATTRIBUTES = {
Expand All @@ -44,7 +44,7 @@
"hr": ["class"],
"img": ["src", "width", "height", "alt", "align", "class"],
"span": ["class"],
"th": ["align"],
"th": ["align", "class"],
"td": ["align", "colspan", "rowspan"],
"div": ["align", "class"],
"h1": ["align"],
Expand All @@ -58,6 +58,11 @@
"pre": ["lang"],
"ol": ["start"],
"input": ["type", "checked", "disabled"],
"aside": ["class"],
"dd": ["class"],
"dl": ["class"],
"dt": ["class"],
"ul": ["class"],
}


Expand Down
2 changes: 1 addition & 1 deletion readme_renderer/rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from docutils.core import publish_parts
from docutils.nodes import colspec, image
from docutils.writers.html4css1 import HTMLTranslator, Writer
from docutils.writers.html5_polyglot import HTMLTranslator, Writer
from docutils.utils import SystemMessage

from .clean import clean
Expand Down
8 changes: 4 additions & 4 deletions tests/fixtures/test_rst_003.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div class="section" id="required-packages">
<section id="required-packages">
<h2>Required packages</h2>
<p>To run the PyPI software, you need Python 2.5+ and PostgreSQL</p>
</div>
<div class="section" id="quick-development-setup">
</section>
<section id="quick-development-setup">
<h2>Quick development setup</h2>
<p>Make sure you are sitting</p>
</div>
</section>
12 changes: 5 additions & 7 deletions tests/fixtures/test_rst_008.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<p>Here is some Python code for a <tt>Dog</tt>:</p>
<pre><span class="k">class</span> <span class="nc">Dog</span><span class="p">(</span><span class="n">Animal</span><span class="p">):</span>
<p>Here is some Python code for a <span class="docutils literal">Dog</span>:</p>
<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>
<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>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>

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

<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>
</pre>
<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>
<p>and then here is some bash:</p>
<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>
<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>
<span class="nb">echo</span> <span class="s2">&quot;OK&quot;</span>
<span class="k">fi</span>
</pre>
<span class="k">fi</span></code></pre>
<p>or click <a href="http://www.surveymonkey.com" rel="nofollow">SurveyMonkey</a></p>
24 changes: 12 additions & 12 deletions tests/fixtures/test_rst_admonitions.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<div class="admonition danger">
<p class="first admonition-title">!DANGER!</p>
<p class="last">Will Robinson</p>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">F Sharp is a note, right?</p>
</div>
<div class="admonition admonition-see-also">
<p class="first admonition-title">See also</p>
<p class="last">A customized admonition.
<aside class="admonition danger">
<p class="admonition-title">!DANGER!</p>
<p>Will Robinson</p>
</aside>
<aside class="admonition note">
<p class="admonition-title">Note</p>
<p>F Sharp is a note, right?</p>
</aside>
<aside class="admonition admonition-see-also">
<p class="admonition-title">See also</p>
<p>A customized admonition.
Read more at <a href="https://docutils.sourceforge.io/docs/ref/rst/directives.html#admonitions" rel="nofollow">docutils</a></p>
</div>
</aside>
67 changes: 30 additions & 37 deletions tests/fixtures/test_rst_caption.html
Original file line number Diff line number Diff line change
@@ -1,50 +1,43 @@
<table>
<caption>Multiplication</caption>
<colgroup>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<thead>
<tr><th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
<tr><th class="head"><p>1</p></th>
<th class="head"><p>2</p></th>
<th class="head"><p>3</p></th>
<th class="head"><p>4</p></th>
<th class="head"><p>5</p></th>
</tr>
</thead>
<tbody>
<tr><td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<tr><td><p>1</p></td>
<td><p>2</p></td>
<td><p>3</p></td>
<td><p>4</p></td>
<td><p>5</p></td>
</tr>
<tr><td>2</td>
<td>4</td>
<td>6</td>
<td>8</td>
<td>10</td>
<tr><td><p>2</p></td>
<td><p>4</p></td>
<td><p>6</p></td>
<td><p>8</p></td>
<td><p>10</p></td>
</tr>
<tr><td>3</td>
<td>6</td>
<td>9</td>
<td>12</td>
<td>15</td>
<tr><td><p>3</p></td>
<td><p>6</p></td>
<td><p>9</p></td>
<td><p>12</p></td>
<td><p>15</p></td>
</tr>
<tr><td>4</td>
<td>8</td>
<td>12</td>
<td>16</td>
<td>20</td>
<tr><td><p>4</p></td>
<td><p>8</p></td>
<td><p>12</p></td>
<td><p>16</p></td>
<td><p>20</p></td>
</tr>
<tr><td>5</td>
<td>10</td>
<td>15</td>
<td>20</td>
<td>25</td>
<tr><td><p>5</p></td>
<td><p>10</p></td>
<td><p>15</p></td>
<td><p>20</p></td>
<td><p>25</p></td>
</tr>
</tbody>
</table>
35 changes: 17 additions & 18 deletions tests/fixtures/test_rst_docinfo.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
<table>
<colgroup><col>
<col>
</colgroup><tbody>
<tr><th>Project:</th><td>pg_query – Pythonic wrapper around libpg_query</td>
</tr>
<tr><th>Created:</th><td>mer 02 ago 2017 14:49:24 CEST</td>
</tr>
<tr><th>Author:</th>
<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>
<tr><th>License:</th><td>GNU General Public License version 3 or later</td>
</tr>
<tr><th>Copyright:</th>
<td>© 2017, 2018 Lele Gaifax</td></tr>
</tbody>
</table>
<div class="section" id="pg-query">
<dl class="docinfo simple">
<dt class="project">Project<span class="colon">:</span></dt>
<dd class="project"><p>pg_query – Pythonic wrapper around libpg_query</p>
</dd>
<dt class="created">Created<span class="colon">:</span></dt>
<dd class="created"><p>mer 02 ago 2017 14:49:24 CEST</p>
</dd>
<dt class="author">Author<span class="colon">:</span></dt>
<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>
<dt class="license">License<span class="colon">:</span></dt>
<dd class="license"><p>GNU General Public License version 3 or later</p>
</dd>
<dt class="copyright">Copyright<span class="colon">:</span></dt>
<dd class="copyright">© 2017, 2018 Lele Gaifax</dd>
</dl>
<section id="pg-query">
<h2>pg_query</h2>
</div>
</section>
42 changes: 21 additions & 21 deletions tests/fixtures/test_rst_linkify.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<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
and <a href="http://postgis.refractions.net" rel="nofollow">PostGIS</a> 2.x are recommended for development and production, since these
support all the GeoDjango features.</p>
<div class="section" id="status">
<section id="status">
<h2>Status</h2>
<p>multigtfs is ready for your GTFS project.</p>
<p>Point releases (0.4.1 to 0.4.2) should be safe, only adding features or fixing
Expand All @@ -21,28 +21,28 @@ <h2>Status</h2>
release.</p>
<p>All valid GTFS feeds are supported for import and export. This includes
feeds with extra columns not yet included in the GTFS spec, and feeds that
omit <tt>calendar.txt</tt> in favor of <tt>calendar_dates.txt</tt> (such as the TriMet
omit <span class="docutils literal">calendar.txt</span> in favor of <span class="docutils literal">calendar_dates.txt</span> (such as the TriMet
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>
<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>
</div>
<div class="section" id="example-project">
</section>
<section id="example-project">
<h2>Example project</h2>
<p>Check out the <a href="examples/explore/README.md" rel="nofollow">example project</a>.</p>
</div>
<div class="section" id="development">
</section>
<section id="development">
<h2>Development</h2>
<table>
<colgroup><col>
<col>
</colgroup><tbody>
<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>
</tr>
<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>
</tr>
<tr><th>Dev Docs:</th><td><a href="http://multigtfs.readthedocs.org/" rel="nofollow">http://multigtfs.readthedocs.org/</a></td>
</tr>
<tr><th>IRC:</th><td><a>irc://irc.freenode.net/tulsawebdevs</a></td>
</tr>
</tbody>
</table>
</div>
<dl class="field-list simple">
<dt>Code<span class="colon">:</span></dt>
<dd><p><a href="https://github.com/tulsawebdevs/django-multi-gtfs" rel="nofollow">https://github.com/tulsawebdevs/django-multi-gtfs</a></p>
</dd>
<dt>Issues<span class="colon">:</span></dt>
<dd><p><a href="https://github.com/tulsawebdevs/django-multi-gtfs/issues" rel="nofollow">https://github.com/tulsawebdevs/django-multi-gtfs/issues</a></p>
</dd>
<dt>Dev Docs<span class="colon">:</span></dt>
<dd><p><a href="http://multigtfs.readthedocs.org/" rel="nofollow">http://multigtfs.readthedocs.org/</a></p>
</dd>
<dt>IRC<span class="colon">:</span></dt>
<dd><p><a>irc://irc.freenode.net/tulsawebdevs</a></p>
</dd>
</dl>
</section>
4 changes: 2 additions & 2 deletions tests/fixtures/test_rst_math.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<p>A <tt>math</tt> directive:</p>
<p>A <span class="docutils literal">math</span> directive:</p>
<div class="math">
\begin{equation*}
\alpha _t(i) = P(O_1, O_2, \ldots O_t, q_t = S_i \lambda )
\end{equation*}
</div>
<p>A <tt>:math:</tt> role:</p>
<p>A <span class="docutils literal">:math:</span> role:</p>
<p>The area of a circle is <span class="math">\(A_\text{c} = (\pi/4) d^2\)</span>.</p>
70 changes: 30 additions & 40 deletions tests/fixtures/test_rst_tables.html
Original file line number Diff line number Diff line change
@@ -1,62 +1,52 @@
<table>
<colgroup>
<col>
<col>
<col>
<col>
</colgroup>
<thead>
<tr><th>Header row, column 1
(header rows optional)</th>
<th>Header 2</th>
<th>Header 3</th>
<th>Header 4</th>
<tr><th class="head"><p>Header row, column 1
(header rows optional)</p></th>
<th class="head"><p>Header 2</p></th>
<th class="head"><p>Header 3</p></th>
<th class="head"><p>Header 4</p></th>
</tr>
</thead>
<tbody>
<tr><td>body row 1, column 1</td>
<td>column 2</td>
<td>column 3</td>
<td>column 4</td>
</tr>
<tr><td>body row 2</td>
<td colspan="3">Cells may span columns.</td>
</tr>
<tr><td>body row 3</td>
<td rowspan="2">Cells may
span rows.</td>
<td colspan="2" rowspan="2"><ul>
<li>Table cells</li>
<li>contain</li>
<li>body elements.</li>
<tr><td><p>body row 1, column 1</p></td>
<td><p>column 2</p></td>
<td><p>column 3</p></td>
<td><p>column 4</p></td>
</tr>
<tr><td><p>body row 2</p></td>
<td colspan="3"><p>Cells may span columns.</p></td>
</tr>
<tr><td><p>body row 3</p></td>
<td rowspan="2"><p>Cells may
span rows.</p></td>
<td colspan="2" rowspan="2"><ul class="simple">
<li><p>Table cells</p></li>
<li><p>contain</p></li>
<li><p>body elements.</p></li>
</ul>
</td>
</tr>
<tr><td>body row 4</td>
<tr><td><p>body row 4</p></td>
</tr>
</tbody>
</table>
<table>
<colgroup>
<col>
<col>
</colgroup>
<thead>
<tr><th>title1</th>
<th>title2</th>
<tr><th class="head"><p>title1</p></th>
<th class="head"><p>title2</p></th>
</tr>
</thead>
<tbody>
<tr><td>col1</td>
<td>col2</td>
<tr><td><p>col1</p></td>
<td><p>col2</p></td>
</tr>
<tr><td rowspan="2">mutirow</td>
<td>cell1</td>
<tr><td rowspan="2"><p>mutirow</p></td>
<td><p>cell1</p></td>
</tr>
<tr><td>cell2</td>
<tr><td><p>cell2</p></td>
</tr>
<tr><td>singlerow</td>
<td>cell3</td>
<tr><td><p>singlerow</p></td>
<td><p>cell3</p></td>
</tr>
</tbody>
</table>

0 comments on commit d853780

Please sign in to comment.