This tool is a versatile Python script for converting Markdown files to HTML and vice versa. It supports various features like custom titles, CSS styling, batch conversion, interactive mode, Markdown extensions, and HTML template customization.
- Convert Markdown to HTML: Converts Markdown files to HTML format.
- Convert HTML to Markdown: Converts HTML files back to Markdown format.
- Custom Title for HTML: Allows specifying a custom title for the HTML document.
- Custom CSS Styling: Link a custom CSS stylesheet for the HTML output.
- Batch Conversion: Convert multiple files at once.
- Interactive Mode: Run the tool in an interactive CLI mode for ease of use.
- Markdown Extensions: Support for various markdown2 extensions.
- HTML Template Customization: Use a custom HTML template for the output.
-
Ensure Python is Installed: Ensure that you have Python installed on your machine. This script is compatible with Python 3.
-
Clone or download this repository Clone or download this repository to your local machine.
git clone https://your-repository-url cd path-to-your-repository
-
Install the required packages
pip install -r requirements.txt
The script can be used in the command line with various arguments to control its behavior.
- Convert a single Markdown file to HTML:
python converter.py input.md output.html --to_html
- Convert a single HTML file to Markdown:
python converter.py input.html output.md --to_md
- Batch Convert Markdown Files:
python converter.py "\*.md" output_directory/ --to_html
- Using a Custom Title and CSS File:
python converter.py input.md output.html --to_html --title "My Custom Title" --css "style.css"
- Enable Markdown Extensions:
python converter.py input.md output.html --to_html --extensions "tables,footnotes"
- Using an HTML Template File:
python converter.py input.md output.html --to_html --template "template.html"
- Interactive Mode:
python converter.py --interactive
When run in interactive mode, the script will prompt for inputs and options, making it easier for users who prefer not to use command line arguments.
-
Converting with Custom Title:
- Command:
python converter.py example.md example.html --to_html --title "Example Document"
- This will convert example.md to example.html with the title "Example Document".
- Command:
-
Batch Conversion:
- Command:
python converter.py "\*.md" converted_html/ --to_html
- This will convert all .md files in the current directory to .html files and save them in the converted_html directory.
- Command:
-
Using Custom CSS:
- Command:
python converter.py example.md example.html --to_html --css "mystyles.css"
- Converts example.md to example.html applying styles from mystyles.css.
- Command:
- When using a custom HTML template, ensure it contains {{content}} where you want the Markdown content to be injected.
- The batch conversion feature assumes the output path is a directory.
Contributions to this project are welcome. Feel free to fork the repository and submit pull requests.