HTML to Markdown converter.
HTML to Markdown converter
pip install -U html2md
As a command line tool:
# To convert a file. html2md examples/hello.html # To convert from stdin. cat examples/hello.html | html2md
From a Python script:
import html2md html = ''' <h1>Header</h1> <b><i>Hello</i></b> from <code>html2md</code> <pre class="py"><code> print('Hello') </code></pre> ''' md = html2md.convert(html) print(md)
Clone the repository
First, fork the project.
# Clone your fork into your local machine. # This will create the `origin` remote pointing to your fork. git clone email@example.com:<your-username>/html2md.git cd html2md # Add an `upstream` remote pointing to the original repository. git remote add upstream firstname.lastname@example.org:davidcavazos/html2md.git
Setting up your environment
Make sure you have
pip install -U virtualenv
Create and activate a new
python -m virtualenv env source env/bin/activate
Note: Once you are all done, you can deactivate it by running
Install the requirements.
pip install -U -r requirements.txt
Modifying the code
First, make sure you're on the latest version.
git checkout master git pull upstream master
Now, create a new branch for your changes. Try to use a short and descriptive name for your changes.
# Create a new branch and change to it. git checkout -b your-branch
You can now modify whatever you want.
Make sure you add tests for any new functionality or fix you do.
If it's in a new file, append the
*_test.py prefix to the file.
# To run all the tests. python setup.py test # To run a specific test suite. # python setup.py test -s <package>.<test_file>.<TestSuite> python setup.py test -s html2md.convert_test.ConvertTest # To run a specific test. # python setup.py test -s <package>.<test_file>.<TestSuite>.<test_name> python setup.py test -s html2md.convert_test.ConvertTest.test_code_block
Creating a Pull Request
After all the tests pass, you'll have to create a "Pull Request" with your changes. You can create a single commit with all the changes.
Note: You can check your changes with
# Create a commit and push it to your fork's branch. git add . git commit -m 'One line description of your changes' git push origin your-branch
Then you can follow the link in your terminal, or navigate to html2md, to create a "Pull Request".
If you need to add further modifications, you'll have to:git add . git commit -m 'One line description of further changes' git push origin your-branch
Afterwards, it will reflect automatically on the Pull Request.
Once everything is okay, it can be merged.
Publishing a new version
Make sure you have some more tools installed.
pip install -U twine
Generate the distribution archives.
# Make sure there are no previous builds. rm -rf dist/ # Build the distribution package. python setup.py sdist bdist_wheel # Check any problems with the README. twine check dist/*
Note: It is highly recommended to publish to
TestPyPIbefore publishing to
PyPI.# To upload to TestPyI. twine upload --repository-url https://test.pypi.org/legacy/ dist/* # To install from TestPyPI. pip install --index-url https://test.pypi.org/simple/ --no-deps html2md
If everything is working correctly, go ahead and publish to
To upload to
twine upload dist/*
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.