diff --git a/.gitignore b/.gitignore index a59522e..04d6b3b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /mark /docker /testdata +.idea/ diff --git a/README.md b/README.md index c5e5134..ecefa6f 100644 --- a/README.md +++ b/README.md @@ -199,7 +199,8 @@ $ docker run --rm -i kovetskiy/mark:latest mark ``` mark [options] [-u ] [-p ] [-k] [-l ] -f -mark [options] [-u ] [-p ] [-k] [-n] -c +mark [options] [-u ] [-p ] [-k] [-b ] -f +mark [options] [-u ] [-p ] [--drop-h1] -f mark -v | --version mark -h | --help ``` @@ -208,14 +209,17 @@ mark -h | --help - `-p ` — Use specified password for updating Confluence page. - `-l ` — Edit specified Confluence page. If -l is not specified, file should contain metadata (see above). +- `-b ` or `--base-url ` – Base URL for Confluence. + Alternative option for base_url config field. - `-f ` — Use specified markdown file for converting to html. - `-c ` — Specify configuration file which should be used for reading Confluence page URL and markdown file path. - `-k` — Lock page editing to current user only to prevent accidental manual edits over Confluence Web UI. +- `--drop-h1` – Don't include H1 headings in Confluence output. - `--dry-run` — Show resulting HTML and don't update Confluence page content. - `--trace` — Enable trace logs. -- `-v | --version` — Show version. +- `-v | --version` — Show version. - `-h | --help` — Show help screen and call 911. You can store user credentials in the configuration file, which should be diff --git a/main.go b/main.go index 57471ba..40d0082 100644 --- a/main.go +++ b/main.go @@ -108,7 +108,6 @@ By default, mark provides several built-in templates and macros: Usage: mark [options] [-u ] [-p ] [-k] [-l ] -f mark [options] [-u ] [-p ] [-k] [-b ] -f - mark [options] [-u ] [-p ] [-k] [-n] -c mark -v | --version mark -h | --help @@ -123,6 +122,7 @@ Options: -f Use specified markdown file for converting to html. -k Lock page editing to current user only to prevent accidental manual edits over Confluence Web UI. + --drop-h1 Don't include H1 headings in Confluence output. --dry-run Resolve page and ancestry, show resulting HTML and exit. --compile-only Show resulting HTML and don't update Confluence page content. --debug Enable debug logs. @@ -143,6 +143,7 @@ func main() { compileOnly = args["--compile-only"].(bool) dryRun = args["--dry-run"].(bool) editLock = args["-k"].(bool) + dropH1 = args["--drop-h1"].(bool) ) if args["--debug"].(bool) { @@ -286,6 +287,11 @@ func main() { markdown = mark.CompileAttachmentLinks(markdown, attaches) + if dropH1 { + log.Info("Leading H1 heading will be excluded from the Confluence output") + markdown = mark.DropDocumentLeadingH1(markdown) + } + html := mark.CompileMarkdown(markdown, stdlib) { diff --git a/pkg/mark/markdown.go b/pkg/mark/markdown.go index 622a9e1..d79b586 100644 --- a/pkg/mark/markdown.go +++ b/pkg/mark/markdown.go @@ -90,3 +90,15 @@ func CompileMarkdown( return string(html) } + +// DropDocumentLeadingH1 will drop leading H1 headings to prevent +// duplication of or visual conflict with page titles. +// NOTE: This is intended only to operate on the whole markdown document. +// Operating on individual lines will clear them if the begin with `#`. +func DropDocumentLeadingH1( + markdown []byte, +) []byte { + h1 := regexp.MustCompile(`^#[^#].*\n`) + markdown = h1.ReplaceAll(markdown, []byte("")) + return markdown +}