A Python library to find html in strings
Project description
markdown-html-finder
A Python library to locate HTML spans in markdown text. This library is written in Rust with bindings for Python.
why?
For a separate project I needed to locate HTML comments in markdown documents. Sadly the markdown parsers I found for Python didn't provide span information for nodes.
While it wouldn't be too hard to add some features to existing Python markdown parsers, I thought it would be interesting to see how Rust can be used from Python. The excellent pulldown-cmark crate provides span information for HTML elements, so that's what we use here.
pyo3 and pyo3-pack do the hard work of providing bindings to Python and building wheels to distribute on PyPi.
install
# poetry
poetry add markdown-html-finder
# pip
pip install markdown-html-finder
usage
from markdown_html_finder import find_html_positions
DOCUMENT = """\
# example markdown document
Amet nobis et numquam qui. Animi perferendis quia qui ut aut expedita. Ut eveniet quia quaerat.
<!-- hello world -->
Quisquam et et velit soluta quia.
"""
# NOTE: find_html_positions raises a ValueError if passed carriage returns `\r`
stripped_document = DOCUMENT.replace('\r', '')
html_positions = find_html_positions(stripped_document)
assert html_positions == [(125, 145)]
dev
# install build dependencies
poetry install
# build for python development
poetry run pyo3-pack development
# build and publish
./s/build
markdown-html-finder-builder
This container extends the quay.io/pypa/manylinux2010_x86_64 docker image and is based on the konstin2/pyo3-pack image, with Python2 support removed.
This image is built and uploaded manually to Docker Hub when necessary.
# build and publish a new version
VERSION='0.2.0'
docker build -f build.Dockerfile . --tag cdignam/markdown-html-finder-builder:$VERSION
docker push cdignam/markdown-html-finder-builder:$VERSION
production build
Update the version in Cargo.toml and run the following commands to build and upload linux wheels.
VERSION='0.2.0'
# build manylinux wheels
docker run --rm -v $(pwd):/io cdignam/markdown-html-finder-builder:$VERSION build --release
# build macos wheel (only builds for installed Python version)
pyo3-pack build --release
# upload built wheels to pypi
twine upload target/wheels/* --skip-existing
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for markdown_html_finder-0.2.2-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e26286c6b9e97a5e231e1dc5078bf314da5f9e6265f35f37cf4188550456cc37 |
|
MD5 | 8670da92c1916af9647228b82da11a22 |
|
BLAKE2b-256 | a16ba966c0280dbe769bb0bcb3103deb3c8cf60d4628a8f87c006deff04a05bb |
Hashes for markdown_html_finder-0.2.2-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 030c8c46a735a0f4b8c9b4d214bf5c8f7377b8eaa9140f3d7654e2a8d0d89426 |
|
MD5 | 4e0a378887028697366d80fe135daf60 |
|
BLAKE2b-256 | 9ac689f6f61935fe06f84e20ecffdb9e511c58ddfbb1dc68f83620f1c5f63f7c |
Hashes for markdown_html_finder-0.2.2-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83121a98833dcbdf2ece019ac259f64989520723f6ec1063bcfa1e2db409d1f7 |
|
MD5 | 75292aaa2581c933c28c2adb7417a982 |
|
BLAKE2b-256 | 3b9c13e336a568652d851c739c457c5d6d9d30abf237203c416eb0ce32e5e08d |
Hashes for markdown_html_finder-0.2.2-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bd9abf7cd26e142c3985a22b02047ad8eed75c21e64e2bf83f21adce27624aa |
|
MD5 | ce346fedca1ca701c3b45ceaad9e12fe |
|
BLAKE2b-256 | 1e10f46c01f8e4073dae9d0fd971fc11780fe1302989110128748863ab5e5a99 |
Hashes for markdown_html_finder-0.2.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4cf8a8b274354835831391d61d30e12b5202ec4c0c8a97fe4af7465cd64d4d97 |
|
MD5 | b162141339bab68ea0f36cbdc5db3697 |
|
BLAKE2b-256 | 28b63eeead04e4e45b3833b8b08af0f50550252e501be97e182af6f533512ee3 |
Hashes for markdown_html_finder-0.2.2-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a850edeb28054be12253b9b91e31e810fe1f4977113b75853f64be848238258c |
|
MD5 | 8a85406d84f47d0b990de1d9e10f933a |
|
BLAKE2b-256 | 66df51311c6f72fda3503d0fd16cc6fed642c7b665ca5b34bc6e7fac6c15b502 |
Hashes for markdown_html_finder-0.2.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84afd5ea416f9a7d04c74324af210e8475f51f69c89a25f6821cdc754ecc25cd |
|
MD5 | 08a859bd550b8d25b06f3889c90be4be |
|
BLAKE2b-256 | c07fc34e26083e0952a7f5afa8b6f56f271f731641421d5401cdf34ff00b00f7 |
Hashes for markdown_html_finder-0.2.2-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4c294e6dbbb3125411fbef8211a67322316df1bcbfa339d70127da503fbdb42 |
|
MD5 | 358c6a3be7dcdaf157b660b0314a08eb |
|
BLAKE2b-256 | 2c2640ba389d5823d31e849b2f713275c0a1aefdf26ac73732f7f509aca5825f |