Skip to main content

Pelican plugin to set anchor tag's class attribute to differentiate between internal and external links

Project description

Link Class: A Plugin for Pelican

Build Status PyPI Version License

This Pelican plugin allows you to set the class attribute of <a> elements (generated in Markdown by [ext](link)) according to whether the link is external (i.e., starts with http:// or https://) or internal to the Pelican-generated site.

For now, this plugin only works with Markdown. It has been tested with version 3.0+ of the Python-Markdown module and may not work with previous versions.

Installation

This plugin is available as a package at PyPI and can be installed via:

python -m pip install pelican-linkclass

Configuration

In order to avoid clashes with already-defined classes in the user CSS style sheets, it is possible to specify the name of the classes that will be used. They can be specified in the Pelican setting file with the LINKCLASS variable, which must be defined as a list of tuples, like this:

'LINKCLASS' = (('EXTERNAL_CLASS', 'name-of-the-class-for-external-links')
                'INTERNAL_CLASS', 'name-of-the-class-for-internal-links'))

The default values for EXTERNAL_CLASS and INTERNAL_CLASS are, respectively, 'external' and 'internal'.

Styling Hyperlinks

One of the possible uses of this plugins is for styling. Suppose that we have the following Markdown content in your article:

This is an [internal](internal) link and this is an
[external](http://external.com) link.

If the default configuration variable values are used, then one possible CSS setting could be:

a.external:before {
    content: url('../images/external-link.png');
    margin-right: 0.2em;
}

(The file external-link.png is also distributed with this plugin. To use it, copy it to the appropriate place in your web site source tree, for instance in theme/static/images/.)

Then, the result will look like the following:

figure

Note that this plugin also works with reference-style links, as in the following example:

This is an [internal][internal] link and this is an
[external][external] link.

 [internal]: internal
 [external]: http://external.com

Contributing

Contributions are welcome and much appreciated. Every little bit helps. You can contribute by improving the documentation, adding missing features, and fixing bugs. You can also help out by reviewing and commenting on existing issues.

To start contributing to this plugin, review the Contributing to Pelican documentation, beginning with the Contributing Code section.

Acknowledgments

Many thanks to Yuliya Bagriy for setting up the package for PyPI, to Lucas Cimon for fixing the issues with pytest, and to Justin Mayer for helping with migration of this plugin under the Pelican Plugins organization.

Author

Copyright (C) 2015, 2017, 2019, 2021 Rafael Laboissière (rafael@laboissiere.net)

Released under the GNU Affero Public License, version 3 or later. No warranties.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pelican-linkclass-2.0.2.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pelican_linkclass-2.0.2-py3-none-any.whl (19.7 kB view details)

Uploaded Python 3

File details

Details for the file pelican-linkclass-2.0.2.tar.gz.

File metadata

  • Download URL: pelican-linkclass-2.0.2.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.7.12 Linux/5.11.0-1022-azure

File hashes

Hashes for pelican-linkclass-2.0.2.tar.gz
Algorithm Hash digest
SHA256 6fe5d7322e362153d3c86ab607467a51714f5b54a558078efd066d46bd4b3d08
MD5 5e9bfc40dad114524b7698208d0b3c3c
BLAKE2b-256 b7bdb93af8d6bc01d0211e6f92d986fafc0407239dfd21ce316077372ef53ffe

See more details on using hashes here.

File details

Details for the file pelican_linkclass-2.0.2-py3-none-any.whl.

File metadata

  • Download URL: pelican_linkclass-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 19.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.7.12 Linux/5.11.0-1022-azure

File hashes

Hashes for pelican_linkclass-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e64d7214db9111399100fcdfbc766e3ed52ddc0b0724124c57e7c55292dd83d5
MD5 c486103f56f13ef1f6201036caf1863b
BLAKE2b-256 e6fc14ca2d87833aa924b9eb2462adb05b51447a608c48e105930742e5db5c94

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page