mirror of
https://github.com/kovetskiy/mark.git
synced 2026-05-01 21:02:33 +00:00
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:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
/mark
|
||||
/docker
|
||||
/testdata
|
||||
.idea/
|
||||
|
||||
@@ -199,7 +199,8 @@ $ docker run --rm -i kovetskiy/mark:latest mark <params>
|
||||
|
||||
```
|
||||
mark [options] [-u <username>] [-p <password>] [-k] [-l <url>] -f <file>
|
||||
mark [options] [-u <username>] [-p <password>] [-k] [-n] -c <file>
|
||||
mark [options] [-u <username>] [-p <password>] [-k] [-b <url>] -f <file>
|
||||
mark [options] [-u <username>] [-p <password>] [--drop-h1] -f <file>
|
||||
mark -v | --version
|
||||
mark -h | --help
|
||||
```
|
||||
@@ -208,14 +209,17 @@ mark -h | --help
|
||||
- `-p <password>` — Use specified password for updating Confluence page.
|
||||
- `-l <url>` — Edit specified Confluence page.
|
||||
If -l is not specified, file should contain metadata (see above).
|
||||
- `-b <url>` or `--base-url <url>` – Base URL for Confluence.
|
||||
Alternative option for base_url config field.
|
||||
- `-f <file>` — Use specified markdown file for converting to html.
|
||||
- `-c <file>` — 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
|
||||
|
||||
8
main.go
8
main.go
@@ -108,7 +108,6 @@ By default, mark provides several built-in templates and macros:
|
||||
Usage:
|
||||
mark [options] [-u <username>] [-p <token>] [-k] [-l <url>] -f <file>
|
||||
mark [options] [-u <username>] [-p <password>] [-k] [-b <url>] -f <file>
|
||||
mark [options] [-u <username>] [-p <password>] [-k] [-n] -c <file>
|
||||
mark -v | --version
|
||||
mark -h | --help
|
||||
|
||||
@@ -123,6 +122,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 +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)
|
||||
|
||||
{
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user