Skip to main content

Markdown URL utilities

Project description

mdurl

Build Status codecov.io PyPI version

TODO: Update the README below this point. Explain that this is a Python port etc.

URL utilities for markdown-it parser.

API

.encode(str [, exclude, keepEncoded]) -> String

Percent-encode a string, avoiding double encoding. Don't touch /a-zA-Z0-9/ + excluded chars + /%[a-fA-F0-9]{2}/ (if not disabled). Broken surrorates are replaced with U+FFFD.

Params:

  • str - input string.
  • exclude - optional, ;/?:@&=+$,-_.!~*'()#. Additional chars to keep intact (except /a-zA-Z0-9/).
  • keepEncoded - optional, true. By default it skips already encoded sequences (/%[a-fA-F0-9]{2}/). If set to false, % will be encoded.

encode.defaultChars, encode.componentChars

You can use these constants as second argument to encode function.

  • encode.defaultChars is the same exclude set as in the standard encodeURI() function
  • encode.componentChars is the same exclude set as in the encodeURIComponent() function

For example, encode('something', encode.componentChars, true) is roughly the equivalent of the encodeURIComponent() function (except encode() doesn't throw).

.decode(str [, exclude]) -> String

Decode percent-encoded string. Invalid percent-encoded sequences (e.g. %2G) are left as is. Invalid UTF-8 characters are replaced with U+FFFD.

Params:

  • str - input string.
  • exclude - set of characters to leave encoded, optional, ;/?:@&=+$,#.

decode.defaultChars, decode.componentChars

You can use these constants as second argument to decode function.

  • decode.defaultChars is the same exclude set as in the standard decodeURI() function
  • decode.componentChars is the same exclude set as in the decodeURIComponent() function

For example, decode('something', decode.defaultChars) has the same behavior as decodeURI('something') on a correctly encoded input.

.parse(url, slashesDenoteHost) -> urlObs

Parse url string. Similar to node's url.parse, but without any normalizations and query string parse.

  • url - input url (string)
  • slashesDenoteHost - if url starts with //, expect a hostname after it. Optional, false.

Result (hash):

  • protocol
  • slashes
  • auth
  • port
  • hostname
  • hash
  • search
  • pathname

Difference with node's url:

  1. No leading slash in paths, e.g. in url.parse('http://foo?bar') pathname is "" (empty string), not "/"
  2. Backslashes are not replaced with slashes, so http:\\example.org\ is treated like a relative path
  3. Trailing colon is treated like a part of the path, i.e. in http://example.org:foo pathname is :foo
  4. Nothing is URL-encoded in the resulting object, (in joyent/node some chars in auth and paths are encoded)
  5. url.parse() does not have parseQueryString argument
  6. Removed extraneous result properties: host, path, query, etc., which can be constructed using other parts of the url.

.format(urlObject)

Format an object previously obtained with .parse() function. Similar to node's url.format.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mdurl-0.1.0.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

mdurl-0.1.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file mdurl-0.1.0.tar.gz.

File metadata

  • Download URL: mdurl-0.1.0.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.7.11

File hashes

Hashes for mdurl-0.1.0.tar.gz
Algorithm Hash digest
SHA256 94873a969008ee48880fb21bad7de0349fef529f3be178969af5817239e9b990
MD5 148af8104f656a6fd70877505bc3fa2c
BLAKE2b-256 36c500f7f9e5b53dcf44f8806201e69016b64ade1075f38ab5d4e8f5ab4b5bfb

See more details on using hashes here.

File details

Details for the file mdurl-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mdurl-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.7.11

File hashes

Hashes for mdurl-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 40654d6dcb8d21501ed13c21cc0bd6fc42ff07ceb8be30029e5ae63ebc2ecfda
MD5 c214c142623a4fe00468cefd1d027290
BLAKE2b-256 ff9fcb94cab8c28f644360bdc96ab8813ec91d5de8090220c223fea350c2c0f0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page