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
This commit is contained in:
Hein committed 2026-10-08 17:05:01 +02:00
1 parent 50b7246c21
commit 5bf9c3673d
17 files changed
+1903 -84

No files matched your search

+18
View File
@@ -21,6 +21,11 @@ func run() int {
var engineName, formatList string
flag.StringVar(&conv.InputDir, "dir", ".", "Directory to scan for markdown files")
flag.StringVar(&conv.InputFile, "input", "",
"Convert only this markdown file (instead of scanning -dir)")
flag.StringVar(&conv.Output, "output", "",
"With -input: output file name, extension added per format (-output report -> report.pdf). "+
"Without -input: directory to write results to instead of next to the sources")
flag.BoolVar(&conv.Recursive, "recursive", true, "Scan directories recursively")
flag.BoolVar(&conv.Parallel, "parallel", true, "Convert files in parallel")
flag.BoolVar(&hookMode, "hook", false, "Run as git pre-commit hook")
@@ -30,12 +35,25 @@ func run() int {
"Output formats, comma separated: "+strings.Join(converter.FormatNames, ", "))
flag.Parse()
set := map[string]bool{}
flag.Visit(func(f *flag.Flag) { set[f.Name] = true })
if conv.InputFile != "" && (set["dir"] || set["recursive"]) {
fmt.Fprintln(os.Stderr, "Error: -input cannot be combined with -dir or -recursive")
return 2
}
formats, err := converter.ParseFormats(formatList)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
return 2
}
conv.Formats = formats
if !hookMode {
if err := conv.Validate(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
return 2
}
}
// The engine only matters for PDF output.
if slices.Contains(formats, converter.FormatPDF) {
+57
View File
@@ -0,0 +1,57 @@
// Command go-tomd converts PDF, HTML and DOCX documents to Markdown.
package main
import (
"flag"
"fmt"
"os"
"strings"
"github.com/Warky-Devs/go-mdtopdf-helper.git/internal/tomd"
)
func main() {
os.Exit(run())
}
func run() int {
r := &tomd.Runner{}
var formatList string
flag.StringVar(&r.InputDir, "dir", ".", "Directory to scan for documents")
flag.StringVar(&r.InputFile, "input", "",
"Convert only this document (instead of scanning -dir); -format is ignored")
flag.StringVar(&r.Output, "output", "",
"With -input: Markdown file name to write (.md added if missing). "+
"Without -input: directory to write results to instead of next to the sources")
flag.BoolVar(&r.Recursive, "recursive", true, "Scan directories recursively")
flag.BoolVar(&r.Parallel, "parallel", true, "Convert files in parallel")
flag.BoolVar(&r.Force, "force", false, "Overwrite Markdown files that already exist")
flag.StringVar(&formatList, "format", strings.Join(tomd.FormatNames, ","),
"Input formats to convert, comma separated: "+strings.Join(tomd.FormatNames, ", "))
flag.Parse()
set := map[string]bool{}
flag.Visit(func(f *flag.Flag) { set[f.Name] = true })
if r.InputFile != "" && (set["dir"] || set["recursive"]) {
fmt.Fprintln(os.Stderr, "Error: -input cannot be combined with -dir or -recursive")
return 2
}
formats, err := tomd.ParseFormats(formatList)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
return 2
}
r.Formats = formats
if err := r.Validate(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
return 2
}
if err := r.Run(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
return 1
}
return 0
}