Files
Hein 5bf9c3673d feat: add DOCX/HTML output, go-tomd reverse converter, and input/output flags
- go-mdtopdf-helper: -format pdf,html,docx; new internal/document writers
  (standalone HTML, pure Go DOCX)
- new go-tomd command converting PDF/HTML/DOCX back to Markdown, skipping
  existing .md files unless -force
- -input/-output on both commands (single file with chosen name, or output
  directory mirroring the scan layout)
- restructure README and build config (Makefile, goreleaser) for both binaries
2026-10-08 17:05:01 +02:00

29 lines
839 B
Go

package tomd
import (
"fmt"
"strings"
"github.com/JohannesKaufmann/html-to-markdown/v2/converter"
"github.com/JohannesKaufmann/html-to-markdown/v2/plugin/base"
"github.com/JohannesKaufmann/html-to-markdown/v2/plugin/commonmark"
"github.com/JohannesKaufmann/html-to-markdown/v2/plugin/strikethrough"
"github.com/JohannesKaufmann/html-to-markdown/v2/plugin/table"
)
// HTML converts an HTML document or fragment to Markdown.
func HTML(data []byte) ([]byte, error) {
conv := converter.NewConverter(converter.WithPlugins(
base.NewBasePlugin(),
commonmark.NewCommonmarkPlugin(),
strikethrough.NewStrikethroughPlugin(),
table.NewTablePlugin(),
))
md, err := conv.ConvertString(string(data))
if err != nil {
return nil, fmt.Errorf("failed to convert HTML: %w", err)
}
return []byte(strings.TrimSpace(md) + "\n"), nil
}