Skip to content

fanly/docsjs-markdown

Repository files navigation

@coding01/docsjs-markdown

Markdown toolkit built for docsjs workflows. Convert docsjs HTML snapshots or DOCX files into Markdown with extensible rules.

npm version npm downloads License


中文文档

What You Get

  • HTML -> Markdown core entry: @coding01/docsjs-markdown
  • DOCX -> Markdown adapter entry: @coding01/docsjs-markdown/docx
  • Rule-based conversion architecture (custom per-tag rules)
  • Optional YAML frontmatter generation
  • CLI for direct .docx -> .md conversion

Recommended Pair: @coding01/docsjs

Use @coding01/docsjs for high-fidelity Word/DOCX import, then feed its HTML snapshot into @coding01/docsjs-markdown for Markdown output.

Landing Page Template Rule

To keep all docsjs ecosystem plugin pages consistent, landing pages follow one shared structure template:

  • Spec file: docs/LANDING_TEMPLATE.md
  • Concrete page: docs/index.html

Installation

npm i @coding01/docsjs-markdown

Quick Start

HTML to Markdown

import { htmlToGfm, htmlToStandardMarkdown } from "@coding01/docsjs-markdown";

const html = "<h1>Hello</h1><p>World</p>";
const gfm = htmlToGfm(html);
const standard = htmlToStandardMarkdown(html);

DOCX to Markdown

import { docxToMarkdown, docxToMarkdownWithMeta } from "@coding01/docsjs-markdown/docx";

const file = input.files?.[0] as File;

const markdown = await docxToMarkdown(file, {
  format: "gfm",
  frontmatter: true,
  sanitizationProfile: "fidelity-first",
});

const richResult = await docxToMarkdownWithMeta(file, {
  format: "gfm",
  frontmatter: true,
  includeParseReport: true,
});

Custom Rules

import { htmlToMarkdown } from "@coding01/docsjs-markdown";

const markdown = htmlToMarkdown("<mark>hit</mark>", {
  rules: {
    mark: (el, ctx) => `==${ctx.convertInline(el)}==`,
  },
});

API

Main Entry: @coding01/docsjs-markdown

  • htmlToMarkdown(html, options)
  • htmlToMarkdownWithMeta(html, options)
  • htmlToGfm(html, options)
  • htmlToStandardMarkdown(html, options)
  • generateFrontmatter(meta)

Sub Entry: @coding01/docsjs-markdown/docx

  • docxToMarkdown(file, options)
  • docxToMarkdownWithMeta(file, options)

Options

  • format: "standard" | "gfm"
  • frontmatter: boolean
  • metadata: custom metadata object
  • rules: custom tag conversion rules
  • includeParseReport: include docsjs parse report (docx entry)
  • sanitizationProfile: "fidelity-first" | "strict" (docx entry)

CLI

docsjs-markdown ./input.docx -o ./output.md --frontmatter --include-parse-report

Options:

  • -o, --output <file>
  • -f, --format <gfm|standard>
  • --frontmatter
  • --include-parse-report
  • --strict
  • -h, --help

Development

npm install
npm run verify
npm run build

Publishing

Manual

npm version patch
git push origin main --follow-tags
npm publish --access public

Suggested CI Rule (same as docsjs)

  • Trigger by tag: v*.*.*
  • Run quality gate: npm run verify
  • Publish package: npm publish --access public

GitHub Packages (repo sidebar "Packages")

  • Workflow: .github/workflows/publish-github-packages.yml
  • Trigger: tag v*.*.* or manual run
  • Target registry: https://npm.pkg.github.com
  • Package name for GitHub Packages: @fanly/docsjs-markdown

License

MIT

Support This Project

If this project saves your time, a small tip is appreciated.

Support docsjs

About

Markdown toolkit for docsjs workflows: convert docsjs HTML snapshots or DOCX into clean, customizable Markdown output. docsjs Markdown 工具包:将 docsjs HTML 快照或 DOCX 转为高质量、可定制的 Markdown 输出。

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors