Pelican plugin to set anchor tag's class attribute to differentiate between internal and external links
Project description
Link Class: A Plugin for Pelican
This Pelican plugin lets you to set the class attribute of <a> elements (generated in Markdown by [ext](link)), depending on whether the link is external (i.e., starts with http:// or https://) or internal to the Pelican-generated site.
Currently, this plugin only works with Markdown. It has been tested with version 3.0+ of the Python-Markdown module and may not work with earlier versions.
Installation
This plugin is available as a package at PyPI and can be installed via:
python -m pip install pelican-linkclass
As long as there is no PLUGINS setting in the Pelican settings file, the newly installed plugin should be detected and enabled automatically. Otherwise, you must add linkclass to your existing PLUGINS list. For more information, please refer to the How to Use Plugins documentation.
Configuration
To avoid clashing with classes already defined in user CSS style sheets, it is possible to specify the names of the classes that will be used. This can be done in the Pelican settings file by defining the LINKCLASS variable as a list of tuples, such as in this example:
'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 possible use of this plugin 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.
Using the default configuration variable values, a possible CSS setting could be:
a.external:before {
content: url('../images/external-link.png');
margin-right: 0.2em;
}
(The external-link.png file is also distributed with this plugin. To use it, copy it to the appropriate location in your website's source tree, for instance in the theme/static/images/ directory.)
The result will then look like this:
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 © 2015, 2017, 2019, 2021-2023, 2025 Rafael Laboissière (rafael@laboissiere.net)
License
This project is released under the terms of the GNU Affero Public License, version 3 or later.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pelican_linkclass-2.1.6.tar.gz.
File metadata
- Download URL: pelican_linkclass-2.1.6.tar.gz
- Upload date:
- Size: 22.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3217a3698371d1748282c06ed1d6daf8885916cb1d15d80e3445d1ddfcb9bf7
|
|
| MD5 |
0e19493b33e3ee89ef54b252ee691aa2
|
|
| BLAKE2b-256 |
3dc9073e18281a17c2832ed42bb252da4fa1d648bcd765b1b7f42f4202db92e9
|
Provenance
The following attestation bundles were made for pelican_linkclass-2.1.6.tar.gz:
Publisher:
main.yml on pelican-plugins/linkclass
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pelican_linkclass-2.1.6.tar.gz -
Subject digest:
d3217a3698371d1748282c06ed1d6daf8885916cb1d15d80e3445d1ddfcb9bf7 - Sigstore transparency entry: 691516572
- Sigstore integration time:
-
Permalink:
pelican-plugins/linkclass@da2b57ed7d44b1b90586e12ec71e2d0558785864 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pelican-plugins
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@da2b57ed7d44b1b90586e12ec71e2d0558785864 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pelican_linkclass-2.1.6-py3-none-any.whl.
File metadata
- Download URL: pelican_linkclass-2.1.6-py3-none-any.whl
- Upload date:
- Size: 20.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db862353b5d86b9962cae7514a297e59829449eaa36c45f4a9d17d448a5a74e3
|
|
| MD5 |
1112078e2112dccc47aaa337a9771218
|
|
| BLAKE2b-256 |
a067ed96928179e02de45a915d87d677783291fdec81e914be37cb70a795d885
|
Provenance
The following attestation bundles were made for pelican_linkclass-2.1.6-py3-none-any.whl:
Publisher:
main.yml on pelican-plugins/linkclass
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pelican_linkclass-2.1.6-py3-none-any.whl -
Subject digest:
db862353b5d86b9962cae7514a297e59829449eaa36c45f4a9d17d448a5a74e3 - Sigstore transparency entry: 691516647
- Sigstore integration time:
-
Permalink:
pelican-plugins/linkclass@da2b57ed7d44b1b90586e12ec71e2d0558785864 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pelican-plugins
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@da2b57ed7d44b1b90586e12ec71e2d0558785864 -
Trigger Event:
push
-
Statement type: