contaix.urls¶
Work with urls
Functions
|
Download PDF articles from markdown text. |
|
Download articles by markdown section. |
|
Extract URLs from HTML anchor tags. |
|
Extract markdown links from a string. |
|
Extract URLs and their context from a markdown string. |
|
Extract URLs with empty context. |
|
Extract URLs with surrounding text as context. |
|
|
|
Remove unwanted hyperlinks and citations from a string. |
|
Verifies URLs in a markdown string by checking their status codes. |
- contaix.urls.download_articles(md_string=None, save_dir='/home/runner/Downloads', *, save_non_pdf=False, verbose=True)[source]¶
Download PDF articles from markdown text. Wrapper around
pdfdol.download.If
md_stringis None, reads from clipboard (requires pyperclip). Seepdfdol.download.download_articlesfor full documentation.
- contaix.urls.download_articles_by_section(md_string=None, rootdir=None, save_non_pdf=False, *, section_marker='###')[source]¶
Download articles by markdown section. Wrapper around
pdfdol.download.If
md_stringis None, reads from clipboard (requires pyperclip). Seepdfdol.download.download_articles_by_sectionfor full documentation.
- contaix.urls.extract_markdown_links(markdown=None, pattern=None)[source]¶
Extract markdown links from a string.
Note
By default this also extracts bare
http(s)://...URLs found in the text. For those, the returned context/name is the URL itself.- Parameters:
- Return type:
- Returns:
Iterator of (context, url) pairs
>>> text = "[Google](https://google.com) and https://github.com" >>> list(extract_markdown_links(text)) [('Google', 'https://google.com'), ('https://github.com', 'https://github.com')]
- contaix.urls.extract_urls(markdown=None, pattern=None, extractor=None)[source]¶
Extract URLs and their context from a markdown string.
- Parameters:
pattern (
Pattern|None) – A compiled regex pattern to match URLs and their context. Defaults to matching both markdown hyperlinks[context](url)and barehttp(s)://...URLs.extractor (
Callable[[Match],tuple[str,str]] |None) –A function that extracts
(context, url)from a match. Defaults to:(context, url)for markdown hyperlinks(url, url)for bare URLs
- Return type:
- Returns:
Iterator of (context, url) pairs
>>> text = "[Google](https://google.com) and https://github.com" >>> list(extract_urls(text)) [('Google', 'https://google.com'), ('https://github.com', 'https://github.com')]
- contaix.urls.extract_urls_only(markdown=None)[source]¶
Extract URLs with empty context.
- Parameters:
- Return type:
- Returns:
Iterator of tuples with empty string and extracted URLs
>>> list(extract_urls_only("Check [this link](https://example.com) and https://github.com/user/repo)")) [('', 'https://example.com'), ('', 'https://github.com/user/repo')]
- contaix.urls.extract_with_surrounding_context(markdown=None, context_chars=30)[source]¶
Extract URLs with surrounding text as context.
- Parameters:
- Return type:
- Returns:
Iterator of (context, url) pairs
>>> text = "Check this link: [Google](https://google.com) and [GitHub](https://github.com)" >>> list(extract_with_surrounding_context(text, context_chars=5)) [('gle](https://google.com) and', 'https://google.com)'), ('Hub](https://github.com)', 'https://github.com)')]
- contaix.urls.remove_hyperlink_crap(string=None, copy_to_clipboard=True)[source]¶
Remove unwanted hyperlinks and citations from a string.
Typically used to clean up text copied from ChatGPT or Claude. Delegates to
dn.repair.remove_hyperlink_crapfor the pure transform, adding clipboard integration on top.If no string is specified, reads from clipboard (requires pyperclip).
- contaix.urls.verify_urls(src=None)[source]¶
Verifies URLs in a markdown string by checking their status codes.
- Parameters:
src (
str|list|None) – The markdown string or list containing URLs. If a string starting with[, parsed as a JSON list of URLs. Otherwise, URLs are extracted from the markdown text.- Returns:
A dictionary with URLs as keys and their status codes as values.
- Return type:
>>> verify_urls(['https://example.com']) {'https://example.com': 200}