From 4c812741ac590eb153193fe2c6d228e6845974f7 Mon Sep 17 00:00:00 2001 From: Stephan Hradek Date: Mon, 6 Jun 2022 08:38:23 +0200 Subject: [PATCH] Feature/h1 title (#196) * h1_title config * introduce h1_title in config * add h1_drop config setting * allsow allow h1_drop in config --- README.md | 5 +++++ config.go | 2 ++ main.go | 19 +++++++++++++++++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ecd06a3..216841d 100644 --- a/README.md +++ b/README.md @@ -440,7 +440,9 @@ mark -h | --help manual edits over Confluence Web UI. - `--space ` - Use specified space key. If not specified space ley must be set in a page metadata. - `--drop-h1` – Don't include H1 headings in Confluence output. + This option corresponds to the `h1_drop` setting in the configuration file. - `--title-from-h1` - Extract page title from a leading H1 heading. If no H1 heading on a page then title must be set in a page metadata. + This option corresponds to the `h1_title` setting in the configuration file. - `--dry-run` — Show resulting HTML and don't update Confluence page content. - `--minor-edit` — Don't send notifications while updating Confluence page. - `--trace` — Enable trace logs. @@ -455,6 +457,8 @@ username = "your-email" password = "password-or-api-key-for-confluence-cloud" # If you are using Confluence Cloud add the /wiki suffix to base_url base_url = "http://confluence.local" +h1_title = true +h1_drop = true ``` **NOTE**: Labels aren't supported when using `minor-edit`! @@ -569,6 +573,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Hugo Cisneiros

💻
jevfok

💻
Mateus Miranda

🚧 +
Skeeve

💻 diff --git a/config.go b/config.go index 53c72f7..9516f34 100644 --- a/config.go +++ b/config.go @@ -10,6 +10,8 @@ type Config struct { Username string `env:"MARK_USERNAME" toml:"username"` Password string `env:"MARK_PASSWORD" toml:"password"` BaseURL string `env:"MARK_BASE_URL" toml:"base_url"` + H1Title bool `env:"MARK_H1_TITLE" toml:"h1_title"` + H1Drop bool `env:"MARK_H1_DROP" toml:"h1_drop"` } func LoadConfig(path string) (*Config, error) { diff --git a/main.go b/main.go index d7e8452..1b2707f 100644 --- a/main.go +++ b/main.go @@ -120,6 +120,14 @@ func main() { log.Fatal(err) } + if ! flags.TitleFromH1 && config.H1Title { + flags.TitleFromH1 = true + } + + if ! flags.DropH1 && config.H1Drop { + flags.DropH1 = true + } + creds, err := GetCredentials(flags, config) if err != nil { log.Fatal(err) @@ -212,7 +220,7 @@ func processFile( if meta.Title == "" { log.Fatal( `page title is not set ('Title' header is not set ` + - `and '--title-from-h1' option is not set or there is no H1 in the file)`, + `and '--title-from-h1' option and 'h1_title' config is not set or there is no H1 in the file)`, ) } @@ -275,7 +283,14 @@ func processFile( } if flags.CompileOnly { - fmt.Println(mark.CompileMarkdown(markdown, stdlib)) + if flags.DropH1 { + log.Info( + "the leading H1 heading will be excluded from the Confluence output", + ) + markdown = mark.DropDocumentLeadingH1(markdown) + } + + fmt.Println(mark.CompileMarkdown(markdown, stdlib)) os.Exit(0) }