Skip to content

Commit f584bf7

Browse files
committed
- [+] add --opt-escape-mode; build with latest; closes #2 #4 #8
1 parent 9103300 commit f584bf7

5 files changed

Lines changed: 30 additions & 45 deletions

File tree

html2md_cli.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# program name, name for the executable
22
ProgramName: html2md
33
Authors: Tong Sun
4+
Since: 2020
45

56
PackageName: main
67

@@ -80,7 +81,13 @@ Options:
8081
- Name: OptLinkReferenceStyle
8182
Type: "string"
8283
Flag: "opt-link-reference-style"
83-
Usage: "Option LinkReferenceStyle\\n"
84+
Usage: "Option LinkReferenceStyle"
85+
86+
- Name: OptEscapeMode
87+
Type: "string"
88+
Flag: "opt-escape-mode"
89+
Usage: "Option EscapeMode\\n"
90+
8491

8592
# Plugins
8693

html2md_cliDef.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
////////////////////////////////////////////////////////////////////////////
22
// Program: html2md
33
// Purpose: HTML to Markdown
4-
// Authors: Tong Sun (c) 2020, All rights reserved
4+
// Authors: Tong Sun (c) 2020-2023, All rights reserved
55
////////////////////////////////////////////////////////////////////////////
66

77
package main
@@ -35,7 +35,8 @@ type rootT struct {
3535
OptEmDelimiter string `cli:"opt-em-delimiter" usage:"Option EmDelimiter"`
3636
OptStrongDelimiter string `cli:"opt-strong-delimiter" usage:"Option StrongDelimiter"`
3737
OptLinkStyle string `cli:"opt-link-style" usage:"Option LinkStyle"`
38-
OptLinkReferenceStyle string `cli:"opt-link-reference-style" usage:"Option LinkReferenceStyle\n"`
38+
OptLinkReferenceStyle string `cli:"opt-link-reference-style" usage:"Option LinkReferenceStyle"`
39+
OptEscapeMode string `cli:"opt-escape-mode" usage:"Option EscapeMode\n"`
3940
PluginConfluenceAttachments bool `cli:"A,plugin-conf-attachment" usage:"Plugin ConfluenceAttachments"`
4041
PluginConfluenceCodeBlock bool `cli:"C,plugin-conf-code" usage:"Plugin ConfluenceCodeBlock"`
4142
PluginFrontMatter bool `cli:"F,plugin-frontmatter" usage:"Plugin FrontMatter"`
@@ -51,11 +52,11 @@ type rootT struct {
5152
var root = &cli.Command{
5253
Name: "html2md",
5354
Desc: "HTML to Markdown\nVersion " + version + " built on " + date +
54-
"\nCopyright (C) 2020, Tong Sun",
55+
"\nCopyright (C) 2020-2023, Tong Sun",
5556
Text: "HTML to Markdown converter on command line" +
5657
"\n\nUsage:\n html2md [Options...]",
5758
Argv: func() interface{} { return new(rootT) },
58-
Fn: html2md,
59+
Fn: Html2md,
5960

6061
NumOption: cli.AtLeast(1),
6162
}
@@ -79,6 +80,7 @@ var root = &cli.Command{
7980
// OptStrongDelimiter string
8081
// OptLinkStyle string
8182
// OptLinkReferenceStyle string
83+
// OptEscapeMode string
8284
// PluginConfluenceAttachments bool
8385
// PluginConfluenceCodeBlock bool
8486
// PluginFrontMatter bool
@@ -98,7 +100,7 @@ var root = &cli.Command{
98100
// var (
99101
// progname = "html2md"
100102
// version = "0.1.0"
101-
// date = "2020-08-09"
103+
// date = "2023-05-02"
102104

103105
// rootArgv *rootT
104106
// // Opts store all the configurable options
@@ -110,9 +112,7 @@ var root = &cli.Command{
110112

111113
// Function main
112114
// func main() {
113-
// cli.SetUsageStyle(cli.DenseNormalStyle) // left-right, for up-down, use ManualStyle
114-
// //NOTE: You can set any writer implements io.Writer
115-
// // default writer is os.Stdout
115+
// cli.SetUsageStyle(cli.DenseNormalStyle)
116116
// if err := cli.Root(root,).Run(os.Args[1:]); err != nil {
117117
// fmt.Fprintln(os.Stderr, err)
118118
// os.Exit(1)
@@ -124,7 +124,8 @@ var root = &cli.Command{
124124
//==========================================================================
125125
// Dumb root handler
126126

127-
// func html2md(ctx *cli.Context) error {
127+
// Html2md - main dispatcher dumb handler
128+
// func Html2md(ctx *cli.Context) error {
128129
// ctx.JSON(ctx.RootArgv())
129130
// ctx.JSON(ctx.Argv())
130131
// fmt.Println()

html2md_main.go

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
////////////////////////////////////////////////////////////////////////////
22
// Program: html2md
33
// Purpose: HTML to Markdown
4-
// Authors: Tong Sun (c) 2020, All rights reserved
4+
// Authors: Tong Sun (c) 2020-2023, All rights reserved
55
////////////////////////////////////////////////////////////////////////////
66

77
package main
@@ -13,58 +13,28 @@ import (
1313
"os"
1414

1515
"github.com/mkideal/cli"
16-
clix "github.com/mkideal/cli/ext"
1716
)
1817

1918
////////////////////////////////////////////////////////////////////////////
2019
// Constant and data type/structure definitions
2120

22-
// The OptsT type defines all the configurable options from cli.
23-
type OptsT struct {
24-
Filei *clix.Reader
25-
Sel string
26-
OptHeadingStyle string
27-
OptHorizontalRule string
28-
OptBulletListMarker string
29-
OptCodeBlockStyle string
30-
OptFence string
31-
OptEmDelimiter string
32-
OptStrongDelimiter string
33-
OptLinkStyle string
34-
OptLinkReferenceStyle string
35-
PluginConfluenceAttachments bool
36-
PluginConfluenceCodeBlock bool
37-
PluginFrontMatter bool
38-
PluginGitHubFlavored bool
39-
PluginStrikethrough bool
40-
PluginTable bool
41-
PluginTaskListItems bool
42-
PluginVimeoEmbed bool
43-
PluginYoutubeEmbed bool
44-
Verbose int
45-
}
46-
4721
////////////////////////////////////////////////////////////////////////////
4822
// Global variables definitions
4923

5024
var (
5125
progname = "html2md"
52-
version = "0.2.01"
53-
date = "2020-08-08"
26+
version = "1.0.0"
27+
date = "2023-05-02"
5428

5529
rootArgv *rootT
56-
// Opts store all the configurable options
57-
Opts OptsT
5830
)
5931

6032
////////////////////////////////////////////////////////////////////////////
6133
// Function definitions
6234

6335
// Function main
6436
func main() {
65-
cli.SetUsageStyle(cli.DenseNormalStyle) // left-right, for up-down, use ManualStyle
66-
//NOTE: You can set any writer implements io.Writer
67-
// default writer is os.Stdout
37+
cli.SetUsageStyle(cli.DenseNormalStyle)
6838
if err := cli.Root(root).Run(os.Args[1:]); err != nil {
6939
fmt.Fprintln(os.Stderr, err)
7040
os.Exit(1)

html2md_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ func TestExec(t *testing.T) {
3131
{
3232
"BoldEscape", "**option src\\_ip**", boldEscape, []string{"-i"},
3333
},
34+
{
35+
"BoldEscapeOff", "**option src_ip**", boldEscape,
36+
[]string{"-i", "--opt-escape-mode", "disabled"},
37+
},
3438
{
3539
"Checkbox", "- [x] Checked!\n- [ ] Check Me!",
3640
"<ul><li><input type=checkbox checked>Checked!</li><li><input type=checkbox>Check Me!</li></ul>",

prop_html2md.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
//==========================================================================
2121
// root handler
2222

23-
func html2md(ctx *cli.Context) error {
23+
func Html2md(ctx *cli.Context) error {
2424
rootArgv = ctx.RootArgv().(*rootT)
2525
// https://pkg.go.dev/github.com/mkideal/cli@v0.2.2/clis?tab=doc
2626
clis.Setup(progname, rootArgv.Verbose.Value())
@@ -80,6 +80,9 @@ func handleOptions(opt *md.Options, rootArgv *rootT) *md.Options {
8080
if rootArgv.OptLinkReferenceStyle != "" {
8181
opt.LinkReferenceStyle = rootArgv.OptLinkReferenceStyle
8282
}
83+
if rootArgv.OptEscapeMode != "" {
84+
opt.EscapeMode = rootArgv.OptEscapeMode
85+
}
8386
return opt
8487
}
8588

0 commit comments

Comments
 (0)