forked from suntong/html2md
-
Notifications
You must be signed in to change notification settings - Fork 0
/
html2md_cliDef.go
142 lines (123 loc) · 5.58 KB
/
html2md_cliDef.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
////////////////////////////////////////////////////////////////////////////
// Program: html2md
// Purpose: HTML to Markdown
// Authors: Tong Sun (c) 2020-2023, All rights reserved
////////////////////////////////////////////////////////////////////////////
package main
import (
// "fmt"
// "os"
"github.com/mkideal/cli"
// "github.com/mkideal/cli/clis"
clix "github.com/mkideal/cli/ext"
)
////////////////////////////////////////////////////////////////////////////
// Constant and data type/structure definitions
//==========================================================================
// html2md
type rootT struct {
cli.Helper
Filei *clix.Reader `cli:"*i,in" usage:"The html/xml file to read from (or stdin)"`
Domain string `cli:"d,domain" usage:"Domain of the web page, needed for links when --in is not url"`
Sel string `cli:"s,sel" usage:"CSS/goquery selectors" dft:"body"`
Excl []string `cli:"x,excl" usage:"Excluding CSS/goquery selectors"`
ExclChildren bool `cli:"xc" usage:"Excluding all children nodes"`
Verbose cli.Counter `cli:"v,verbose" usage:"Verbose mode (Multiple -v options increase the verbosity.)\n"`
OptHeadingStyle string `cli:"opt-heading-style" usage:"Option HeadingStyle"`
OptHorizontalRule string `cli:"opt-horizontal-rule" usage:"Option HorizontalRule"`
OptBulletListMarker string `cli:"opt-bullet-list-marker" usage:"Option BulletListMarker"`
OptCodeBlockStyle string `cli:"opt-code-block-style" usage:"Option CodeBlockStyle"`
OptFence string `cli:"opt-fence" usage:"Option Fence"`
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"`
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"`
PluginGitHubFlavored bool `cli:"G,plugin-gfm" usage:"Plugin GitHubFlavored"`
PluginStrikethrough bool `cli:"S,plugin-strikethrough" usage:"Plugin Strikethrough"`
PluginTable bool `cli:"T,plugin-table" usage:"Plugin Table"`
PluginTableCompat bool `cli:"plugin-table-compat" usage:"Plugin TableCompat"`
PluginTaskListItems bool `cli:"L,plugin-task-list" usage:"Plugin TaskListItems"`
PluginVimeoEmbed bool `cli:"V,plugin-vimeo" usage:"Plugin VimeoEmbed"`
PluginYoutubeEmbed bool `cli:"Y,plugin-youtube" usage:"Plugin YoutubeEmbed"`
}
var root = &cli.Command{
Name: "html2md",
Desc: "HTML to Markdown\nVersion " + version + " built on " + date +
"\nCopyright (C) 2020-2024, Tong Sun",
Text: "HTML to Markdown converter on command line" +
"\n\nUsage:\n html2md [Options...]",
Argv: func() interface{} { return new(rootT) },
Fn: Html2md,
NumOption: cli.AtLeast(1),
}
// Template for main starts here
////////////////////////////////////////////////////////////////////////////
// Constant and data type/structure definitions
// The OptsT type defines all the configurable options from cli.
// type OptsT struct {
// Filei *clix.Reader
// Domain string
// Sel string
// Excl []string
// ExclChildren bool
// Verbose cli.Counter
// OptHeadingStyle string
// OptHorizontalRule string
// OptBulletListMarker string
// OptCodeBlockStyle string
// OptFence string
// OptEmDelimiter string
// OptStrongDelimiter string
// OptLinkStyle string
// OptLinkReferenceStyle string
// OptEscapeMode string
// PluginBrToNewline bool
// PluginConfluenceAttachments bool
// PluginConfluenceCodeBlock bool
// PluginFrontMatter bool
// PluginGitHubFlavored bool
// PluginStrikethrough bool
// PluginTable bool
// PluginTableCompat bool
// PluginTaskListItems bool
// PluginVimeoEmbed bool
// PluginYoutubeEmbed bool
// Verbose int
// }
////////////////////////////////////////////////////////////////////////////
// Global variables definitions
// var (
// progname = "html2md"
// version = "0.1.0"
// date = "2023-05-03"
// rootArgv *rootT
// // Opts store all the configurable options
// Opts OptsT
// )
////////////////////////////////////////////////////////////////////////////
// Function definitions
// Function main
// func main() {
// cli.SetUsageStyle(cli.DenseNormalStyle)
// if err := cli.Root(root,).Run(os.Args[1:]); err != nil {
// fmt.Fprintln(os.Stderr, err)
// os.Exit(1)
// }
// fmt.Println("")
// }
// Template for main dispatcher starts here
//==========================================================================
// Dumb root handler
// Html2md - main dispatcher dumb handler
// func Html2md(ctx *cli.Context) error {
// ctx.JSON(ctx.RootArgv())
// ctx.JSON(ctx.Argv())
// fmt.Println()
// return nil
// }
// Template for CLI handling starts here