Skip to main content

A Python library to find html in strings

Project description

markdown-html-finder PyPI

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

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

markdown_html_finder-0.2.2-cp39-cp39-macosx_10_7_x86_64.whl (548.2 kB view hashes)

Uploaded CPython 3.9 macOS 10.7+ x86-64

markdown_html_finder-0.2.2-cp38-cp38-macosx_10_7_x86_64.whl (548.2 kB view hashes)

Uploaded CPython 3.8 macOS 10.7+ x86-64

markdown_html_finder-0.2.2-cp37-cp37m-macosx_10_7_x86_64.whl (546.9 kB view hashes)

Uploaded CPython 3.7m macOS 10.7+ x86-64

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