{"id":19022915,"url":"https://github.com/chdsbd/markdown-html-finder","last_synced_at":"2025-04-23T08:29:02.890Z","repository":{"id":55699920,"uuid":"198078740","full_name":"chdsbd/markdown-html-finder","owner":"chdsbd","description":":microscope: An experiment with writing Python modules in Rust using pyo3 and pyo3-pack","archived":false,"fork":false,"pushed_at":"2022-06-30T15:57:03.000Z","size":60,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-14T18:21:37.768Z","etag":null,"topics":["pyo3","python","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chdsbd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-21T16:17:46.000Z","updated_at":"2021-09-22T02:58:19.000Z","dependencies_parsed_at":"2022-08-15T06:30:50.550Z","dependency_job_id":null,"html_url":"https://github.com/chdsbd/markdown-html-finder","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chdsbd%2Fmarkdown-html-finder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chdsbd%2Fmarkdown-html-finder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chdsbd%2Fmarkdown-html-finder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chdsbd%2Fmarkdown-html-finder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chdsbd","download_url":"https://codeload.github.com/chdsbd/markdown-html-finder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250398726,"owners_count":21424045,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pyo3","python","rust"],"created_at":"2024-11-08T20:28:07.537Z","updated_at":"2025-04-23T08:29:02.871Z","avatar_url":"https://github.com/chdsbd.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# markdown-html-finder [![PyPI](https://img.shields.io/pypi/v/markdown-html-finder.svg)](https://pypi.org/project/markdown-html-finder/)\n\nA Python library to locate HTML spans in markdown text. This library is written in Rust with bindings for Python.\n\n## why?\nFor a [separate project](https://github.com/chdsbd/kodiak) I needed to locate HTML comments in markdown documents. Sadly the markdown parsers I found for Python didn't provide span information for nodes.\n\nWhile 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](https://github.com/raphlinus/pulldown-cmark) crate provides span information for HTML elements, so that's what we use here.\n\n[pyo3](https://github.com/PyO3/pyo3) and [maturin](https://github.com/PyO3/maturin) do the hard work of providing bindings to Python and building wheels to distribute on PyPi.\n\n## install\n\n```bash\n# poetry\npoetry add markdown-html-finder\n\n# pip\npip install markdown-html-finder\n```\n\n## usage\n\n```python\nfrom markdown_html_finder import find_html_positions\n\nDOCUMENT = \"\"\"\\\n# example markdown document\n\nAmet nobis et numquam qui. Animi perferendis quia qui ut aut expedita. Ut eveniet quia quaerat.\n\u003c!-- hello world --\u003e\nQuisquam et et velit soluta quia.\n\"\"\"\n\n# NOTE: find_html_positions raises a ValueError if passed carriage returns `\\r`\nstripped_document = DOCUMENT.replace('\\r', '')\nhtml_positions = find_html_positions(stripped_document)\nassert html_positions == [(125, 145)]\n```\n\n## dev\n```bash\n# install build dependencies\npoetry install\n\n# build for python development\npoetry run maturin development\n```\n\n### building wheels\nWe need a wheel per version and platform. To support Python 3.7, 3.8, 3.9 we need to have 3.7, 3.8, 3.9 installed on macOS and Linux. For macOS we can use pyenv. For Linux we can use a Docker container.\n\n#### macos\n1. install pyenv\n2. install each python version we want to support via `pyenv install`. Use `pyenv install --list` to see the available options.\n3. add your new Python installs globally via `pyenv global 3.8.7 3.9.0`\n4. configure your $PATH with the .pyenv python versions. use `pyenv shims` to find the binary paths and add them, like `PATH=/Users/chris/.pyenv/shims/:$PATH`\n5. verify your Python versions are accessible via `python3.9` and verify maturin can find your python versions via `./.venv/bin/maturin list-python`\n6. build the macOS wheels via `./.venv/bin/maturin build`\n7. upload wheels to pypi via `./.venv/bin/twine upload --skip-existing target/wheels/*`\n\n#### linux\n1. use the docker container to build all the Linux Python wheels via `docker run --rm -v $(pwd):/io cdignam/markdown-html-finder-builder:0.3.0 build --release`\n2. upload wheels to pypi via `./.venv/bin/twine upload --skip-existing target/wheels/*`\n\n\n### markdown-html-finder-builder\nThis container extends the [quay.io/pypa/manylinux2014_x86_64](https://quay.io/pypa/manylinux2014_x86_64) docker image and is based on the [konstin2/maturin](https://hub.docker.com/r/konstin2/maturin) image, with Python2 support removed.\n\nThis image is built and uploaded manually to Docker Hub when necessary.\n\n```bash\n# build and publish a new version\nVERSION='0.2.0'\ndocker build -f build.Dockerfile . --tag cdignam/markdown-html-finder-builder:$VERSION\ndocker push cdignam/markdown-html-finder-builder:$VERSION\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchdsbd%2Fmarkdown-html-finder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchdsbd%2Fmarkdown-html-finder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchdsbd%2Fmarkdown-html-finder/lists"}