cppmanlite 0.1.1__tar.gz → 0.1.6__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.
- {cppmanlite-0.1.1 → cppmanlite-0.1.6}/PKG-INFO +1 -1
- {cppmanlite-0.1.1 → cppmanlite-0.1.6}/cppmanlite/core.py +58 -6
- {cppmanlite-0.1.1 → cppmanlite-0.1.6}/cppmanlite.egg-info/PKG-INFO +1 -1
- {cppmanlite-0.1.1 → cppmanlite-0.1.6}/pyproject.toml +1 -1
- {cppmanlite-0.1.1 → cppmanlite-0.1.6}/LICENSE +0 -0
- {cppmanlite-0.1.1 → cppmanlite-0.1.6}/README.md +0 -0
- {cppmanlite-0.1.1 → cppmanlite-0.1.6}/cppmanlite/__init__.py +0 -0
- {cppmanlite-0.1.1 → cppmanlite-0.1.6}/cppmanlite/data/index.json +0 -0
- {cppmanlite-0.1.1 → cppmanlite-0.1.6}/cppmanlite.egg-info/SOURCES.txt +0 -0
- {cppmanlite-0.1.1 → cppmanlite-0.1.6}/cppmanlite.egg-info/dependency_links.txt +0 -0
- {cppmanlite-0.1.1 → cppmanlite-0.1.6}/cppmanlite.egg-info/requires.txt +0 -0
- {cppmanlite-0.1.1 → cppmanlite-0.1.6}/cppmanlite.egg-info/top_level.txt +0 -0
- {cppmanlite-0.1.1 → cppmanlite-0.1.6}/setup.cfg +0 -0
|
@@ -150,7 +150,7 @@ def list_pages(limit: int = 0) -> list[dict[str, str]]:
|
|
|
150
150
|
# --------------------------------------------------------------------------- #
|
|
151
151
|
|
|
152
152
|
_CONTENT_RE = re.compile(
|
|
153
|
-
r'<div
|
|
153
|
+
r'<div class="mw-content-ltr mw-parser-output"[^>]*>(.*?)(?:</div>\s*<!--|\Z)',
|
|
154
154
|
re.DOTALL,
|
|
155
155
|
)
|
|
156
156
|
_SCRIPT_RE = re.compile(r"<script[^>]*>.*?</script>", re.DOTALL)
|
|
@@ -349,12 +349,64 @@ def _format_search_html(results: list[dict[str, str]]) -> str:
|
|
|
349
349
|
)
|
|
350
350
|
|
|
351
351
|
|
|
352
|
-
def _format_page_html(content: str) -> str:
|
|
352
|
+
def _format_page_html(content: str, page_url: str = "") -> str:
|
|
353
|
+
"""Format page content for Jupyter display with working links.
|
|
354
|
+
|
|
355
|
+
In a **trusted** notebook, Jupyter renders external https:// links
|
|
356
|
+
with target=\"_blank\" — clicking opens cppreference.com in a new tab.
|
|
357
|
+
In an untrusted notebook, the sanitizer strips external hrefs to '#'.
|
|
358
|
+
|
|
359
|
+
Links:
|
|
360
|
+
- Navigation links → absolute https://en.cppreference.com/w/... + target=\"_blank\"
|
|
361
|
+
- Edit links (<a href=\".../index.php?...action=edit\">) → unwrapped (text kept, <a> removed)
|
|
362
|
+
- Anchor links (href=\"#...\") → left as-is (in-page navigation)
|
|
363
|
+
"""
|
|
364
|
+
from urllib.parse import urljoin
|
|
365
|
+
|
|
366
|
+
base_href = (
|
|
367
|
+
f"https://en.cppreference.com/w/{page_url}" if page_url
|
|
368
|
+
else "https://en.cppreference.com/w/"
|
|
369
|
+
)
|
|
370
|
+
|
|
371
|
+
# 1. Remove edit links entirely: <a ... href=".../index.php?...action=edit...">text</a> → text
|
|
372
|
+
content = re.sub(
|
|
373
|
+
r'<a [^>]*href="[^"]*index\.php[^"]*action=edit[^"]*"[^>]*>(.*?)</a>',
|
|
374
|
+
r'\1',
|
|
375
|
+
content,
|
|
376
|
+
flags=re.DOTALL,
|
|
377
|
+
)
|
|
378
|
+
|
|
379
|
+
# 2. Rewrite remaining hrefs
|
|
380
|
+
def _rewrite_href(m: re.Match) -> str:
|
|
381
|
+
href = m.group(1)
|
|
382
|
+
|
|
383
|
+
# Skip javascript: URLs — neutralize
|
|
384
|
+
if href.startswith("javascript:"):
|
|
385
|
+
return 'href="#" onclick="return false"'
|
|
386
|
+
|
|
387
|
+
# Skip anchors (in-page navigation) — keep as-is
|
|
388
|
+
if href.startswith("#"):
|
|
389
|
+
return f'href="{href}"'
|
|
390
|
+
|
|
391
|
+
# Resolve to absolute URL if needed
|
|
392
|
+
if not href.startswith("http://") and not href.startswith("https://"):
|
|
393
|
+
href = urljoin(base_href, href)
|
|
394
|
+
|
|
395
|
+
return f'href="{html.escape(href)}" target="_blank" rel="noopener"'
|
|
396
|
+
|
|
397
|
+
content = re.sub(r'href="([^"]*)"', _rewrite_href, content)
|
|
398
|
+
|
|
353
399
|
return (
|
|
354
|
-
'<div
|
|
400
|
+
'<div class="cppmanlite-content" '
|
|
401
|
+
'style="max-height:600px;overflow:auto;'
|
|
355
402
|
'border:1px solid #ddd;padding:16px;font-size:14px">'
|
|
356
403
|
+ content
|
|
357
|
-
+
|
|
404
|
+
+ '</div>'
|
|
405
|
+
+ '<p style="font-size:11px;color:#888;margin-top:4px">'
|
|
406
|
+
+ 'Links open cppreference.com in a new tab. '
|
|
407
|
+
+ 'If links don\'t work, trust this notebook: '
|
|
408
|
+
+ '<b>File → Trust Notebook</b>'
|
|
409
|
+
+ '</p>'
|
|
358
410
|
)
|
|
359
411
|
|
|
360
412
|
|
|
@@ -395,7 +447,7 @@ def _man_sync(query: str) -> None:
|
|
|
395
447
|
if _is_jupyter():
|
|
396
448
|
from IPython.display import HTML, display
|
|
397
449
|
|
|
398
|
-
display(HTML(_format_page_html(content)))
|
|
450
|
+
display(HTML(_format_page_html(content, page_url=url)))
|
|
399
451
|
else:
|
|
400
452
|
# Terminal: print formatted text
|
|
401
453
|
print(f"\n{'=' * 80}\n{title}\n{'=' * 80}\n")
|
|
@@ -414,7 +466,7 @@ async def _man_async(query: str) -> None:
|
|
|
414
466
|
if _is_jupyter():
|
|
415
467
|
from IPython.display import HTML, display
|
|
416
468
|
|
|
417
|
-
display(HTML(_format_page_html(content)))
|
|
469
|
+
display(HTML(_format_page_html(content, page_url=url)))
|
|
418
470
|
else:
|
|
419
471
|
# Pyodide console / terminal
|
|
420
472
|
print(f"\n{'=' * 80}\n{title}\n{'=' * 80}\n")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|