Skip to content

Commit

Permalink
Merge pull request #23 from Skeeve/NoHardWraps
Browse files Browse the repository at this point in the history
No hard wraps
  • Loading branch information
justmiles authored Jul 22, 2020
2 parents 91a92cb + df5545b commit aa3117e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <br />
--version version for markdown2confluence

## Examples
Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <br />")
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)")

Expand Down
2 changes: 1 addition & 1 deletion lib/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 12 additions & 5 deletions lib/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Markdown2Confluence struct {
File string
Ancestor string
Debug bool
WithHardWraps bool
Since int
Username string
Password string
Expand Down Expand Up @@ -238,17 +239,23 @@ 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 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,
),
Expand Down

0 comments on commit aa3117e

Please sign in to comment.