From: Vladimír Vondruš Date: Sun, 26 Aug 2018 15:52:34 +0000 (+0200) Subject: plugins: make it possible to specify classes on all link roles. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=e09e2ebfd502a08253ce4f87b1b1c5c6ddd6c0b7;p=blog.git plugins: make it possible to specify classes on all link roles. --- diff --git a/doc/plugins/links.rst b/doc/plugins/links.rst index bd355ac3..d9f3ed5b 100644 --- a/doc/plugins/links.rst +++ b/doc/plugins/links.rst @@ -72,12 +72,16 @@ one slash, the target is simply prepended with ``https://github.com/``. Link text is equal to link target for repository, commit and issue/PR links, otherwise the full expanded URL is used. Similarly to builtin linking functionality, if you want a custom text for a link, use the -:rst:`:gh:`link text `` syntax. +:rst:`:gh:`link text `` syntax. It's also possible to add custom +CSS classes by deriving the role and adding the :rst:`:class:` option. .. code-figure:: .. code:: rst + .. role:: gh-flat(gh) + :class: m-flat + - Profile link: :gh:`mosra` - Repository link: :gh:`mosra/m.css` - Commit link: :gh:`mosra/m.css@4d362223f107cffd8731a0ea031f9353a0a2c7c4` @@ -87,6 +91,10 @@ functionality, if you want a custom text for a link, use the - File link: :gh:`mosra/m.css$master/css/m-dark.css` - Arbitrary link: :gh:`mosra/magnum/graphs/contributors` - :gh:`Link with custom title ` + - Flat link: :gh-flat:`mosra` + + .. role:: gh-flat(gh) + :class: m-flat - Profile link: :gh:`mosra` - Repository link: :gh:`mosra/m.css` @@ -97,6 +105,7 @@ functionality, if you want a custom text for a link, use the - File link: :gh:`mosra/m.css$master/css/m-dark.css` - Arbitrary link: :gh:`mosra/magnum/graphs/contributors` - :gh:`Link with custom title ` + - Flat link: :gh-flat:`mosra` `OpenGL functions and extensions`_ ================================== @@ -119,23 +128,32 @@ Link text is equal to full function name including the ``gl`` prefix and ``()`` for functions, equal to extension name or equal to extension function link, including the vendor suffix. For :rst:`:glfn:`, :rst:`:glext:` and :rst:`:webglext:` it's possible to specify alternate link text using the -well-known syntax. +well-known syntax. Adding custom CSS classes can be done by deriving the role +and adding the :rst:`:class:` option. .. code-figure:: .. code:: rst + .. role:: glfn-flat(glfn) + :class: m-flat + - Function link: :glfn:`DispatchCompute` - Extension link: :glext:`ARB_direct_state_access` - WebGL extension link: :webglext:`OES_texture_float` - Extension function link: :glfnext:`SpecializeShader ` - :glfn:`Custom link title ` + - Flat link: :glfn-flat:`DrawElements` + + .. role:: glfn-flat(glfn) + :class: m-flat - Function link: :glfn:`DispatchCompute` - Extension link: :glext:`ARB_direct_state_access` - WebGL extension link: :webglext:`OES_texture_float` - Extension function link: :glfnext:`SpecializeShader ` - :glfn:`Custom link title ` + - Flat link: :glfn-flat:`DrawElements` `Vulkan functions and extensions`_ ================================== @@ -162,17 +180,25 @@ possible to specify alternate link text using the well-known syntax. .. code:: rst + .. role:: vkfn-flat(vkfn) + :class: m-flat + - Function link: :vkfn:`CreateInstance` - Type link: :vktype:`InstanceCreateInfo` - Definition link: :vktype:`VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO ` - Extension link: :vkext:`KHR_swapchain` - :vkfn:`Custom link title ` + - Flat link :vkfn-flat:`DestroyDevice` + + .. role:: vkfn-flat(vkfn) + :class: m-flat - Function link: :vkfn:`CreateInstance` - Type link: :vktype:`InstanceCreateInfo` - Definition link: :vktype:`VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO ` - Extension link: :vkext:`KHR_swapchain` - :vkfn:`Custom link title ` + - Flat link :vkfn-flat:`DestroyDevice` `Doxygen documentation`_ ======================== @@ -209,18 +235,26 @@ just the title is rendered, as normal text). You can append ``#anchor`` to ``link-target`` to link to anchors that are not present in the tag file (such as ``#details`` for the detailed docs or ``#pub-methods`` for jumping straight to a list of public member functions), the same works for query parameters -starting with ``?``. +starting with ``?``. Adding custom CSS classes can be done by deriving the role +and adding the :rst:`:class:` option. .. code-figure:: .. code:: rst + .. role:: dox-flat(dox) + :class: m-flat + - Function link: :dox:`Utility::Directory::mkpath()` - Class link: :dox:`Interconnect::Emitter` - Page link: :dox:`building-corrade` - :dox:`Custom link title ` - :dox:`Link to documentation index page ` - :dox:`Link to an anchor ` + - Flat link: :dox-flat:`plugin-management` + + .. role:: dox-flat(dox) + :class: m-flat - Function link: :dox:`Utility::Directory::mkpath()` - Class link: :dox:`Interconnect::Emitter` @@ -228,6 +262,7 @@ starting with ``?``. - :dox:`Custom link title ` - :dox:`Link to documentation index page ` - :dox:`Link to an anchor ` + - Flat link: :dox-flat:`plugin-management` .. note-success:: @@ -256,16 +291,23 @@ and makes its syntax consistent with other common roles of :abbr:`reST ` and :abbr:`CSS ` + .. role:: abbr-warning(abbr) + :class: m-text m-warning + + :abbr:`HTML ` and :abbr-warning:`CSS ` are *all you need* for producing rich content-oriented websites. - :abbr:`HTML ` and :abbr:`CSS ` + .. role:: abbr-warning(abbr) + :class: m-text m-warning + + :abbr:`HTML ` and :abbr-warning:`CSS ` are *all you need* for producing rich content-oriented websites. `File size queries`_ @@ -284,20 +326,27 @@ including the ``m/`` directory into one of your :py:`PLUGIN_PATHS` and add Use the :rst:`filesize` interpreted text role to display the size of a file including units. The :rst:`filesize-gz` role compresses the file using GZip -first before calculating the size. +first before calculating the size. Adding custom CSS classes can be done by +deriving the role and adding the :rst:`:class:` option. .. code-figure:: .. code:: rst + .. role:: filesize-yay(filesize-gz) + :class: m-text m-success + The compiled ``m-dark.compiled.css`` CSS file has :filesize:`{filename}/../css/m-dark.compiled.css` but only - :filesize-gz:`{filename}/../css/m-dark.compiled.css` when the server + :filesize-yay:`{filename}/../css/m-dark.compiled.css` when the server sends it compressed. + .. role:: filesize-yay(filesize-gz) + :class: m-text m-success + The compiled ``m-dark.compiled.css`` CSS file has :filesize:`{filename}/../css/m-dark.compiled.css` but only - :filesize-gz:`{filename}/../css/m-dark.compiled.css` when the server + :filesize-yay:`{filename}/../css/m-dark.compiled.css` when the server sends it compressed. `Aliases`_ diff --git a/pelican-plugins/m/abbr.py b/pelican-plugins/m/abbr.py index 219f9dcb..812e12a8 100644 --- a/pelican-plugins/m/abbr.py +++ b/pelican-plugins/m/abbr.py @@ -25,6 +25,7 @@ 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 and m.vk @@ -39,9 +40,10 @@ def parse_link(text): def abbr(name, rawtext, text, lineno, inliner, options={}, content=[]): abbr, title = parse_link(text) + set_classes(options) if not abbr: - return [nodes.abbreviation(title, title)], [] - return [nodes.abbreviation(abbr, abbr, title=title)], [] + return [nodes.abbreviation(title, title, **options)], [] + return [nodes.abbreviation(abbr, abbr, title=title, **options)], [] def register(): rst.roles.register_local_role('abbr', abbr) diff --git a/pelican-plugins/m/dox.py b/pelican-plugins/m/dox.py index 4063841b..8cda075c 100644 --- a/pelican-plugins/m/dox.py +++ b/pelican-plugins/m/dox.py @@ -25,6 +25,8 @@ from docutils.parsers.rst.states import Inliner from docutils import nodes, utils from docutils.parsers import rst +from docutils.parsers.rst.roles import set_classes + from pelican import signals import xml.etree.ElementTree as ET import os @@ -116,6 +118,8 @@ def init(pelicanobj): def dox(name, rawtext, text, lineno, inliner: Inliner, options={}, content=[]): title, target, hash = parse_link(text) + set_classes(options) + # Try linking to the whole docs first for basename, url in tagfile_basenames: if basename == target: diff --git a/pelican-plugins/m/filesize.py b/pelican-plugins/m/filesize.py index 60c8afa0..ad85428d 100644 --- a/pelican-plugins/m/filesize.py +++ b/pelican-plugins/m/filesize.py @@ -26,6 +26,7 @@ import os import gzip from docutils import nodes from docutils.parsers import rst +from docutils.parsers.rst.roles import set_classes from pelican import signals settings = {} @@ -44,7 +45,8 @@ def filesize(name, rawtext, text, lineno, inliner, options={}, content=[]): size /= 1024.0 else: size_string = "%.1f PB" % size - return [nodes.inline(size_string, size_string)], [] + set_classes(options) + return [nodes.inline(size_string, size_string, **options)], [] def filesize_gz(name, rawtext, text, lineno, inliner, options={}, content=[]): with open(text.format(filename=os.path.join(os.getcwd(), settings['path'])), mode='rb') as f: @@ -57,7 +59,8 @@ def filesize_gz(name, rawtext, text, lineno, inliner, options={}, content=[]): size /= 1024.0 else: size_string = "%.1f PB" % size - return [nodes.inline(size_string, size_string)], [] + set_classes(options) + return [nodes.inline(size_string, size_string, **options)], [] def register(): signals.initialized.connect(init) diff --git a/pelican-plugins/m/gh.py b/pelican-plugins/m/gh.py index 689a55ab..a74ace4f 100644 --- a/pelican-plugins/m/gh.py +++ b/pelican-plugins/m/gh.py @@ -25,6 +25,7 @@ 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 and m.vk @@ -72,6 +73,7 @@ def gh(name, rawtext, text, lineno, inliner, options={}, content=[]): else: title, url = gh_internal(account, ref, title, link) + set_classes(options) node = nodes.reference(rawtext, title, refuri=url, **options) return [node], [] diff --git a/pelican-plugins/m/gl.py b/pelican-plugins/m/gl.py index 01f9b84c..0e89331f 100644 --- a/pelican-plugins/m/gl.py +++ b/pelican-plugins/m/gl.py @@ -25,6 +25,7 @@ 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 and m.vk @@ -42,6 +43,7 @@ def glext(name, rawtext, text, lineno, inliner, options={}, content=[]): if not title: title = extension prefix = extension.partition('_')[0] url = "https://www.khronos.org/registry/OpenGL/extensions/{}/{}.txt".format(prefix, extension) + set_classes(options) node = nodes.reference(rawtext, title, refuri=url, **options) return [node], [] @@ -49,6 +51,7 @@ def webglext(name, rawtext, text, lineno, inliner, options={}, content=[]): title, extension = parse_link(text) if not title: title = extension url = "https://www.khronos.org/registry/webgl/extensions/{}/".format(extension) + set_classes(options) node = nodes.reference(rawtext, title, refuri=url, **options) return [node], [] @@ -56,6 +59,7 @@ def glfn(name, rawtext, text, lineno, inliner, options={}, content=[]): title, fn = parse_link(text) if not title: title = "gl{}()".format(fn) url = "https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/gl{}.xhtml".format(fn) + set_classes(options) node = nodes.reference(rawtext, title, refuri=url, **options) return [node], [] @@ -63,6 +67,7 @@ def glfnext(name, rawtext, text, lineno, inliner, options={}, content=[]): title, extension = parse_link(text) prefix = extension.partition('_')[0] url = "https://www.khronos.org/registry/OpenGL/extensions/{}/{}.txt".format(prefix, extension) + set_classes(options) node = nodes.reference(rawtext, "gl" + title + prefix + "()", refuri=url, **options) return [node], [] diff --git a/pelican-plugins/m/test/abbr/page.html b/pelican-plugins/m/test/abbr/page.html index 4a121abf..bcf66a6f 100644 --- a/pelican-plugins/m/test/abbr/page.html +++ b/pelican-plugins/m/test/abbr/page.html @@ -23,7 +23,7 @@

m.abbr

-

Text. Text.

+

Text. Text. Strong Abbr.

diff --git a/pelican-plugins/m/test/abbr/page.rst b/pelican-plugins/m/test/abbr/page.rst index 2d8118aa..d277ad0f 100644 --- a/pelican-plugins/m/test/abbr/page.rst +++ b/pelican-plugins/m/test/abbr/page.rst @@ -1,4 +1,7 @@ m.abbr ###### -:abbr:`Text `. :abbr:`Text`. +.. role:: abbr-strong(abbr) + :class: m-text m-strong + +:abbr:`Text <Title>`. :abbr:`Text`. :abbr-strong:`Strong Abbr <STRONGG!>`. diff --git a/pelican-plugins/m/test/dox/page.html b/pelican-plugins/m/test/dox/page.html index aad6bd63..33e05c4e 100644 --- a/pelican-plugins/m/test/dox/page.html +++ b/pelican-plugins/m/test/dox/page.html @@ -34,6 +34,7 @@ <li><a href="http://doc.magnum.graphics/corrade/#search">Link to index page with hash after</a></li> <li><a href="http://doc.magnum.graphics/corrade/corrade-cmake.html#search">Link to page with hash after</a></li> <li><a href="http://doc.magnum.graphics/corrade/namespaceCorrade_1_1Utility_1_1Directory.html?q=hello#search">Link to class with query and hash after</a></li> +<li>Flat link: <a class="m-flat" href="http://doc.magnum.graphics/corrade/plugin-management.html">Plugin management tutorial</a></li> </ul> <p>These should produce warnings:</p> <ul> diff --git a/pelican-plugins/m/test/dox/page.rst b/pelican-plugins/m/test/dox/page.rst index f401ccf9..a9f09cd4 100644 --- a/pelican-plugins/m/test/dox/page.rst +++ b/pelican-plugins/m/test/dox/page.rst @@ -1,6 +1,9 @@ m.dox ##### +.. role:: dox-flat(dox) + :class: m-flat + - Function link: :dox:`Utility::Directory::mkpath()` - Class link: :dox:`Interconnect::Emitter` - Page link: :dox:`building-corrade` @@ -11,6 +14,7 @@ m.dox - :dox:`Link to index page with hash after <corrade#search>` - :dox:`Link to page with hash after <corrade-cmake#search>` - :dox:`Link to class with query and hash after <Utility::Directory?q=hello#search>` +- Flat link: :dox-flat:`plugin-management` These should produce warnings: diff --git a/pelican-plugins/m/test/filesize/page.html b/pelican-plugins/m/test/filesize/page.html index b7ea6e59..a4aab6f8 100644 --- a/pelican-plugins/m/test/filesize/page.html +++ b/pelican-plugins/m/test/filesize/page.html @@ -23,8 +23,9 @@ <div class="m-col-l-10 m-push-l-1"> <h1>m.filesize</h1> <!-- content --> -<p>This file has <span>117.0 B</span> and <span>91.0 B</span> -gzipped.</p> +<p>This file has <span>342.0 B</span> and <span>177.0 B</span> +gzipped. I mean, <span class="m-text m-success">177.0 B</span> is good, but +<span class="m-text m-danger">342.0 B</span> not.</p> <!-- /content --> </div> </div> diff --git a/pelican-plugins/m/test/filesize/page.rst b/pelican-plugins/m/test/filesize/page.rst index c247d02d..0c79fa8d 100644 --- a/pelican-plugins/m/test/filesize/page.rst +++ b/pelican-plugins/m/test/filesize/page.rst @@ -1,5 +1,11 @@ m.filesize ########## +.. role:: filesize-nay(filesize) + :class: m-text m-danger +.. role:: filesize-yay(filesize-gz) + :class: m-text m-success + This file has :filesize:`{filename}/page.rst` and :filesize-gz:`{filename}/page.rst` -gzipped. +gzipped. I mean, :filesize-yay:`{filename}/page.rst` is good, but +:filesize-nay:`{filename}/page.rst` not. diff --git a/pelican-plugins/m/test/gh/page.html b/pelican-plugins/m/test/gh/page.html index 5d7332ab..9f9f3976 100644 --- a/pelican-plugins/m/test/gh/page.html +++ b/pelican-plugins/m/test/gh/page.html @@ -33,6 +33,7 @@ <li>File link: <a href="https://github.com/mosra/m.css/tree/master/css/m-dark.css">https://github.com/mosra/m.css/tree/master/css/m-dark.css</a></li> <li>Arbitrary link: <a href="https://github.com/mosra/magnum/graphs/contributors">https://github.com/mosra/magnum/graphs/contributors</a></li> <li><a href="https://github.com/getpelican/pelican">Link with custom title</a></li> +<li>Flat link: <a class="m-flat" href="https://github.com/mosra">@mosra</a></li> </ul> <!-- /content --> </div> diff --git a/pelican-plugins/m/test/gh/page.rst b/pelican-plugins/m/test/gh/page.rst index 0d278371..4a0a388b 100644 --- a/pelican-plugins/m/test/gh/page.rst +++ b/pelican-plugins/m/test/gh/page.rst @@ -1,6 +1,9 @@ m.gh #### +.. role:: gh-flat(gh) + :class: m-flat + - Profile link: :gh:`mosra` - Repository link: :gh:`mosra/m.css` - Commit link: :gh:`mosra/m.css@4d362223f107cffd8731a0ea031f9353a0a2c7c4` @@ -10,3 +13,4 @@ m.gh - File link: :gh:`mosra/m.css$master/css/m-dark.css` - Arbitrary link: :gh:`mosra/magnum/graphs/contributors` - :gh:`Link with custom title <getpelican/pelican>` +- Flat link: :gh-flat:`mosra` diff --git a/pelican-plugins/m/test/gl/page.html b/pelican-plugins/m/test/gl/page.html index 9676821c..20b763bf 100644 --- a/pelican-plugins/m/test/gl/page.html +++ b/pelican-plugins/m/test/gl/page.html @@ -29,6 +29,7 @@ <li>WebGL extension link: <a href="https://www.khronos.org/registry/webgl/extensions/OES_texture_float/">OES_texture_float</a></li> <li>Extension function link: <a href="https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_gl_spirv.txt">glSpecializeShaderARB()</a></li> <li><a href="https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glDrawElementsIndirect.xhtml">Custom link title</a></li> +<li>Flat link: <a class="m-flat" href="https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glDrawElements.xhtml">glDrawElements()</a></li> </ul> <!-- /content --> </div> diff --git a/pelican-plugins/m/test/gl/page.rst b/pelican-plugins/m/test/gl/page.rst index efe36130..ebcc04e2 100644 --- a/pelican-plugins/m/test/gl/page.rst +++ b/pelican-plugins/m/test/gl/page.rst @@ -1,8 +1,12 @@ m.gl #### +.. role:: glfn-flat(glfn) + :class: m-flat + - Function link: :glfn:`DispatchCompute` - Extension link: :glext:`ARB_direct_state_access` - WebGL extension link: :webglext:`OES_texture_float` - Extension function link: :glfnext:`SpecializeShader <ARB_gl_spirv>` - :glfn:`Custom link title <DrawElementsIndirect>` +- Flat link: :glfn-flat:`DrawElements` diff --git a/pelican-plugins/m/test/vk/page.html b/pelican-plugins/m/test/vk/page.html index b5003d3a..0235f51d 100644 --- a/pelican-plugins/m/test/vk/page.html +++ b/pelican-plugins/m/test/vk/page.html @@ -29,6 +29,7 @@ <li>Definition link: <a href="https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VkStructureType.html">VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO</a></li> <li>Extension link: <a href="https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#VK_KHR_swapchain">KHR_swapchain</a></li> <li><a href="https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/vkDestroyInstance.html">Custom link title</a></li> +<li>Flat link <a class="m-flat" href="https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/vkDestroyDevice.html">vkDestroyDevice()</a></li> </ul> <!-- /content --> </div> diff --git a/pelican-plugins/m/test/vk/page.rst b/pelican-plugins/m/test/vk/page.rst index 2bc76cdd..d9dbd8d5 100644 --- a/pelican-plugins/m/test/vk/page.rst +++ b/pelican-plugins/m/test/vk/page.rst @@ -1,8 +1,12 @@ m.vk #### +.. role:: vkfn-flat(vkfn) + :class: m-flat + - Function link: :vkfn:`CreateInstance` - Type link: :vktype:`InstanceCreateInfo` - Definition link: :vktype:`VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO <StructureType>` - Extension link: :vkext:`KHR_swapchain` - :vkfn:`Custom link title <DestroyInstance>` +- Flat link :vkfn-flat:`DestroyDevice` diff --git a/pelican-plugins/m/vk.py b/pelican-plugins/m/vk.py index 7eba3d6d..8fad35f2 100644 --- a/pelican-plugins/m/vk.py +++ b/pelican-plugins/m/vk.py @@ -25,6 +25,7 @@ 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 and m.vk @@ -41,6 +42,7 @@ def vkext(name, rawtext, text, lineno, inliner, options={}, content=[]): title, extension = parse_link(text) if not title: title = extension url = "https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#VK_{}".format(extension) + set_classes(options) node = nodes.reference(rawtext, title, refuri=url, **options) return [node], [] @@ -48,6 +50,7 @@ def vkfn(name, rawtext, text, lineno, inliner, options={}, content=[]): title, fn = parse_link(text) if not title: title = "vk{}()".format(fn) url = "https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/vk{}.html".format(fn) + set_classes(options) node = nodes.reference(rawtext, title, refuri=url, **options) return [node], [] @@ -55,6 +58,7 @@ def vktype(name, rawtext, text, lineno, inliner, options={}, content=[]): title, fn = parse_link(text) if not title: title = "Vk{}".format(fn) url = "https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/Vk{}.html".format(fn) + set_classes(options) node = nodes.reference(rawtext, title, refuri=url, **options) return [node], []