pelican-linkclass 2.1.3__tar.gz → 2.1.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pelican-linkclass might be problematic. Click here for more details.

@@ -0,0 +1,67 @@
1
+ CHANGELOG
2
+ =========
3
+
4
+ 2.1.4 - 2024-04-14
5
+ ------------------
6
+
7
+ Ensure plugin is included in sdist build
8
+
9
+ 2.1.3 - 2024-04-07
10
+ ------------------
11
+
12
+ Maintainance release (no user visible changes)
13
+
14
+ * Add Python 3.12 to CI test matrix
15
+ * Switch build system from Hatchling to PDM
16
+ * Fix linters errors
17
+
18
+ 2.1.2 - 2023-10-31
19
+ ------------------
20
+
21
+ Fix project name
22
+
23
+ 2.1.1 - 2023-10-31
24
+ ------------------
25
+
26
+ Maintenance release:
27
+
28
+ - Migrate to the new tooling standards
29
+ - Improve code quality
30
+
31
+ 2.1.0 - 2023-04-13
32
+ ------------------
33
+
34
+ The tuples in the LINKCLASS configuration variable have only two elements now. This makes the code consistent with the plugin documentation (README.md file) and resolves issue #34.
35
+
36
+ 2.0.4 - 2022-10-01
37
+ ------------------
38
+
39
+ Update list of years in Copyright notices
40
+
41
+ 2.0.3 - 2022-07-15
42
+ ------------------
43
+
44
+ In `test_linkclass.py`, use `io` instead of `six` to import `StringIO`.
45
+
46
+ 2.0.2 - 2021-12-17
47
+ ------------------
48
+
49
+ Upgrade code to Python 3.6+ (thanks to Justin Mayer)
50
+
51
+ 2.0.1 - 2021-11-04
52
+ ------------------
53
+
54
+ Maintenance release: Use .format() instead of % operator to format strings
55
+
56
+ 2.0.0 - 2021-02-17
57
+ ------------------
58
+
59
+ Convert to namespace plugin for use with Pelican 4.5 and above
60
+
61
+ [Justin Mayer](https://github.com/justinmayer) [PR #11](https://github.com/pelican-plugins/linkclass/pull/11/)
62
+
63
+
64
+ 1.0.0 - 2019-09-29
65
+ ------------------
66
+
67
+ Initial release to PyPI
@@ -0,0 +1,9 @@
1
+ Contributing
2
+ ============
3
+
4
+ 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][].
5
+
6
+ To start contributing to this plugin, review the [Contributing to Pelican][] documentation, beginning with the **Contributing Code** section.
7
+
8
+ [existing issues]: https://github.com/pelican-plugins/linkclass/issues
9
+ [Contributing to Pelican]: https://docs.getpelican.com/en/latest/contribute.html
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pelican-linkclass
3
- Version: 2.1.3
3
+ Version: 2.1.4
4
4
  Summary: Pelican plugin to set anchor tag's class attribute to differentiate between internal and external links
5
- Keywords: pelican plugin link class
6
- Author-Email: Rafael Laboissière <rafael@laboissiere.net>
5
+ Keywords: pelican,plugin,link class
6
+ Author-Email: =?utf-8?q?Rafael_Laboissi=C3=A8re?= <rafael@laboissiere.net>
7
7
  License: AGPL-3.0
8
8
  Classifier: Development Status :: 5 - Production/Stable
9
9
  Classifier: Environment :: Console
@@ -0,0 +1 @@
1
+ from .linkclass import * # NOQA: F403
@@ -0,0 +1,51 @@
1
+ """Link Class Plugin for Pelican."""
2
+
3
+ # Copyright (C) 2015, 2019, 2023 Rafael Laboissière
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify it
6
+ # under the terms of the GNU General Affero Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or (at
8
+ # your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful, but
11
+ # WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see http://www.gnu.org/licenses/.
17
+
18
+
19
+ from pelican import signals
20
+
21
+ from .mdx_linkclass import LC_CONFIG, LinkClassExtension
22
+
23
+
24
+ def addLinkClass(gen):
25
+ """Add LinkClass connector."""
26
+ if not gen.settings.get("MARKDOWN"):
27
+ from pelican.settings import DEFAULT_CONFIG
28
+
29
+ gen.settings["MARKDOWN"] = DEFAULT_CONFIG["MARKDOWN"]
30
+
31
+ if gen.settings.get("LINKCLASS"):
32
+ for param, default in gen.settings.get("LINKCLASS"):
33
+ LC_CONFIG[param] = default
34
+
35
+ if LinkClassExtension not in gen.settings["MARKDOWN"]:
36
+ config = {}
37
+ for key, value in LC_CONFIG.items():
38
+ config[key] = value
39
+ for key, value in gen.settings.items():
40
+ if key in LC_CONFIG:
41
+ config[key] = value
42
+ lcobj = LinkClassExtension(config)
43
+ try:
44
+ gen.settings["MARKDOWN"]["extensions"].append(lcobj)
45
+ except KeyError:
46
+ gen.settings["MARKDOWN"]["extensions"] = [lcobj]
47
+
48
+
49
+ def register():
50
+ """Register the Link Class plugin with Pelican."""
51
+ signals.initialized.connect(addLinkClass)
@@ -0,0 +1,105 @@
1
+ """Markdown extension for the Link Class plugin for Pelican."""
2
+
3
+ # Copyright (C) 2015, 2017, 2019, 2023 Rafael Laboissière
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify it
6
+ # under the terms of the GNU General Affero Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or (at
8
+ # your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful, but
11
+ # WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see http://www.gnu.org/licenses/.
17
+
18
+
19
+ import re
20
+
21
+ from markdown.extensions import Extension
22
+ from markdown.inlinepatterns import (
23
+ LINK_RE,
24
+ REFERENCE_RE,
25
+ LinkInlineProcessor,
26
+ ReferenceInlineProcessor,
27
+ )
28
+
29
+ LC_CONFIG = {"INTERNAL_CLASS": "internal", "EXTERNAL_CLASS": "external"}
30
+ LC_HELP = {
31
+ "INTERNAL_CLASS": "Name of the CSS class for internal links",
32
+ "EXTERNAL_CLASS": "Name of the CSS class for external links",
33
+ }
34
+
35
+
36
+ def add_class(elm, config):
37
+ """Utlity function for adding the appropriate class attribute."""
38
+ try:
39
+ m = re.match("^https?://", elm.get("href"))
40
+ elm.set("class", m and config["EXTERNAL_CLASS"] or config["INTERNAL_CLASS"])
41
+ except AttributeError:
42
+ pass
43
+ return elm
44
+
45
+
46
+ class LinkClassExtension(Extension):
47
+ """Markdown extension for the Link Class plugin."""
48
+
49
+ def __init__(self, config):
50
+ """Initialize the class object."""
51
+ for key, value in LC_CONFIG.items():
52
+ self.config[key] = [value, LC_HELP[key]]
53
+ super().__init__(**config)
54
+
55
+ def extendMarkdown(self, md):
56
+ """Register the Markdown extension."""
57
+ # LinkClass instances is added to the list of inline pattern
58
+ # processors, with higher priority than the processor defined for the
59
+ # "link" and the "reference" objects, such that the normal behavior is
60
+ # overridden.
61
+ LinkClassPattern = LinkClass(LINK_RE, self.getConfigs())
62
+ LinkClassPattern.md = md
63
+ md.inlinePatterns.register(LinkClassPattern, "linkclass", 200)
64
+ ReferenceClassPattern = ReferenceClass(REFERENCE_RE, self.getConfigs())
65
+ ReferenceClassPattern.md = md
66
+ md.inlinePatterns.register(ReferenceClassPattern, "referenceclass", 200)
67
+
68
+
69
+ class LinkClass(LinkInlineProcessor):
70
+ """Markdown inline pattern processor for adding class attribute to inline-style hyperlinks.""" # NOQA: E501
71
+
72
+ def __init__(self, pattern, config):
73
+ """Initialize the Markdwon inline pattern processor."""
74
+ super().__init__(pattern)
75
+ # Store the configuration dict
76
+ self.config = config
77
+
78
+ def handleMatch(self, m, data):
79
+ """Add the class attribute to the generated <a> element."""
80
+ # Build the <a> element using the parent class
81
+ elm, start, end = super().handleMatch(m, data)
82
+ # Return the <a> element with added class
83
+ return add_class(elm, self.config), start, end
84
+
85
+
86
+ class ReferenceClass(ReferenceInlineProcessor):
87
+ """Markdown inline pattern processor for adding class attribute to inline-style references.""" # NOQA: E501
88
+
89
+ def __init__(self, pattern, config):
90
+ """Initialize the Markdwon inline pattern processor."""
91
+ super().__init__(pattern)
92
+ # Store the configuration dict
93
+ self.config = config
94
+
95
+ def handleMatch(self, m, data):
96
+ """Add the class attribute to the generated <a> element."""
97
+ # Build the <a> element using the parent class
98
+ elm, start, end = super().handleMatch(m, data)
99
+ # Return the <a> element with added class
100
+ return add_class(elm, self.config), start, end
101
+
102
+
103
+ def makeExtension(config=None):
104
+ """Register the MarkDown extension."""
105
+ return LinkClassExtension(config=config)
@@ -0,0 +1,212 @@
1
+ """Unit testing suite for the Link Class Plugin."""
2
+
3
+ # Copyright (C) 2015, 2017, 2019, 2021-2023 Rafael Laboissière <rafael@laboissiere.net> # noqa: E501
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify it
6
+ # under the terms of the GNU General Affero Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or (at
8
+ # your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful, but
11
+ # WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see http://www.gnu.org/licenses/.
17
+
18
+ # For running this test in a standalone-way, run:
19
+ # (cd .. ; python3 -Wd -m unittest discover)
20
+
21
+ from io import StringIO
22
+ import os
23
+ import re
24
+ from shutil import rmtree
25
+ import sys
26
+ from tempfile import mkdtemp
27
+ import unittest
28
+
29
+ from pelican import Pelican
30
+ from pelican.settings import read_settings
31
+
32
+ from . import linkclass
33
+
34
+ INTERNAL_CLASS = "internal"
35
+ EXTERNAL_CLASS = "external"
36
+
37
+ INTERNAL_INLINE_TEXT = "internal inline text"
38
+ INTERNAL_INLINE_LINK = "internal inline link"
39
+
40
+ INTERNAL_REFERENCE_TEXT = "internal reference text"
41
+ INTERNAL_REFERENCE_LABEL = "internal reference label"
42
+ INTERNAL_REFERENCE_LINK = "internal-reference-link"
43
+
44
+ EXTERNAL_INLINE_TEXT_HTTP = "external inline text http"
45
+ EXTERNAL_INLINE_LINK_HTTP = "https://inline.org"
46
+
47
+ EXTERNAL_REFERENCE_TEXT_HTTP = "external reference text http"
48
+ EXTERNAL_REFERENCE_LABEL_HTTP = "external reference label http"
49
+ EXTERNAL_REFERENCE_LINK_HTTP = "https://reference.org"
50
+
51
+ EXTERNAL_INLINE_TEXT_HTTPS = "external inline text https"
52
+ EXTERNAL_INLINE_LINK_HTTPS = "https://inline.org"
53
+
54
+ EXTERNAL_REFERENCE_TEXT_HTTPS = "external reference text https"
55
+ EXTERNAL_REFERENCE_LABEL_HTTPS = "external reference label https"
56
+ EXTERNAL_REFERENCE_LINK_HTTPS = "https://reference.org"
57
+
58
+ LINK_PATTERN = '<a class="{}" href="{}">{}</a>'
59
+
60
+ TEST_FILE_STEM = "test"
61
+ TEST_DIR_PREFIX = "pelicantests."
62
+
63
+
64
+ class TestLinkClass(unittest.TestCase):
65
+ """Class for testing the <a> output elements generated by the Link Class plugin."""
66
+
67
+ def setUp(self, override=None):
68
+ self.output_path = mkdtemp(prefix=TEST_DIR_PREFIX)
69
+ self.content_path = mkdtemp(prefix=TEST_DIR_PREFIX)
70
+ settings = {
71
+ "PATH": self.content_path,
72
+ "OUTPUT_PATH": self.output_path,
73
+ "PLUGINS": [linkclass],
74
+ "CACHE_CONTENT": False,
75
+ "SITEURL": "http://example.org",
76
+ "TIMEZONE": "UTC",
77
+ "LINKCLASS": (
78
+ ("INTERNAL_CLASS", INTERNAL_CLASS),
79
+ ("EXTERNAL_CLASS", EXTERNAL_CLASS),
80
+ ),
81
+ }
82
+ if override:
83
+ settings.update(override)
84
+
85
+ # Generate the test Markdown source file
86
+ with open(
87
+ os.path.join(self.content_path, f"{TEST_FILE_STEM}.md"),
88
+ "w",
89
+ ) as fid:
90
+ template = """Title: Test
91
+ Date: 1970-01-01
92
+
93
+ This is an [{}]({}), inline-style link.
94
+ This is an [{}]({}), inline-style link (with http URL).
95
+ This is an [{}]({}), inline-style link (with https URL).
96
+
97
+ This is an [{}][{}], reference-style link.
98
+ This is an [{}][{}], reference-style link (with http URL).
99
+ This is an [{}][{}], reference-style link (with https URL).
100
+
101
+ [{}]: {}
102
+ [{}]: {}
103
+ [{}]: {}
104
+
105
+ """
106
+ fid.write(
107
+ template.format(
108
+ INTERNAL_INLINE_TEXT,
109
+ INTERNAL_INLINE_LINK,
110
+ EXTERNAL_INLINE_TEXT_HTTP,
111
+ EXTERNAL_INLINE_LINK_HTTP,
112
+ EXTERNAL_INLINE_TEXT_HTTPS,
113
+ EXTERNAL_INLINE_LINK_HTTP,
114
+ INTERNAL_REFERENCE_TEXT,
115
+ INTERNAL_REFERENCE_LABEL,
116
+ EXTERNAL_REFERENCE_TEXT_HTTP,
117
+ EXTERNAL_REFERENCE_LABEL_HTTP,
118
+ EXTERNAL_REFERENCE_TEXT_HTTPS,
119
+ EXTERNAL_REFERENCE_LABEL_HTTPS,
120
+ INTERNAL_REFERENCE_LABEL,
121
+ INTERNAL_REFERENCE_LINK,
122
+ EXTERNAL_REFERENCE_LABEL_HTTP,
123
+ EXTERNAL_REFERENCE_LINK_HTTP,
124
+ EXTERNAL_REFERENCE_LABEL_HTTPS,
125
+ EXTERNAL_REFERENCE_LINK_HTTPS,
126
+ )
127
+ )
128
+
129
+ # Run the Pelican instance
130
+ self.settings = read_settings(override=settings)
131
+ pelican = Pelican(settings=self.settings)
132
+ saved_stdout = sys.stdout
133
+ sys.stdout = StringIO()
134
+ pelican.run()
135
+ sys.stdout = saved_stdout
136
+
137
+ def tearDown(self):
138
+ """Remove the temporary directories."""
139
+ rmtree(self.output_path)
140
+ rmtree(self.content_path)
141
+
142
+ def search(self, string):
143
+ """Search for a string in the article output."""
144
+ with open(
145
+ os.path.join(self.output_path, f"{TEST_FILE_STEM}.html"),
146
+ ) as fid:
147
+ found = False
148
+ for line in fid.readlines():
149
+ if re.search(string, line):
150
+ found = True
151
+ break
152
+ return found
153
+
154
+ def test_internal_inline(self):
155
+ """Test for the internal inline link."""
156
+ assert self.search(
157
+ LINK_PATTERN.format(
158
+ INTERNAL_CLASS,
159
+ INTERNAL_INLINE_LINK,
160
+ INTERNAL_INLINE_TEXT,
161
+ )
162
+ )
163
+
164
+ def test_external_inline_http(self):
165
+ """Test for the external http inline link."""
166
+ assert self.search(
167
+ LINK_PATTERN.format(
168
+ EXTERNAL_CLASS,
169
+ EXTERNAL_INLINE_LINK_HTTP,
170
+ EXTERNAL_INLINE_TEXT_HTTP,
171
+ )
172
+ )
173
+
174
+ def test_external_inline_https(self):
175
+ """Test for the external https inline link."""
176
+ assert self.search(
177
+ LINK_PATTERN.format(
178
+ EXTERNAL_CLASS,
179
+ EXTERNAL_INLINE_LINK_HTTPS,
180
+ EXTERNAL_INLINE_TEXT_HTTPS,
181
+ )
182
+ )
183
+
184
+ def test_internal_reference(self):
185
+ """Test for the internal reference link."""
186
+ assert self.search(
187
+ LINK_PATTERN.format(
188
+ INTERNAL_CLASS,
189
+ INTERNAL_REFERENCE_LINK,
190
+ INTERNAL_REFERENCE_TEXT,
191
+ )
192
+ )
193
+
194
+ def test_external_reference_http(self):
195
+ """Test for the external http reference link."""
196
+ assert self.search(
197
+ LINK_PATTERN.format(
198
+ EXTERNAL_CLASS,
199
+ EXTERNAL_REFERENCE_LINK_HTTP,
200
+ EXTERNAL_REFERENCE_TEXT_HTTPS,
201
+ )
202
+ )
203
+
204
+ def test_external_reference_https(self):
205
+ """Test for the external https reference link."""
206
+ assert self.search(
207
+ LINK_PATTERN.format(
208
+ EXTERNAL_CLASS,
209
+ EXTERNAL_REFERENCE_LINK_HTTPS,
210
+ EXTERNAL_REFERENCE_TEXT_HTTPS,
211
+ )
212
+ )
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pelican-linkclass"
3
- version = "2.1.3"
3
+ version = "2.1.4"
4
4
  description = "Pelican plugin to set anchor tag's class attribute to differentiate between internal and external links"
5
5
  authors = [
6
6
  { name = "Rafael Laboissière", email = "rafael@laboissiere.net" },
@@ -60,6 +60,20 @@ test = [
60
60
  "pytest-sugar>=0.9.7",
61
61
  ]
62
62
 
63
+ [tool.pdm.build]
64
+ source-includes = [
65
+ "CHANGELOG.md",
66
+ "CONTRIBUTING.md",
67
+ "external-link.png",
68
+ "linkclass-example.png",
69
+ ]
70
+ includes = [
71
+ "pelican/",
72
+ ]
73
+ excludes = [
74
+ "tasks.py",
75
+ ]
76
+
63
77
  [tool.autopub]
64
78
  project-name = "Link Class"
65
79
  git-username = "botpub"
@@ -1,99 +0,0 @@
1
- from inspect import cleandoc
2
- import logging
3
- import os
4
- from pathlib import Path
5
- from shutil import which
6
-
7
- from invoke import task
8
-
9
- logger = logging.getLogger(__name__)
10
-
11
- PKG_NAME = "linkclass"
12
- PKG_PATH = Path(f"pelican/plugins/{PKG_NAME}")
13
-
14
- ACTIVE_VENV = os.environ.get("VIRTUAL_ENV", None)
15
- VENV_HOME = Path(os.environ.get("WORKON_HOME", "~/.local/share/virtualenvs"))
16
- VENV_PATH = Path(ACTIVE_VENV) if ACTIVE_VENV else (VENV_HOME.expanduser() / PKG_NAME)
17
- VENV = str(VENV_PATH.expanduser())
18
- BIN_DIR = "bin" if os.name != "nt" else "Scripts"
19
- VENV_BIN = Path(VENV) / Path(BIN_DIR)
20
-
21
- TOOLS = ("pdm", "pre-commit")
22
- PDM = which("pdm") if which("pdm") else (VENV_BIN / "pdm")
23
- CMD_PREFIX = f"{VENV_BIN}/" if ACTIVE_VENV else f"{PDM} run "
24
- PRECOMMIT = which("pre-commit") if which("pre-commit") else f"{CMD_PREFIX}pre-commit"
25
- PTY = os.name != "nt"
26
-
27
-
28
- @task
29
- def tests(c, deprecations=False):
30
- """Run the test suite, optionally with `--deprecations`."""
31
- deprecations_flag = "" if deprecations else "-W ignore::DeprecationWarning"
32
- c.run(f"{CMD_PREFIX}pytest {deprecations_flag}", pty=PTY)
33
-
34
-
35
- @task
36
- def black(c, check=False, diff=False):
37
- """Run Black auto-formatter, optionally with `--check` or `--diff`."""
38
- check_flag, diff_flag = "", ""
39
- if check:
40
- check_flag = "--check"
41
- if diff:
42
- diff_flag = "--diff"
43
- c.run(f"{CMD_PREFIX}black {check_flag} {diff_flag} {PKG_PATH} tasks.py", pty=PTY)
44
-
45
-
46
- @task
47
- def ruff(c, fix=False, diff=False):
48
- """Run Ruff to ensure code meets project standards."""
49
- diff_flag, fix_flag = "", ""
50
- if fix:
51
- fix_flag = "--fix"
52
- if diff:
53
- diff_flag = "--diff"
54
- c.run(f"{CMD_PREFIX}ruff check {diff_flag} {fix_flag} .", pty=PTY)
55
-
56
-
57
- @task
58
- def lint(c, fix=False, diff=False):
59
- """Check code style via linting tools."""
60
- ruff(c, fix=fix, diff=diff)
61
- black(c, check=(not fix), diff=diff)
62
-
63
-
64
- @task
65
- def tools(c):
66
- """Install development tools in the virtual environment if not already on PATH."""
67
- for tool in TOOLS:
68
- if not which(tool):
69
- logger.info(f"** Installing {tool} **")
70
- c.run(f"{CMD_PREFIX}pip install {tool}")
71
-
72
-
73
- @task
74
- def precommit(c):
75
- """Install pre-commit hooks to .git/hooks/pre-commit."""
76
- logger.info("** Installing pre-commit hooks **")
77
- c.run(f"{PRECOMMIT} install")
78
-
79
-
80
- @task
81
- def setup(c):
82
- """Set up the development environment."""
83
- if which("pdm") or ACTIVE_VENV:
84
- tools(c)
85
- c.run(f"{CMD_PREFIX}python -m pip install --upgrade pip", pty=PTY)
86
- c.run(f"{PDM} update --dev", pty=PTY)
87
- precommit(c)
88
- logger.info("\nDevelopment environment should now be set up and ready!\n")
89
- else:
90
- error_message = """
91
- PDM is not installed, and there is no active virtual environment available.
92
- You can either manually create and activate a virtual environment, or you can
93
- install PDM via:
94
-
95
- curl -sSL https://raw.githubusercontent.com/pdm-project/pdm/main/install-pdm.py | python3 -
96
-
97
- Once you have taken one of the above two steps, run `invoke setup` again.
98
- """ # noqa: E501
99
- raise SystemExit(cleandoc(error_message))