mdurl
mdurl is a Python port of the JavaScript mdurl package, providing utilities for parsing, encoding, and decoding URLs in Markdown. The latest version is 0.1.2, released on August 14, 2022. The project has a stable release history with no recent updates.
Common errors
-
ModuleNotFoundError: No module named 'mdurl'
cause The 'mdurl' package is not installed in the Python environment where the code is being run.fixInstall the package using pip: `pip install mdurl` -
AttributeError: module 'mdurl' has no attribute 'quote'
cause The user is attempting to call a function that does not exist in the `mdurl` library, possibly confusing its API with other URL parsing libraries like `urllib.parse` or the original JavaScript `mdurl`.fixRefer to the `mdurl` documentation. The primary encoding function is `mdurl.encode()` and the decoding function is `mdurl.decode()`. -
TypeError: argument 's' must be str, not int
cause The `mdurl.encode()` or `mdurl.decode()` function received an argument that is not a string, but an integer (or another non-string type) instead.fixEnsure that the input provided to `mdurl.encode()` or `mdurl.decode()` is a string. -
ValueError: Malformed URL scheme
cause While `mdurl.parse()` is designed to be lenient, if the input URL string is severely malformed, particularly regarding its scheme or structure (e.g., `https:/example.com` instead of `https://example.com`), it can lead to unexpected parsing results or a `ValueError` if subsequent operations on the parsed object assume a valid structure.fixValidate and ensure that the URL string passed to `mdurl.parse()` or other functions has a reasonably well-formed structure, including the correct scheme (e.g., `http://`, `https://`).
Warnings
- gotcha mdurl functions do not perform URL normalization; ensure input URLs are properly formatted.
- gotcha Invalid percent-encoded sequences are left as-is during decoding.
Install
-
pip install mdurl
Imports
- encode
import mdurl.encode
from mdurl import encode
- decode
import mdurl.decode
from mdurl import decode
- parse
import mdurl.parse
from mdurl import parse
- format
import mdurl.format
from mdurl import format
Quickstart
from mdurl import encode, decode, parse, format
# Encode a URL
encoded_url = encode('https://example.com/path?query=param')
print(f'Encoded URL: {encoded_url}')
# Decode a URL
decoded_url = decode(encoded_url)
print(f'Decoded URL: {decoded_url}')
# Parse a URL
parsed_url = parse('https://example.com/path?query=param')
print(f'Parsed URL: {parsed_url}')
# Format a parsed URL
formatted_url = format(parsed_url)
print(f'Formatted URL: {formatted_url}')