chiark / gitweb /
plugins: new m.link plugin.
authorVladimír Vondruš <mosra@centrum.cz>
Sun, 26 Aug 2018 16:03:15 +0000 (18:03 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Sun, 26 Aug 2018 16:03:15 +0000 (18:03 +0200)
doc/plugins.rst
doc/plugins/links.rst
pelican-plugins/m/abbr.py
pelican-plugins/m/gh.py
pelican-plugins/m/gl.py
pelican-plugins/m/link.py [new file with mode: 0644]
pelican-plugins/m/test/link/page.html [new file with mode: 0644]
pelican-plugins/m/test/link/page.rst [new file with mode: 0644]
pelican-plugins/m/test/test_link.py [new file with mode: 0644]
pelican-plugins/m/vk.py
site/pelicanconf.py

index 1ab7289f35826a96cf39847a2efa2fc7b33ec797..8404bd5f35f560645afaa94cd93c2738886e2257 100644 (file)
@@ -47,7 +47,8 @@ and restart Pelican. Download the plugins below or
     :gh:`m.code <mosra/m.css$master/pelican-plugins/m/code.py>` (needs also :gh:`ansilexer <mosra/m.css$master/pelican-plugins/ansilexer.py>`)
 -   :gh:`m.plots <mosra/m.css$master/pelican-plugins/m/plots.py>`,
     :gh:`m.dot <mosra/m.css$master/pelican-plugins/m/dot.py>`
--   :gh:`m.gh <mosra/m.css$master/pelican-plugins/m/gh.py>`,
+-   :gh:`m.link <mosra/m.css$master/pelican-plugins/m/link.py>`,
+    :gh:`m.gh <mosra/m.css$master/pelican-plugins/m/gh.py>`,
     :gh:`m.dox <mosra/m.css$master/pelican-plugins/m/dox.py>`,
     :gh:`m.gl <mosra/m.css$master/pelican-plugins/m/gl.py>`,
     :gh:`m.vk <mosra/m.css$master/pelican-plugins/m/vk.py>`,
@@ -100,7 +101,7 @@ else.
 `Links and other » <{filename}/plugins/links.rst>`_
 ===================================================
 
-The :py:`m.gh`, :py:`m.dox`, :py:`m.gl`, :py:`m.vk`, :py:`m.abbr`,
+The :py:`m.link`, :py:`m.gh`, :py:`m.dox`, :py:`m.gl`, :py:`m.vk`, :py:`m.abbr`,
 :py:`m.fiilesize` and :py:`m.alias` plugins make it easy for you to link to
 GitHub projects, issues or PRs, to Doxygen documentation, query file sizes and
 provide URL aliases to preserve link compatibility.
index d9f3ed5b190723b2ebda0a345f53456058d329f3..3669aed4cbb18de803a792b0706547f0239327cb 100644 (file)
@@ -50,6 +50,35 @@ own requirements.
 .. contents::
     :class: m-block m-default
 
+`Stylable links`_
+=================
+
+Download the `m/link.py <{filename}/plugins.rst>`_ file, put it including the
+``m/`` directory into one of your :py:`PLUGIN_PATHS` and add :py:`m.link`
+package to your :py:`PLUGINS` in ``pelicanconf.py``:
+
+.. code:: python
+
+    PLUGINS += ['m.link']
+
+The :rst:`:link:` interpreted text role is an alternative to the builtin
+:abbr:`reST <reStructuredText>` link syntax, but with an ability to specify
+additional CSS classes. At the moment the plugin knows only external URLs.
+
+.. code-figure::
+
+    .. code:: rst
+
+        .. role:: link-flat-big(link)
+            :class: m-flat m-text m-big
+
+        :link-flat-big:`Look here, this is great! <http://mcss.mosra.cz>`
+
+    .. role:: link-flat-big(link)
+        :class: m-flat m-text m-big
+
+    :link-flat-big:`Look here, this is great! <http://mcss.mosra.cz>`
+
 `GitHub`_
 =========
 
index 812e12a8a91d038c57d4a4419c8f4404faac1f67..feaab9ec26561e5c50fec57fdc1fe2186824bc2f 100644 (file)
@@ -28,7 +28,7 @@ from docutils.parsers import rst
 from docutils.parsers.rst.roles import set_classes
 
 # to avoid dependencies, link_regexp and parse_link() is common for m.abbr,
-# m.gh, m.gl and m.vk
+# m.gh, m.gl, m.link and m.vk
 
 link_regexp = re.compile(r'(?P<title>.*) <(?P<link>.+)>')
 
index a74ace4f32e08a5f35567996f24a2f63bd2e40dd..73502697c39d4309fb7647aea08331ed7ffa72ff 100644 (file)
@@ -28,7 +28,7 @@ from docutils.parsers import rst
 from docutils.parsers.rst.roles import set_classes
 
 # to avoid dependencies, link_regexp and parse_link() is common for m.abbr,
-# m.gh, m.gl and m.vk
+# m.gh, m.gl, m.link and m.vk
 
 link_regexp = re.compile(r'(?P<title>.*) <(?P<link>.+)>')
 
index 0e89331fca076c4643a5952f4af9577f82a9cef8..7297d84578d6202bc01a423877576e93b7aaf2be 100644 (file)
@@ -28,7 +28,7 @@ from docutils.parsers import rst
 from docutils.parsers.rst.roles import set_classes
 
 # to avoid dependencies, link_regexp and parse_link() is common for m.abbr,
-# m.gh, m.gl and m.vk
+# m.gh, m.gl, m.link and m.vk
 
 link_regexp = re.compile(r'(?P<title>.*) <(?P<link>.+)>')
 
diff --git a/pelican-plugins/m/link.py b/pelican-plugins/m/link.py
new file mode 100644 (file)
index 0000000..1de1afb
--- /dev/null
@@ -0,0 +1,50 @@
+#
+#   This file is part of m.css.
+#
+#   Copyright © 2017, 2018 Vladimír Vondruš <mosra@centrum.cz>
+#
+#   Permission is hereby granted, free of charge, to any person obtaining a
+#   copy of this software and associated documentation files (the "Software"),
+#   to deal in the Software without restriction, including without limitation
+#   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+#   and/or sell copies of the Software, and to permit persons to whom the
+#   Software is furnished to do so, subject to the following conditions:
+#
+#   The above copyright notice and this permission notice shall be included
+#   in all copies or substantial portions of the Software.
+#
+#   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+#   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+#   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+#   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+#   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+#   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+#   DEALINGS IN THE SOFTWARE.
+#
+
+import re
+from docutils import nodes, utils
+from docutils.parsers import rst
+from docutils.parsers.rst.roles import set_classes
+
+# to avoid dependencies, link_regexp and parse_link() is common for m.abbr,
+# m.gh, m.gl, m.link and m.vk
+
+link_regexp = re.compile(r'(?P<title>.*) <(?P<link>.+)>')
+
+def parse_link(text):
+    link = utils.unescape(text)
+    m = link_regexp.match(link)
+    if m: return m.group('title', 'link')
+    return None, link
+
+def link(name, rawtext, text, lineno, inliner, options={}, content=[]):
+    title, url = parse_link(text)
+    if not title: title = url
+    # TODO: mailto URLs, internal links (need to gut out docutils for that)
+    set_classes(options)
+    node = nodes.reference(rawtext, title, refuri=url, **options)
+    return [node], []
+
+def register():
+    rst.roles.register_local_role('link', link)
diff --git a/pelican-plugins/m/test/link/page.html b/pelican-plugins/m/test/link/page.html
new file mode 100644 (file)
index 0000000..4960f00
--- /dev/null
@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8" />
+  <title>m.link | A Pelican Blog</title>
+  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400i,600,600i" />
+  <link rel="stylesheet" href="static/m-dark.css" />
+  <link rel="canonical" href="page.html" />
+  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+</head>
+<body>
+<header><nav id="navigation">
+  <div class="m-container">
+    <div class="m-row">
+      <a href="./" id="m-navbar-brand" class="m-col-t-9 m-col-m-none m-left-m">A Pelican Blog</a>
+    </div>
+  </div>
+</nav></header>
+<main>
+<article>
+  <div class="m-container m-container-inflatable">
+    <div class="m-row">
+      <div class="m-col-l-10 m-push-l-1">
+        <h1>m.link</h1>
+<!-- content -->
+<ul>
+<li>URL with no title: <a href="http://mcss.mosra.cz">http://mcss.mosra.cz</a></li>
+<li>URL with a title: <a href="http://mcss.mosra.cz">m.css</a></li>
+<li>Link with a class: <a class="m-flat m-text m-strong" href="https://twitter.com/czmosra">https://twitter.com/czmosra</a></li>
+</ul>
+<!-- /content -->
+      </div>
+    </div>
+  </div>
+</article>
+</main>
+</body>
+</html>
diff --git a/pelican-plugins/m/test/link/page.rst b/pelican-plugins/m/test/link/page.rst
new file mode 100644 (file)
index 0000000..5ca6a12
--- /dev/null
@@ -0,0 +1,9 @@
+m.link
+######
+
+.. role:: link-flat(link)
+    :class: m-flat m-text m-strong
+
+-   URL with no title: :link:`http://mcss.mosra.cz`
+-   URL with a title: :link:`m.css <http://mcss.mosra.cz>`
+-   Link with a class: :link-flat:`https://twitter.com/czmosra`
diff --git a/pelican-plugins/m/test/test_link.py b/pelican-plugins/m/test/test_link.py
new file mode 100644 (file)
index 0000000..e893ac8
--- /dev/null
@@ -0,0 +1,36 @@
+#
+#   This file is part of m.css.
+#
+#   Copyright © 2017, 2018 Vladimír Vondruš <mosra@centrum.cz>
+#
+#   Permission is hereby granted, free of charge, to any person obtaining a
+#   copy of this software and associated documentation files (the "Software"),
+#   to deal in the Software without restriction, including without limitation
+#   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+#   and/or sell copies of the Software, and to permit persons to whom the
+#   Software is furnished to do so, subject to the following conditions:
+#
+#   The above copyright notice and this permission notice shall be included
+#   in all copies or substantial portions of the Software.
+#
+#   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+#   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+#   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+#   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+#   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+#   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+#   DEALINGS IN THE SOFTWARE.
+#
+
+from . import PluginTestCase
+
+class Link(PluginTestCase):
+    def __init__(self, *args, **kwargs):
+        super().__init__(__file__, '', *args, **kwargs)
+
+    def test(self):
+        self.run_pelican({
+            'PLUGINS': ['m.htmlsanity', 'm.link']
+        })
+
+        self.assertEqual(*self.actual_expected_contents('page.html'))
index 8fad35f2cf4f531a0a4b351de7d332d5fdaa2536..1cbf54577c5b1693326865299c71df999cf711fd 100644 (file)
@@ -28,7 +28,7 @@ from docutils.parsers import rst
 from docutils.parsers.rst.roles import set_classes
 
 # to avoid dependencies, link_regexp and parse_link() is common for m.abbr,
-# m.gh, m.gl and m.vk
+# m.gh, m.gl, m.link and m.vk
 
 link_regexp = re.compile(r'(?P<title>.*) <(?P<link>.+)>')
 
index de0ebdbc948c520b4be61013c4968da6657217ad..cfcb7335e808cd85434f82df52ebd0ab8269c8f1 100644 (file)
@@ -147,6 +147,7 @@ PLUGINS = ['m.abbr',
            'm.gh',
            'm.htmlsanity',
            'm.images',
+           'm.link',
            'm.math',
            'm.metadata',
            'm.plots',