Skip to content

Commit bb06559

Browse files
authored
Wrap and shorten long URLs (#78)
1 parent a7577a3 commit bb06559

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/assets/styles/global.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,8 @@ body {
14951495
color: #1a5276;
14961496
background-color: rgba(30, 100, 160, 0.08);
14971497
border-color: rgba(30, 100, 160, 0.2);
1498+
overflow-wrap: anywhere;
1499+
white-space: normal;
14981500
}
14991501

15001502
.prose .ref-py-release:hover {

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)