d2m
v1.5.0
Published
Convert DOM to Semantic Markdown
Downloads
211
Readme
DOM to Markdown CLI
A command-line tool to convert HTML DOM to Semantic Markdown.
Installation
To use the CLI tool with npx or install it globally, follow these instructions:
Using npx
You can use the tool directly with npx without needing to install it globally:
npx d2m@latest -i tryme.html -o output.mdGlobal Installation
To install the CLI tool globally, use the following commands:
- Clone the repository:
git clone https://github.com/romansky/dom-to-semantic-markdown.git
cd examples/cli- Install dependencies:
npm install- Build the project:
npm run build- Link the package globally:
npm linkAfter linking the package globally, you can use the d2m command anywhere on your system.
Usage
The d2m command converts HTML files or URL content to Markdown. Here are the available options:
-i, --input <file>: Input HTML file-o, --output <file>: Output Markdown file (if not specified, the result will be printed to the console)-e, --extract-main: Extract main content (optional)-u, --url <url>: URL to fetch HTML content from-t, --track-table-columns: Enable table column tracking for improved LLM data correlation-m, --include-meta-data <"basic" | "extended">: Include metadata extracted from the HTML head-p, --use-playwright: Use Playwright to fetch HTML from URL (handles dynamic content, may requirenpx playwright installif browsers are not found)--playwright-wait-until <event>: Specify the Playwrightpage.gotowaitUntil event. Options:load(default),domcontentloaded,networkidle,commit. Used only with-por--use-playwright.
Explanation of waitUntil options:
'domcontentloaded': Waits for theDOMContentLoadedevent. The HTML document has been completely parsed, but stylesheets, images, and subframes may still be loading.'load': Waits for theloadevent. The entire page, including all dependent resources like stylesheets and images, has finished loading. This is the new default if-pis used.'networkidle': Waits until there are no network connections for at least 500 ms. This is excellent for pages that load data asynchronously or SPAs that render content after the initial load.'commit': Waits for the navigation to be committed. This is the fastest but might capture the page in a very early state, often before any meaningful content is rendered by JavaScript.
Note: If you plan to use the --use-playwright option (see Usage), you might need to install Playwright's browser drivers first:
npx playwright installExamples
Using npx
(without local install use npx d2m@latest -i ... or d2m -i ... if globally installed, ie- npm link )
- Convert an HTML file and print the result to the console:
npx d2m@latest -i tryme.html- Convert an HTML file and save the result to a Markdown file:
npx d2m@latest -i tryme.html -o output.md- Extract the main content from the HTML file and print the result to the console:
npx d2m@latest -i tryme.html -e- Convert HTML content from a URL and print the result to the console:
npx d2m@latest -u https://example.com- Convert HTML content from a URL and save the result to a Markdown file:
npx d2m@latest -u https://example.com -o output.md- Convert an HTML file with table column tracking:
npx d2m@latest -i tryme.html -t- Convert HTML content from a URL using Playwright and save to a file:
npx d2m@latest -u https://example.com -p -o output_playwright.md- Convert HTML content from a URL using Playwright while waiting until network has settled
npx d2m@latest -u https://example.com -p --playwright-wait-until networkidle -o output_spa.mdLicense
This project is licensed under the MIT License. See the LICENSE file for details.
