Add Option for Dropping Leading H1 Heading (#36)

* Add goland IDE prefs to .gitignore

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

* Remove manpage reference to unused -n and -c args

* Add manpage docs for --drop-h1 argument

* Update docs; add docs for --drop-h1 argument

* Rename method to be more verbose; add code comments

Renames to `DropDocumentLeadingH1` to better denote the method's
purpose and adds code docs to this effect in order to hopefully
negate potential misuse on single lines.

* Revert "Add manpage docs for --drop-h1 argument"

This reverts commit 48a641baed.

The `--drop-h1` flag is not understood as an argument in this
context, but rather is folded under `[options]`. This change
caused the arguments to not be properly parsed when the --drop-h1
flag was passed.
This commit is contained in:
Luke Fritz
2020-11-20 08:44:41 -06:00
committed by GitHub
parent b82421a2a6
commit 4ea476ace2
4 changed files with 26 additions and 3 deletions

View File

@@ -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
}