|
| 1 | +//////////////////////////////////////////////////////////////////////////// |
| 2 | +// Program: html2md |
| 3 | +// Purpose: HTML to Markdown |
| 4 | +// Authors: Tong Sun (c) 2020, All rights reserved |
| 5 | +//////////////////////////////////////////////////////////////////////////// |
| 6 | + |
| 7 | +package main |
| 8 | + |
| 9 | +import ( |
| 10 | + // "fmt" |
| 11 | + // "os" |
| 12 | + |
| 13 | + "github.com/mkideal/cli" |
| 14 | + // "github.com/mkideal/cli/clis" |
| 15 | + clix "github.com/mkideal/cli/ext" |
| 16 | +) |
| 17 | + |
| 18 | +//////////////////////////////////////////////////////////////////////////// |
| 19 | +// Constant and data type/structure definitions |
| 20 | + |
| 21 | +//========================================================================== |
| 22 | +// html2md |
| 23 | + |
| 24 | +type rootT struct { |
| 25 | + cli.Helper |
| 26 | + Filei *clix.Reader `cli:"*i,in" usage:"The html/xml file to read from (or stdin)"` |
| 27 | + Sel string `cli:"s,sel" usage:"CSS/goquery selectors\n"` |
| 28 | + OptHeadingStyle string `cli:"opt-heading-style" usage:"Option HeadingStyle"` |
| 29 | + OptHorizontalRule string `cli:"opt-horizontal-rule" usage:"Option HorizontalRule"` |
| 30 | + OptBulletListMarker string `cli:"opt-bullet-list-marker" usage:"Option BulletListMarker"` |
| 31 | + OptCodeBlockStyle string `cli:"opt-code-block-style" usage:"Option CodeBlockStyle"` |
| 32 | + OptFence string `cli:"opt-fence" usage:"Option Fence"` |
| 33 | + OptEmDelimiter string `cli:"opt-em-delimiter" usage:"Option EmDelimiter"` |
| 34 | + OptStrongDelimiter string `cli:"opt-strong-delimiter" usage:"Option StrongDelimiter"` |
| 35 | + OptLinkStyle string `cli:"opt-link-style" usage:"Option LinkStyle"` |
| 36 | + OptLinkReferenceStyle string `cli:"opt-link-reference-style" usage:"Option LinkReferenceStyle\n"` |
| 37 | + PluginConfluenceAttachments bool `cli:"plugin-conf-attachment" usage:"Plugin ConfluenceAttachments"` |
| 38 | + PluginConfluenceCodeBlock bool `cli:"plugin-conf-code" usage:"Plugin ConfluenceCodeBlock"` |
| 39 | + PluginFrontMatter bool `cli:"plugin-frontmatter" usage:"Plugin FrontMatter"` |
| 40 | + PluginGitHubFlavored bool `cli:"plugin-gfm" usage:"Plugin GitHubFlavored"` |
| 41 | + PluginStrikethrough bool `cli:"plugin-strikethrough" usage:"Plugin Strikethrough"` |
| 42 | + PluginTable bool `cli:"plugin-table" usage:"Plugin Table"` |
| 43 | + PluginTaskListItems bool `cli:"plugin-task-list" usage:"Plugin TaskListItems"` |
| 44 | + PluginVimeoEmbed bool `cli:"plugin-vimeo" usage:"Plugin VimeoEmbed"` |
| 45 | + PluginYoutubeEmbed bool `cli:"plugin-youtube" usage:"Plugin YoutubeEmbed"` |
| 46 | +} |
| 47 | + |
| 48 | +var root = &cli.Command{ |
| 49 | + Name: "html2md", |
| 50 | + Desc: "HTML to Markdown\nVersion " + version + " built on " + date + |
| 51 | + "\nCopyright (C) 2020, Tong Sun", |
| 52 | + Text: "HTML to Markdown converter on command line" + |
| 53 | + "\n\nUsage:\n html2md [Options...]", |
| 54 | + Argv: func() interface{} { return new(rootT) }, |
| 55 | + Fn: html2md, |
| 56 | + |
| 57 | + NumOption: cli.AtLeast(1), |
| 58 | +} |
| 59 | + |
| 60 | +// Template for main starts here |
| 61 | +//////////////////////////////////////////////////////////////////////////// |
| 62 | +// Constant and data type/structure definitions |
| 63 | + |
| 64 | +// The OptsT type defines all the configurable options from cli. |
| 65 | +// type OptsT struct { |
| 66 | +// Filei *clix.Reader |
| 67 | +// Sel string |
| 68 | +// OptHeadingStyle string |
| 69 | +// OptHorizontalRule string |
| 70 | +// OptBulletListMarker string |
| 71 | +// OptCodeBlockStyle string |
| 72 | +// OptFence string |
| 73 | +// OptEmDelimiter string |
| 74 | +// OptStrongDelimiter string |
| 75 | +// OptLinkStyle string |
| 76 | +// OptLinkReferenceStyle string |
| 77 | +// PluginConfluenceAttachments bool |
| 78 | +// PluginConfluenceCodeBlock bool |
| 79 | +// PluginFrontMatter bool |
| 80 | +// PluginGitHubFlavored bool |
| 81 | +// PluginStrikethrough bool |
| 82 | +// PluginTable bool |
| 83 | +// PluginTaskListItems bool |
| 84 | +// PluginVimeoEmbed bool |
| 85 | +// PluginYoutubeEmbed bool |
| 86 | +// Verbose int |
| 87 | +// } |
| 88 | + |
| 89 | +//////////////////////////////////////////////////////////////////////////// |
| 90 | +// Global variables definitions |
| 91 | + |
| 92 | +// var ( |
| 93 | +// progname = "html2md" |
| 94 | +// version = "0.1.0" |
| 95 | +// date = "2020-07-25" |
| 96 | + |
| 97 | +// rootArgv *rootT |
| 98 | +// // Opts store all the configurable options |
| 99 | +// Opts OptsT |
| 100 | +// ) |
| 101 | + |
| 102 | +//////////////////////////////////////////////////////////////////////////// |
| 103 | +// Function definitions |
| 104 | + |
| 105 | +// Function main |
| 106 | +// func main() { |
| 107 | +// cli.SetUsageStyle(cli.DenseNormalStyle) // left-right, for up-down, use ManualStyle |
| 108 | +// //NOTE: You can set any writer implements io.Writer |
| 109 | +// // default writer is os.Stdout |
| 110 | +// if err := cli.Root(root,).Run(os.Args[1:]); err != nil { |
| 111 | +// fmt.Fprintln(os.Stderr, err) |
| 112 | +// os.Exit(1) |
| 113 | +// } |
| 114 | +// fmt.Println("") |
| 115 | +// } |
| 116 | + |
| 117 | +// Template for main dispatcher starts here |
| 118 | +//========================================================================== |
| 119 | +// Dumb root handler |
| 120 | + |
| 121 | +// func html2md(ctx *cli.Context) error { |
| 122 | +// ctx.JSON(ctx.RootArgv()) |
| 123 | +// ctx.JSON(ctx.Argv()) |
| 124 | +// fmt.Println() |
| 125 | + |
| 126 | +// return nil |
| 127 | +// } |
| 128 | + |
| 129 | +// Template for CLI handling starts here |
0 commit comments