From 072de962b1dda808c38e67134aed1ba02a81b8fa Mon Sep 17 00:00:00 2001 From: Stephan Hradek Date: Wed, 22 Jul 2020 14:05:33 +0200 Subject: [PATCH 1/2] remove hard wraps --- README.md | 1 + cmd/root.go | 1 + lib/markdown.go | 15 +++++++++++---- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6a22eec..274f4ee 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ For best practice we recommend you [authenticate using an API token](https://id. -s, --space string Space in which page should be created -t, --title string Set the page title on upload (defaults to filename without extension) -u, --username string Confluence username. (Alternatively set CONFLUENCE_USERNAME environment variable) + -w, --hardwraps Render newlines as
--version version for markdown2confluence ## Examples diff --git a/cmd/root.go b/cmd/root.go index 6b09c00..a104aa1 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -22,6 +22,7 @@ func init() { rootCmd.PersistentFlags().StringVarP(&m.Endpoint, "endpoint", "e", lib.DefaultEndpoint, "Confluence endpoint. (Alternatively set CONFLUENCE_ENDPOINT environment variable)") rootCmd.PersistentFlags().StringVar(&m.Parent, "parent", "", "Optional parent page to next content under") rootCmd.PersistentFlags().BoolVarP(&m.Debug, "debug", "d", false, "Enable debug logging") + rootCmd.PersistentFlags().BoolVarP(&m.WithHardWraps, "hardwraps", "w", false, "Render newlines as
") rootCmd.PersistentFlags().IntVarP(&m.Since, "modified-since", "m", 0, "Only upload files that have modifed in the past n minutes") rootCmd.PersistentFlags().StringVarP(&m.Title, "title", "t", "", "Set the page title on upload (defaults to filename without extension)") diff --git a/lib/markdown.go b/lib/markdown.go index dbc78af..c967119 100644 --- a/lib/markdown.go +++ b/lib/markdown.go @@ -33,6 +33,7 @@ type Markdown2Confluence struct { File string Ancestor string Debug bool + WithHardWraps bool Since int Username string Password string @@ -240,15 +241,21 @@ func validateInput(s string, msg string) { func renderContent(filePath, s string) (content string, images []string, err error) { confluenceExtension := e.NewConfluenceExtension(filePath) + ro := goldmark.WithRendererOptions( + html.WithXHTML(), + ) + if m.WithHardWraps { + ro = goldmark.WithRendererOptions( + html.WithHardWraps(), + html.WithXHTML(), + ) + } md := goldmark.New( goldmark.WithExtensions(extension.GFM, extension.DefinitionList), goldmark.WithParserOptions( parser.WithAutoHeadingID(), ), - goldmark.WithRendererOptions( - html.WithHardWraps(), - html.WithXHTML(), - ), + ro, goldmark.WithExtensions( confluenceExtension, ), From df5545b1c1778615e764aa0c6ece1d3611032fd1 Mon Sep 17 00:00:00 2001 From: Stephan Hradek Date: Wed, 22 Jul 2020 14:57:57 +0200 Subject: [PATCH 2/2] pass wrap-flag --- lib/file.go | 2 +- lib/markdown.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/file.go b/lib/file.go index 8321416..77fa7ea 100644 --- a/lib/file.go +++ b/lib/file.go @@ -43,7 +43,7 @@ func (f *MarkdownFile) Upload(m *Markdown2Confluence) (url string, err error) { wikiContent := string(dat) var images []string - wikiContent, images, err = renderContent(f.Path, wikiContent) + wikiContent, images, err = renderContent(f.Path, wikiContent, m.WithHardWraps) if err != nil { return url, fmt.Errorf("unable to render content from %s: %s", f.Path, err) diff --git a/lib/markdown.go b/lib/markdown.go index c967119..893cc2f 100644 --- a/lib/markdown.go +++ b/lib/markdown.go @@ -239,12 +239,12 @@ func validateInput(s string, msg string) { } } -func renderContent(filePath, s string) (content string, images []string, err error) { +func renderContent(filePath, s string, withHardWraps bool) (content string, images []string, err error) { confluenceExtension := e.NewConfluenceExtension(filePath) ro := goldmark.WithRendererOptions( html.WithXHTML(), ) - if m.WithHardWraps { + if withHardWraps { ro = goldmark.WithRendererOptions( html.WithHardWraps(), html.WithXHTML(),