Skip to content

Commit c8a4f8f

Browse files
authored
Merge pull request #16 from ImportTaste/master
<br> to newline plugin
2 parents 0c94a6d + 082a6fb commit c8a4f8f

4 files changed

Lines changed: 30 additions & 0 deletions

File tree

html2md_cli.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ Options:
101101

102102
# Plugins
103103

104+
- Name: PluginBrToNewline
105+
Type: bool
106+
Flag: "plugin-br-to-newline"
107+
Usage: Plugin BrToNewline
108+
104109
- Name: PluginConfluenceAttachments
105110
Type: bool
106111
Flag: "A,plugin-conf-attachment"

html2md_cliDef.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type rootT struct {
3939
OptLinkStyle string `cli:"opt-link-style" usage:"Option LinkStyle"`
4040
OptLinkReferenceStyle string `cli:"opt-link-reference-style" usage:"Option LinkReferenceStyle"`
4141
OptEscapeMode string `cli:"opt-escape-mode" usage:"Option EscapeMode\n"`
42+
PluginBrToNewline bool `cli:"plugin-br-to-newline" usage:"Plugin BrToNewline"`
4243
PluginConfluenceAttachments bool `cli:"A,plugin-conf-attachment" usage:"Plugin ConfluenceAttachments"`
4344
PluginConfluenceCodeBlock bool `cli:"C,plugin-conf-code" usage:"Plugin ConfluenceCodeBlock"`
4445
PluginFrontMatter bool `cli:"F,plugin-frontmatter" usage:"Plugin FrontMatter"`
@@ -85,6 +86,7 @@ var root = &cli.Command{
8586
// OptLinkStyle string
8687
// OptLinkReferenceStyle string
8788
// OptEscapeMode string
89+
// PluginBrToNewline bool
8890
// PluginConfluenceAttachments bool
8991
// PluginConfluenceCodeBlock bool
9092
// PluginFrontMatter bool

plugin_brnewline.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package main
2+
3+
import (
4+
md "github.com/JohannesKaufmann/html-to-markdown"
5+
"github.com/PuerkitoBio/goquery"
6+
)
7+
8+
// TaskListItems converts checkboxes into task list items.
9+
func BrToNewline() md.Plugin {
10+
return func(c *md.Converter) []md.Rule {
11+
return []md.Rule{
12+
{
13+
Filter: []string{"br"},
14+
Replacement: func(content string, selec *goquery.Selection, opt *md.Options) *string {
15+
return md.String("\n")
16+
},
17+
},
18+
}
19+
}
20+
}

prop_html2md.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ func handleOptions(opt *md.Options, rootArgv *rootT) *md.Options {
9898
}
9999

100100
func handlePlugins(conv *md.Converter, rootArgv *rootT) *md.Converter {
101+
if rootArgv.PluginBrToNewline {
102+
conv.Use(BrToNewline())
103+
}
101104
if rootArgv.PluginConfluenceAttachments {
102105
conv.Use(plugin.ConfluenceAttachments())
103106
}

0 commit comments

Comments
 (0)