Skip to content

Commit

Permalink
- [+] implement excluding control. close #6
Browse files Browse the repository at this point in the history
  • Loading branch information
suntong committed May 3, 2023
1 parent 51354af commit 098407f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
25 changes: 25 additions & 0 deletions html2md_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ const (

boldText = "<strong>Bold Text</strong>"
boldEscape = "<strong>option src_ip</strong>"

excludingControlTest = `<div class="outter-class">
<h1 class="inner-class">
<div class="other-class3">
<h3>Some heading i don't need</h3>
</div>
The string I need
<span class="other-class" >Some value I don't need</span>
<span class="other-class2" title="sometitle"></span>
</h1>
</div>`
)

type testCase struct {
Expand Down Expand Up @@ -45,6 +56,20 @@ func TestExec(t *testing.T) {
"Only <del>blue ones</del> <s> left</s>",
[]string{"-i", "--plugin-strikethrough"},
},
{
"ExclChildren", "The string I need", excludingControlTest,
[]string{"-s", "h1", "--xc", "-i"},
},
{
"Excl1", `### Some heading i don't need
The string I need`, excludingControlTest,
[]string{"-s", "h1", "-xspan", "-i"},
},
{
"Excl2", "The string I need", excludingControlTest,
[]string{"-s", "h1", "-x", "span", "-xdiv", "-i"},
},
// {
// "", "", "", []string{"-i"},
// },
Expand Down
11 changes: 11 additions & 0 deletions prop_html2md.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ func Html2md(ctx *cli.Context) error {
doc, err := goquery.NewDocumentFromReader(rootArgv.Filei)
clis.AbortOn("Reading file with goquery", err)
content := doc.Find(rootArgv.Sel)
if rootArgv.ExclChildren {
content = content.Children().Remove().End()
// h, _ := goquery.OuterHtml(content)
// clis.Verbose(3, "%#v\n", h)
} else if len(rootArgv.Excl) != 0 {
for _, ex := range rootArgv.Excl {
content = content.Find(ex).Remove().End()
h, _ := content.Html()
clis.Verbose(5, "%#v\n", h)
}
}

domain, url := rootArgv.Domain, rootArgv.Filei.Name()
if domain == "" && regexp.MustCompile(`(?i)^http`).MatchString(url) {
Expand Down

0 comments on commit 098407f

Please sign in to comment.