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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cppmanlite
3
- Version: 0.1.1
3
+ Version: 0.1.6
4
4
  Summary: Lightweight serverless C++ documentation lookup — pure Python, no C deps
5
5
  License-Expression: MIT
6
6
  Project-URL: Homepage, https://dive4dec.github.io/cppmanlite/
@@ -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 id="mw-content-text"[^>]*>(.*?)(?:</div>\s*<!--|\Z)',
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 style="max-height:600px;overflow:auto;'
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
- + "</div>"
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")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cppmanlite
3
- Version: 0.1.1
3
+ Version: 0.1.6
4
4
  Summary: Lightweight serverless C++ documentation lookup — pure Python, no C deps
5
5
  License-Expression: MIT
6
6
  Project-URL: Homepage, https://dive4dec.github.io/cppmanlite/
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "cppmanlite"
7
- version = "0.1.1"
7
+ version = "0.1.6"
8
8
  description = "Lightweight serverless C++ documentation lookup — pure Python, no C deps"
9
9
  readme = "README.md"
10
10
  license = "MIT"
File without changes
File without changes
File without changes