mirror of
https://github.com/Warky-Devs/go-mdtopdf-helper.git
synced 2026-11-25 13:48:47 +00:00
- 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
29 lines
839 B
Go
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
|
|
}
|