GithubHelp home page GithubHelp logo

jaywcjlove / html-to-markdown-cli Goto Github PK

View Code? Open in Web Editor NEW
70.0 4.0 6.0 242 KB

Command line tool that converts HTML to markdown.

Home Page: https://jaywcjlove.github.io/html-to-markdown-cli

License: MIT License

JavaScript 51.67% TypeScript 45.96% HTML 2.37%
htmltomarkdown markdown

html-to-markdown-cli's Introduction

@wcj/html-to-markdown

Buy me a coffee CI NPM @wcj/html-to-markdown version NPM @wcj/html-to-markdown-cli version

HTML conversion tool to markdown. Command line tool => @wcj/html-to-markdown-cli.

Installation

This package is ESM only: Node 14+ is needed to use it and it must be import instead of require.

npm i @wcj/html-to-markdown

Command line tool

$ npx @wcj/html-to-markdown-cli ./html/index.html
# ๐ŸŒ Request: /Users/xxx/index.html
# ๐ŸŽ‰ Compliled successfully!
# โ•ฐโ”ˆ Output: /Users/xxx/dist/index.md

$ npx @wcj/html-to-markdown-cli https://jaywcjlove.github.io/idoc/
# ๐ŸŒ Request: https://jaywcjlove.github.io/idoc/
# ๐ŸŽ‰ Compliled successfully!
# โ•ฐโ”ˆ Output: /Users/xxx/dist/idoc.md

# Or

$ sudo npm i @wcj/html-to-markdown-cli -g
$ html-to-markdown ./html/index.html
# ๐ŸŒ Request: /Users/xxx/html/index.html
# ๐ŸŽ‰ Compliled successfully!
# โ•ฐโ”ˆ Output: /Users/xxx/html/dist/index.md

$ html-to-markdown https://jaywcjlove.github.io/idoc/
# ๐ŸŒ Request: https://jaywcjlove.github.io/idoc/
# ๐ŸŽ‰ Compliled successfully!
# โ•ฐโ”ˆ Output: /Users/xxx/dist/idoc.md

Command Help

Usage: html-to-markdown <URL|file path|-> [options] [--help|h] [--version|v]

Passing "-" as the first arg will take input from STDIN

Options:

  -v, --version, Show version number
  -h, --help, Displays help information.
  -o, --output <dir-path>, Output directory. defalut(dist)
  -s, --stdout, Output to stdout

Example:

  html-to-markdown ./html/index.html
  html-to-markdown https://jaywcjlove.github.io/idoc/
  html-to-markdown --output="dist"
  echo "<h1>hello world</h1>"| html-to-markdown - --stdout

Support Config

In the project's root directory, add a .htm2mdrc.js file with the following configuration to enable the rehype and remark plugins.

/**
 * @typedef {import("@wcj/html-to-markdown").Options} Options
 * @type {Options}
 **/
export default { 
  rehypeParseOption: {},
  rehypePlugins: [],
  remarkPlugins: [],
};

Usage

import htmlToMarkdown from '@wcj/html-to-markdown';

htmlToMarkdown({ html: '<h1>Markdown String</h1>' });
// => # Markdown String

API

import { PluggableList } from 'unified';
import { Options as RehypeParseOptions } from 'rehype-parse';
declare type Options = {
  html?: string;
  url?: string;
  rehypeParseOption?: RehypeParseOptions;
  /**
   * List of [remark plugins](https://github.com/remarkjs/remark/blob/main/doc/plugins.md#list-of-plugins) to use.
   * See the next section for examples on how to pass options
   */
  remarkPlugins?: PluggableList;
  /**
   * List of [rehype plugins](https://github.com/rehypejs/rehype/blob/main/doc/plugins.md#list-of-plugins) to use.
   * See the next section for examples on how to pass options
   */
  rehypePlugins?: PluggableList;
};
export default function htmlToMarkdown(options?: Options): Promise<string>;

Development

$ npm i
$ npm install --workspaces
$ npm run build
$ npm run build:cli

Related

Contributors

As always, thanks to our amazing contributors!

Made with contributors.

License

Licensed under the MIT License.

html-to-markdown-cli's People

Contributors

jaywcjlove avatar jessp01 avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

html-to-markdown-cli's Issues

Format not well when convert checked list

origin html:

<ul data-type="taskList">
    <li data-checked="false" data-type="taskItem">
        <label>
            <input type="checkbox">
            <span></span>
       </label>
       <div><p>question</p></div>
    </li>
</ul>

result:
image

Doesn't work from CLI

$ npx @wcj/html-to-markdown-cli ./changelog.html
sh: 1: html-to-markdown: not found

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v4
  • actions/setup-node v4
  • peaceiris/actions-gh-pages v4
  • ncipollo/release-action v1
npm
example/demo1/package.json
  • rehype-rewrite ^4.0.2
package.json
  • idoc ^1.25.0
  • lerna ^8.0.0
  • tsbb ^4.2.3
packages/cli/package.json
  • @types/minimist ~1.2.2
  • auto-config-loader ^1.7.7
  • fs-extra ^11.1.1
  • minimist ~1.2.6
  • node-fetch ^3.2.3
  • node ^14.16 || >=16.0.0
packages/html-to-markdown/package.json
  • rehype ^13.0.0
  • rehype-format ^5.0.0
  • rehype-ignore ^2.0.0
  • rehype-remark ^10.0.0
  • rehype-video ^2.0.0
  • remark-gfm ^4.0.0
  • remark-stringify ^11.0.0
  • unified ^11.0.0
  • node ^14.16 || >=16.0.0

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.