Skip to content

Commit 198c437

Browse files
committed
Strip http[s]://[www/] from plain URLs
1 parent 1147893 commit 198c437

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/plugins/remark-python-refs.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,17 @@ export default function remarkPythonRefs() {
284284
visit(tree, "link", (node: Link, index, parent) => {
285285
if (index == null || !parent) return;
286286

287-
const label = extractText(node.children);
288-
const info = classify(node.url, label);
287+
const rawLabel = extractText(node.children);
288+
const info = classify(node.url, rawLabel);
289289
if (!info) return;
290290

291+
// For autolinked bare URLs, drop the protocol, leading "www.",
292+
// and trailing slash so the badge reads "python.org/downloads/..."
293+
// rather than the full "https://www.python.org/.../" form.
294+
const label = rawLabel.startsWith("http")
295+
? rawLabel.replace(/^https?:\/\/(?:www\.)?/i, "").replace(/\/$/, "")
296+
: rawLabel;
297+
291298
collectRef(info.type, label, node.url);
292299
const html = buildBadgeHtml({ ...info, label, url: node.url });
293300

0 commit comments

Comments
 (0)