File size: 1,976 Bytes
1be405f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# html_to_markdown/main.py
# Usage: python -m html_to_markdown.main input.html output.md --extract-main --refify-urls --include-meta extended --debug
# Arguments:
# input.html: Path to your input HTML file.
# output.md: Desired path for the output Markdown file.
# --extract-main: (Optional) Extracts the main content from the HTML.
# --refify-urls: (Optional) Refactors URLs to reference-style.
# --include-meta: (Optional) Includes metadata. Choose between basic or extended.
# --debug: (Optional) Enables debug logging for detailed trace.
from html_to_markdown import convert_html_to_markdown
from conversion_options import ConversionOptions
def main():
import argparse
parser = argparse.ArgumentParser(description="Convert HTML to Markdown.")
parser.add_argument('input_file', help="Path to the input HTML file.")
parser.add_argument('output_file', help="Path to the output Markdown file.")
parser.add_argument('--extract-main', action='store_true', help="Extract main content.")
parser.add_argument('--refify-urls', action='store_true', help="Refify URLs.")
parser.add_argument('--include-meta', choices=['basic', 'extended'], default=False, help="Include metadata.")
parser.add_argument('--debug', action='store_true', help="Enable debug logging.")
args = parser.parse_args()
with open(args.input_file, 'r', encoding='utf-8') as f:
html_content = f.read()
options = ConversionOptions(
extract_main_content=args.extract_main,
refify_urls=args.refify_urls,
include_meta_data=args.include_meta if args.include_meta else False,
debug=args.debug
)
markdown = convert_html_to_markdown(html_content, options)
with open(args.output_file, 'w', encoding='utf-8') as f:
f.write(markdown)
print(f"Conversion complete. Markdown saved to {args.output_file}")
if __name__ == "__main__":
main()
|