mirror of
https://github.com/kovetskiy/mark.git
synced 2026-05-02 21:32:34 +00:00
Add flag for removing leading H1 heading in markdown; fixes #35
This commit is contained in:
7
main.go
7
main.go
@@ -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)
|
||||
|
||||
{
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user