Skip to content

Commit

Permalink
<br> to newline plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
God-damnit-all committed Jun 15, 2023
1 parent 0c94a6d commit 082a6fb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions html2md_cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ Options:

# Plugins

- Name: PluginBrToNewline
Type: bool
Flag: "plugin-br-to-newline"
Usage: Plugin BrToNewline

- Name: PluginConfluenceAttachments
Type: bool
Flag: "A,plugin-conf-attachment"
Expand Down
2 changes: 2 additions & 0 deletions html2md_cliDef.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type rootT struct {
OptLinkStyle string `cli:"opt-link-style" usage:"Option LinkStyle"`
OptLinkReferenceStyle string `cli:"opt-link-reference-style" usage:"Option LinkReferenceStyle"`
OptEscapeMode string `cli:"opt-escape-mode" usage:"Option EscapeMode\n"`
PluginBrToNewline bool `cli:"plugin-br-to-newline" usage:"Plugin BrToNewline"`
PluginConfluenceAttachments bool `cli:"A,plugin-conf-attachment" usage:"Plugin ConfluenceAttachments"`
PluginConfluenceCodeBlock bool `cli:"C,plugin-conf-code" usage:"Plugin ConfluenceCodeBlock"`
PluginFrontMatter bool `cli:"F,plugin-frontmatter" usage:"Plugin FrontMatter"`
Expand Down Expand Up @@ -85,6 +86,7 @@ var root = &cli.Command{
// OptLinkStyle string
// OptLinkReferenceStyle string
// OptEscapeMode string
// PluginBrToNewline bool
// PluginConfluenceAttachments bool
// PluginConfluenceCodeBlock bool
// PluginFrontMatter bool
Expand Down
20 changes: 20 additions & 0 deletions plugin_brnewline.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
md "github.com/JohannesKaufmann/html-to-markdown"
"github.com/PuerkitoBio/goquery"
)

// TaskListItems converts checkboxes into task list items.
func BrToNewline() md.Plugin {
return func(c *md.Converter) []md.Rule {
return []md.Rule{
{
Filter: []string{"br"},
Replacement: func(content string, selec *goquery.Selection, opt *md.Options) *string {
return md.String("\n")
},
},
}
}
}
3 changes: 3 additions & 0 deletions prop_html2md.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ func handleOptions(opt *md.Options, rootArgv *rootT) *md.Options {
}

func handlePlugins(conv *md.Converter, rootArgv *rootT) *md.Converter {
if rootArgv.PluginBrToNewline {
conv.Use(BrToNewline())
}
if rootArgv.PluginConfluenceAttachments {
conv.Use(plugin.ConfluenceAttachments())
}
Expand Down

0 comments on commit 082a6fb

Please sign in to comment.