forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB2d82fddIvan Molodetskikh1 year ago2536 commits

shortcodes.py44 lines, 2.0 KiBHistoryRawDownload
1# Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
2
3# Permission is hereby granted, free of charge, to any person obtaining a copy
4# of this software and associated documentation files (the "Software"), to
5# deal in the Software without restriction, including without limitation the
6# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7# sell copies of the Software, and to permit persons to whom the Software is
8# furnished to do so, subject to the following conditions:
9
10# The above copyright notice and this permission notice shall be included in
11# all copies or substantial portions of the Software.
12
13# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
16# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19# IN THE SOFTWARE.
20
21from __future__ import annotations
22import re
23from re import Match
24
25def on_page_markdown(
26 markdown: str, *, page, config, files
27):
28 def replace(match: Match):
29 matches = match.groups()
30 preposition, version = matches[0], matches[1]
31 return _badge_for_version(preposition, version)
32
33 return re.sub(
34 r"<sup>(Until|Since): (.*?)</sup>",
35 replace, markdown, flags = re.I | re.M
36 )
37
38def _badge_for_version(preposition: str, version: str):
39 if version == "next release":
40 # we might fail to make real links to release notes on other cases too, but for now this is the one i've found
41 return f"<span class=\"badge\">{preposition}: {version}</span>"
42 else:
43 path = f"https://github.com/YaLTeR/niri/releases/tag/v{version}"
44 return f"<span class=\"badge\">[{preposition}: {version}]({path})</span>"