From: Vladimír Vondruš
Date: Fri, 8 May 2020 14:49:03 +0000 (+0200)
Subject: m.htmlsanity: apply .m-link-wrap to plain URL links.
X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=8774635585cfa72987dff5470d1c179c10bf3052;p=blog.git
m.htmlsanity: apply .m-link-wrap to plain URL links.
---
diff --git a/doc/css/typography.rst b/doc/css/typography.rst
index 03a6ce15..88b0bd97 100644
--- a/doc/css/typography.rst
+++ b/doc/css/typography.rst
@@ -443,11 +443,12 @@ in the grid system for aligning and floating blocks in a similar way.
By default, all text is wrapped according to default HTML rules. In order to
look better on very narrow screens, it's possible to use :html:`` to
-hyphenate words --- either manually on a case-by-case basis, or using the
-`m.htmlsanity plugin <{filename}/plugins/htmlsanity.rst#hyphenation>`_. The
-:html:`` HTML tag does the same without rendering any hyphens, and
-finally there's a :css:`.m-link-wrap` you can apply to links with long URLs to
-break anywhere:
+hyphenate words. The :html:`` HTML tag does the same without rendering
+any hyphens, and finally there's a :css:`.m-link-wrap` you can apply to links
+with long URLs to break anywhere. Both hyphenation and link wrapping can be
+done either manually on a case-by-case basis, or using the
+`m.htmlsanity plugin <{filename}/plugins/htmlsanity.rst>`_, which can do both
+automatically.
.. code-figure::
diff --git a/doc/plugins/htmlsanity.rst b/doc/plugins/htmlsanity.rst
index f6080e81..89040463 100644
--- a/doc/plugins/htmlsanity.rst
+++ b/doc/plugins/htmlsanity.rst
@@ -117,6 +117,15 @@ horrible, right?) with a custom HTML5 writer derived from
- :abbr:`reST ` comments are simply ignored, instead of
being put into :html:``
+Additionally, the following m.css-specific changes are done:
+
+- Footnotes and footnote references have the :css:`.m-footnote`
+ `styling classes <{filename}/css/typography.rst#footnotes-and-footnote-references>`_
+ applied
+- Links that are just URLs have :css:`.m-link-wrap` appied `to better wrap on narrow screens <{filename}/css/typography.rst#footnotes-and-footnote-references>`_.
+ Note that it's also possible to apply this and other CSS classes explicitly
+ with the `m.link <{filename}/plugins/links.rst#stylable-links>`_ plugin.
+
`Typography`_
=============
diff --git a/documentation/test_python/inspect_type_links/inspect_type_links.first.Foo.html b/documentation/test_python/inspect_type_links/inspect_type_links.first.Foo.html
index 3e0e810d..95e788b5 100644
--- a/documentation/test_python/inspect_type_links/inspect_type_links.first.Foo.html
+++ b/documentation/test_python/inspect_type_links/inspect_type_links.first.Foo.html
@@ -43,7 +43,7 @@ lead to self; referencing the subclass via reference_self_data, reference_inner_data
and reference_inner_other_data. Inside function definitions the
-rules are different as per https://docs.python.org/3/reference/executionmodel.html#resolution-of-names:
+rules are different as per https://docs.python.org/3/reference/executionmodel.html#resolution-of-names:
The scope of names defined in a class block is limited to the class
block; it does not extend to the code blocks of methods
diff --git a/plugins/m/htmlsanity.py b/plugins/m/htmlsanity.py
index 70df7f65..ce734f28 100644
--- a/plugins/m/htmlsanity.py
+++ b/plugins/m/htmlsanity.py
@@ -370,6 +370,15 @@ class SaneHtmlTranslator(HTMLTranslator):
# why?!?!
#if not isinstance(node.parent, nodes.TextElement):
#assert len(node) == 1 and isinstance(node[0], nodes.image)
+
+ # If the link is a plain URL without explicitly specified title, apply
+ # m-link-wrap so it doesn't leak out of the view on narrow screens.
+ # This can be disabled by explicitly providing the URL also as a title
+ # --- then the node will have a name attribute and we'll skip in that
+ # case.
+ if len(node.children) == 1 and isinstance(node.children[0], nodes.Text) and 'name' not in node and 'refuri' in node and node.children[0] == node['refuri']:
+ node['classes'] += ['m-link-wrap']
+
self.body.append(self.starttag(node, 'a', '', **atts))
def depart_reference(self, node):
diff --git a/plugins/m/test/gh/page.html b/plugins/m/test/gh/page.html
index 9f9f3976..1b1772a7 100644
--- a/plugins/m/test/gh/page.html
+++ b/plugins/m/test/gh/page.html
@@ -28,10 +28,10 @@
Repository link: mosra/m.css
Commit link: mosra/m.css@4d36222
Issue/PR link: mosra/magnum#123
-Tree link: https://github.com/mosra/m.css/tree/next
-Tag link: https://github.com/mosra/magnum/releases/tag/snapshot-2015-05
-File link: https://github.com/mosra/m.css/tree/master/css/m-dark.css
-Arbitrary link: https://github.com/mosra/magnum/graphs/contributors
+Tree link: https://github.com/mosra/m.css/tree/next
+Tag link: https://github.com/mosra/magnum/releases/tag/snapshot-2015-05
+File link: https://github.com/mosra/m.css/tree/master/css/m-dark.css
+Arbitrary link: https://github.com/mosra/magnum/graphs/contributors
Link with custom title
Flat link: @mosra
diff --git a/plugins/m/test/htmlsanity_content/page.html b/plugins/m/test/htmlsanity_content/page.html
index cb60caf4..43233507 100644
--- a/plugins/m/test/htmlsanity_content/page.html
+++ b/plugins/m/test/htmlsanity_content/page.html
@@ -77,7 +77,7 @@ content
An emphasised text, strong text and a literal
. Link to
Google, the heading below or just an
-URL as-is: https://mcss.mosra.cz/. E-mail. A footnote
+URL as-is: https://mcss.mosra.cz/. E-mail. A footnote
reference on a single thing and more things
+
A line:
diff --git a/plugins/m/test/htmlsanity_content/page.rst b/plugins/m/test/htmlsanity_content/page.rst
index 156d8f96..393206d6 100644
--- a/plugins/m/test/htmlsanity_content/page.rst
+++ b/plugins/m/test/htmlsanity_content/page.rst
@@ -53,6 +53,22 @@ reference on a single thing [1]_ and more things [1]_ [2]_
.. [1] A footnote description
.. [2] Second thing description
+.. container:: m-row
+
+ .. container:: m-col-m-4 m-push-m-4 m-col-t-6 m-push-t-3 m-nopady
+
+ A link that gets auto-wrapped:
+
+ http://llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch.co.uk
+
+ A link that doesn't, because the title is different:
+
+ `llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch.co.uk `_
+
+ A link that also doesn't, because the title is the same, but specified explicitly:
+
+ `http://llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch.co.uk `_
+
`Section title with link`_
--------------------------
diff --git a/plugins/m/test/htmlsanity_typography/page.html b/plugins/m/test/htmlsanity_typography/page.html
index 0736a626..54941807 100644
--- a/plugins/m/test/htmlsanity_typography/page.html
+++ b/plugins/m/test/htmlsanity_typography/page.html
@@ -58,7 +58,7 @@ verbatim blocks:
either:
diff --git a/plugins/m/test/link/page.html b/plugins/m/test/link/page.html
index 01980c98..6f1055e5 100644
--- a/plugins/m/test/link/page.html
+++ b/plugins/m/test/link/page.html
@@ -24,9 +24,9 @@
m.link