: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>`,
`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.
.. 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`_
=========
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>.+)>')
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>.+)>')
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>.+)>')
--- /dev/null
+#
+# 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)
--- /dev/null
+<!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>
--- /dev/null
+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`
--- /dev/null
+#
+# 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'))
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>.+)>')
'm.gh',
'm.htmlsanity',
'm.images',
+ 'm.link',
'm.math',
'm.metadata',
'm.plots',