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, ),