new -n flag on to activate numbering on links
This commit is contained in:
parent
4fe9d4a03e
commit
26449b8498
11
README.md
11
README.md
@ -8,21 +8,26 @@ A simple wrapper around the Go library https://github.com/LukeEmmet/html2gemini
|
|||||||
```
|
```
|
||||||
html2gmi <flags>
|
html2gmi <flags>
|
||||||
|
|
||||||
|
Usage of C:\Users\lukee\Desktop\programming\projects\go\src\github.com\LukeEmmet\html2gmi\html2gmi.exe:
|
||||||
|
-m, --citationMarkers Use footnote style citation markers
|
||||||
-c, --citationStart int Start citations from this index (default 1)
|
-c, --citationStart int Start citations from this index (default 1)
|
||||||
-i, --input string Input path. Otherwise uses stdin
|
-i, --input string Input path. Otherwise uses stdin
|
||||||
-l, --linkEmitFrequency int Emit gathered links through the document after this number of paragraphs (default 2)
|
-l, --linkEmitFrequency int Emit gathered links through the document after this number of paragraphs (default 2)
|
||||||
-m --citationMarkers Output citation style markers
|
-n, --numberedLinks Number the links
|
||||||
-o, --output string Output path. Otherwise uses stdout
|
-o, --output string Output path. Otherwise uses stdout
|
||||||
-v, --version Find out what version of html2gmi you're running
|
-v, --version Find out what version of html2gmi you're running
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Remarks
|
## Remarks
|
||||||
|
|
||||||
linkEmitFrequency - this flag determines the frequency of the output of link lists. For example 1 means any links from the previous paragraph are emitted after each paragraph. 2, would mean they are emitted every two paragraphs and so on. Any gathered links are always emitted before a new heading.
|
* linkEmitFrequency - this flag determines the frequency of the output of link lists. For example 1 means any links from the previous paragraph are emitted after each paragraph. 2, would mean they are emitted every two paragraphs and so on. Any gathered links are always emitted before a new heading.
|
||||||
|
* citationStart - this flag determines the start index of the links. By default this is 1, so the first link is labelled "[1]", but you can set this as required.
|
||||||
|
* citationMarkers - use a numbered marker in the text to indicate the location of the citation, [1], [2] etc
|
||||||
|
* numberedLinks - number the links with a reference number [1], [2] etc
|
||||||
|
|
||||||
citationStart - this flag determines the start index of the links. By default this is 1, so the first link is labelled "[1]", but you can set this as required.
|
|
||||||
|
|
||||||
You can pipe content in from other applications, for example utilities that download HTML from the web.
|
You can pipe content in from other applications, for example utilities that download HTML from the web.
|
||||||
|
|
||||||
|
36
html2gmi.go
36
html2gmi.go
@ -11,13 +11,14 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
var version = "0.2.2"
|
var version = "0.2.3"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
output = flag.StringP("output", "o", "", "Output path. Otherwise uses stdout")
|
output = flag.StringP("output", "o", "", "Output path. Otherwise uses stdout")
|
||||||
input = flag.StringP("input", "i", "", "Input path. Otherwise uses stdin")
|
input = flag.StringP("input", "i", "", "Input path. Otherwise uses stdin")
|
||||||
citationStart = flag.IntP("citationStart", "c", 1, "Start citations from this index")
|
citationStart = flag.IntP("citationStart", "c", 1, "Start citations from this index")
|
||||||
citationMarkers = flag.BoolP("citationMarkers", "m", false, "Use footnote style citation markers")
|
citationMarkers = flag.BoolP("citationMarkers", "m", false, "Use footnote style citation markers")
|
||||||
|
numberedLinks = flag.BoolP("numberedLinks", "n", false, "Number the links")
|
||||||
linkEmitFrequency = flag.IntP("linkEmitFrequency", "l", 2, "Emit gathered links through the document after this number of paragraphs")
|
linkEmitFrequency = flag.IntP("linkEmitFrequency", "l", 2, "Emit gathered links through the document after this number of paragraphs")
|
||||||
verFlag = flag.BoolP("version", "v", false, "Find out what version of html2gmi you're running")
|
verFlag = flag.BoolP("version", "v", false, "Find out what version of html2gmi you're running")
|
||||||
)
|
)
|
||||||
@ -56,12 +57,12 @@ func getInput() (string, error) {
|
|||||||
info, err := os.Stdin.Stat()
|
info, err := os.Stdin.Stat()
|
||||||
check(err)
|
check(err)
|
||||||
|
|
||||||
if *input != "" {
|
if *input != "" {
|
||||||
//get the input file from the command line
|
//get the input file from the command line
|
||||||
dat, err := ioutil.ReadFile(*input)
|
dat, err := ioutil.ReadFile(*input)
|
||||||
check(err)
|
check(err)
|
||||||
inputHtml = string(dat)
|
inputHtml = string(dat)
|
||||||
} else if info.Mode()&os.ModeNamedPipe != 0 {
|
} else if info.Mode()&os.ModeNamedPipe != 0 {
|
||||||
// we have a pipe input
|
// we have a pipe input
|
||||||
inputHtml = readStdin()
|
inputHtml = readStdin()
|
||||||
|
|
||||||
@ -93,16 +94,17 @@ func main() {
|
|||||||
options.CitationStart = *citationStart
|
options.CitationStart = *citationStart
|
||||||
options.LinkEmitFrequency = *linkEmitFrequency
|
options.LinkEmitFrequency = *linkEmitFrequency
|
||||||
options.CitationMarkers = *citationMarkers
|
options.CitationMarkers = *citationMarkers
|
||||||
|
options.NumberedLinks = *numberedLinks
|
||||||
|
|
||||||
//use slightly nicer Unicode borders, otherwise can use +,|,-
|
//use slightly nicer Unicode borders, otherwise can use +,|,-
|
||||||
options.PrettyTablesOptions.CenterSeparator = "┼"
|
options.PrettyTablesOptions.CenterSeparator = "┼"
|
||||||
options.PrettyTablesOptions.ColumnSeparator = "│"
|
options.PrettyTablesOptions.ColumnSeparator = "│"
|
||||||
options.PrettyTablesOptions.RowSeparator = "─"
|
options.PrettyTablesOptions.RowSeparator = "─"
|
||||||
|
|
||||||
//dont use an extra line to separate header from body, but
|
//dont use an extra line to separate header from body, but
|
||||||
//do separate each row visually
|
//do separate each row visually
|
||||||
options.PrettyTablesOptions.HeaderLine = false
|
options.PrettyTablesOptions.HeaderLine = false
|
||||||
options.PrettyTablesOptions.RowLine = true
|
options.PrettyTablesOptions.RowLine = true
|
||||||
|
|
||||||
text, err := html2gemini.FromString(inputHtml, *options)
|
text, err := html2gemini.FromString(inputHtml, *options)
|
||||||
|
|
||||||
@ -110,7 +112,7 @@ func main() {
|
|||||||
|
|
||||||
//process the output
|
//process the output
|
||||||
if *output == "" {
|
if *output == "" {
|
||||||
fmt.Print(text + "\n") //terminate with a new line
|
fmt.Print(text + "\n") //terminate with a new line
|
||||||
} else {
|
} else {
|
||||||
//save to the specified output
|
//save to the specified output
|
||||||
gmiBytes := []byte(text)
|
gmiBytes := []byte(text)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user