diff options
| author | Tong Sun <[email protected]> | 2023-05-02 13:27:10 -0400 |
|---|---|---|
| committer | Tong Sun <[email protected]> | 2023-05-02 13:27:10 -0400 |
| commit | f584bf775faa77901bac27e1ab3416c4712544e8 (patch) | |
| tree | caa6405732977f148724cdc762d13f781d45ebbb | |
| parent | - [#] only install cloudsmith cli when necessary (diff) | |
| download | html2md-f584bf775faa77901bac27e1ab3416c4712544e8.tar.xz html2md-f584bf775faa77901bac27e1ab3416c4712544e8.zip | |
- [+] add --opt-escape-mode; build with latest; closes #2 #4 #8
| -rw-r--r-- | html2md_cli.yaml | 9 | ||||
| -rw-r--r-- | html2md_cliDef.go | 19 | ||||
| -rw-r--r-- | html2md_main.go | 38 | ||||
| -rw-r--r-- | html2md_test.go | 4 | ||||
| -rw-r--r-- | prop_html2md.go | 5 |
5 files changed, 30 insertions, 45 deletions
diff --git a/html2md_cli.yaml b/html2md_cli.yaml index a12a6fb..642b72c 100644 --- a/html2md_cli.yaml +++ b/html2md_cli.yaml @@ -1,6 +1,7 @@ # program name, name for the executable ProgramName: html2md Authors: Tong Sun +Since: 2020 PackageName: main @@ -80,7 +81,13 @@ Options: - Name: OptLinkReferenceStyle Type: "string" Flag: "opt-link-reference-style" - Usage: "Option LinkReferenceStyle\\n" + Usage: "Option LinkReferenceStyle" + + - Name: OptEscapeMode + Type: "string" + Flag: "opt-escape-mode" + Usage: "Option EscapeMode\\n" + # Plugins diff --git a/html2md_cliDef.go b/html2md_cliDef.go index c27b33b..6a7dc21 100644 --- a/html2md_cliDef.go +++ b/html2md_cliDef.go @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////// // Program: html2md // Purpose: HTML to Markdown -// Authors: Tong Sun (c) 2020, All rights reserved +// Authors: Tong Sun (c) 2020-2023, All rights reserved //////////////////////////////////////////////////////////////////////////// package main @@ -35,7 +35,8 @@ type rootT struct { OptEmDelimiter string `cli:"opt-em-delimiter" usage:"Option EmDelimiter"` OptStrongDelimiter string `cli:"opt-strong-delimiter" usage:"Option StrongDelimiter"` OptLinkStyle string `cli:"opt-link-style" usage:"Option LinkStyle"` - OptLinkReferenceStyle string `cli:"opt-link-reference-style" usage:"Option LinkReferenceStyle\n"` + OptLinkReferenceStyle string `cli:"opt-link-reference-style" usage:"Option LinkReferenceStyle"` + OptEscapeMode string `cli:"opt-escape-mode" usage:"Option EscapeMode\n"` 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"` @@ -51,11 +52,11 @@ type rootT struct { var root = &cli.Command{ Name: "html2md", Desc: "HTML to Markdown\nVersion " + version + " built on " + date + - "\nCopyright (C) 2020, Tong Sun", + "\nCopyright (C) 2020-2023, Tong Sun", Text: "HTML to Markdown converter on command line" + "\n\nUsage:\n html2md [Options...]", Argv: func() interface{} { return new(rootT) }, - Fn: html2md, + Fn: Html2md, NumOption: cli.AtLeast(1), } @@ -79,6 +80,7 @@ var root = &cli.Command{ // OptStrongDelimiter string // OptLinkStyle string // OptLinkReferenceStyle string +// OptEscapeMode string // PluginConfluenceAttachments bool // PluginConfluenceCodeBlock bool // PluginFrontMatter bool @@ -98,7 +100,7 @@ var root = &cli.Command{ // var ( // progname = "html2md" // version = "0.1.0" -// date = "2020-08-09" +// date = "2023-05-02" // rootArgv *rootT // // Opts store all the configurable options @@ -110,9 +112,7 @@ var root = &cli.Command{ // Function main // func main() { -// cli.SetUsageStyle(cli.DenseNormalStyle) // left-right, for up-down, use ManualStyle -// //NOTE: You can set any writer implements io.Writer -// // default writer is os.Stdout +// cli.SetUsageStyle(cli.DenseNormalStyle) // if err := cli.Root(root,).Run(os.Args[1:]); err != nil { // fmt.Fprintln(os.Stderr, err) // os.Exit(1) @@ -124,7 +124,8 @@ var root = &cli.Command{ //========================================================================== // Dumb root handler -// func html2md(ctx *cli.Context) error { +// Html2md - main dispatcher dumb handler +// func Html2md(ctx *cli.Context) error { // ctx.JSON(ctx.RootArgv()) // ctx.JSON(ctx.Argv()) // fmt.Println() diff --git a/html2md_main.go b/html2md_main.go index 2bb6225..bd4b7f5 100644 --- a/html2md_main.go +++ b/html2md_main.go @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////// // Program: html2md // Purpose: HTML to Markdown -// Authors: Tong Sun (c) 2020, All rights reserved +// Authors: Tong Sun (c) 2020-2023, All rights reserved //////////////////////////////////////////////////////////////////////////// package main @@ -13,48 +13,20 @@ import ( "os" "github.com/mkideal/cli" - clix "github.com/mkideal/cli/ext" ) //////////////////////////////////////////////////////////////////////////// // Constant and data type/structure definitions -// The OptsT type defines all the configurable options from cli. -type OptsT struct { - Filei *clix.Reader - Sel string - OptHeadingStyle string - OptHorizontalRule string - OptBulletListMarker string - OptCodeBlockStyle string - OptFence string - OptEmDelimiter string - OptStrongDelimiter string - OptLinkStyle string - OptLinkReferenceStyle string - PluginConfluenceAttachments bool - PluginConfluenceCodeBlock bool - PluginFrontMatter bool - PluginGitHubFlavored bool - PluginStrikethrough bool - PluginTable bool - PluginTaskListItems bool - PluginVimeoEmbed bool - PluginYoutubeEmbed bool - Verbose int -} - //////////////////////////////////////////////////////////////////////////// // Global variables definitions var ( progname = "html2md" - version = "0.2.01" - date = "2020-08-08" + version = "1.0.0" + date = "2023-05-02" rootArgv *rootT - // Opts store all the configurable options - Opts OptsT ) //////////////////////////////////////////////////////////////////////////// @@ -62,9 +34,7 @@ var ( // Function main func main() { - cli.SetUsageStyle(cli.DenseNormalStyle) // left-right, for up-down, use ManualStyle - //NOTE: You can set any writer implements io.Writer - // default writer is os.Stdout + cli.SetUsageStyle(cli.DenseNormalStyle) if err := cli.Root(root).Run(os.Args[1:]); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) diff --git a/html2md_test.go b/html2md_test.go index a9ed5ae..c8e6507 100644 --- a/html2md_test.go +++ b/html2md_test.go @@ -32,6 +32,10 @@ func TestExec(t *testing.T) { "BoldEscape", "**option src\\_ip**", boldEscape, []string{"-i"}, }, { + "BoldEscapeOff", "**option src_ip**", boldEscape, + []string{"-i", "--opt-escape-mode", "disabled"}, + }, + { "Checkbox", "- [x] Checked!\n- [ ] Check Me!", "<ul><li><input type=checkbox checked>Checked!</li><li><input type=checkbox>Check Me!</li></ul>", []string{"-i", "-G"}, diff --git a/prop_html2md.go b/prop_html2md.go index 2435f23..b32f90f 100644 --- a/prop_html2md.go +++ b/prop_html2md.go @@ -20,7 +20,7 @@ import ( //========================================================================== // root handler -func html2md(ctx *cli.Context) error { +func Html2md(ctx *cli.Context) error { rootArgv = ctx.RootArgv().(*rootT) // https://pkg.go.dev/github.com/mkideal/[email protected]/clis?tab=doc clis.Setup(progname, rootArgv.Verbose.Value()) @@ -80,6 +80,9 @@ func handleOptions(opt *md.Options, rootArgv *rootT) *md.Options { if rootArgv.OptLinkReferenceStyle != "" { opt.LinkReferenceStyle = rootArgv.OptLinkReferenceStyle } + if rootArgv.OptEscapeMode != "" { + opt.EscapeMode = rootArgv.OptEscapeMode + } return opt } |