Add flag for removing leading H1 heading in markdown; fixes #35

This commit is contained in:
Luke Fritz
2020-11-16 23:50:25 -06:00
parent 94707f13b0
commit 9c9c6a0ccd
2 changed files with 17 additions and 0 deletions

View File

@@ -123,6 +123,7 @@ Options:
-f <file> 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 +144,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 +288,11 @@ func main() {
markdown = mark.CompileAttachmentLinks(markdown, attaches)
if dropH1 {
log.Info("Leading H1 heading will be excluded from the Confluence output")
markdown = mark.DropH1Markdown(markdown)
}
html := mark.CompileMarkdown(markdown, stdlib)
{

View File

@@ -90,3 +90,13 @@ func CompileMarkdown(
return string(html)
}
// dropH1Markdown will drop leading H1 headings to prevent
// duplication of or conflict with page titles.
func DropH1Markdown(
markdown []byte,
) []byte {
h1 := regexp.MustCompile(`^#[^#].*\n`)
markdown = h1.ReplaceAll(markdown, []byte(""))
return markdown
}