rename Extensions → Options
This commit is contained in:
parent
99ba8c18fe
commit
91a38d3048
@ -10,13 +10,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
var opt markdown.Options
|
||||||
|
flag.BoolVar(&opt.Notes, "notes", false, "turn on footnote syntax")
|
||||||
|
flag.BoolVar(&opt.Smart, "smart", false, "turn on smart quotes, dashes, and ellipses")
|
||||||
|
flag.BoolVar(&opt.Dlists, "dlists", false, "support definitions lists")
|
||||||
|
|
||||||
flag.Usage = func() {
|
flag.Usage = func() {
|
||||||
fmt.Fprintf(os.Stderr, "Usage: %s [FILE]\n", os.Args[0])
|
fmt.Fprintf(os.Stderr, "Usage: %s [FILE]\n", os.Args[0])
|
||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
}
|
}
|
||||||
optNotes := flag.Bool("notes", false, "turn on footnote syntax")
|
|
||||||
optSmart := flag.Bool("smart", false, "turn on smart quotes, dashes, and ellipses")
|
|
||||||
optDlists := flag.Bool("dlists", false, "support definitions lists")
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
r := os.Stdin
|
r := os.Stdin
|
||||||
@ -29,16 +31,10 @@ func main() {
|
|||||||
r = f
|
r = f
|
||||||
}
|
}
|
||||||
|
|
||||||
e := markdown.Extensions{
|
|
||||||
Notes: *optNotes,
|
|
||||||
Smart: *optSmart,
|
|
||||||
Dlists: *optDlists,
|
|
||||||
}
|
|
||||||
|
|
||||||
startPProf()
|
startPProf()
|
||||||
defer stopPProf()
|
defer stopPProf()
|
||||||
|
|
||||||
doc := markdown.Parse(r, e)
|
doc := markdown.Parse(r, opt)
|
||||||
w := bufio.NewWriter(os.Stdout)
|
w := bufio.NewWriter(os.Stdout)
|
||||||
doc.WriteHtml(w)
|
doc.WriteHtml(w)
|
||||||
w.Flush()
|
w.Flush()
|
||||||
|
2
doc.go
2
doc.go
@ -12,7 +12,7 @@ Usage example:
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
doc := md.Parse(os.Stdin, md.Extensions{Smart: true})
|
doc := md.Parse(os.Stdin, md.Options{Smart: true})
|
||||||
|
|
||||||
w := bufio.NewWriter(os.Stdout)
|
w := bufio.NewWriter(os.Stdout)
|
||||||
doc.WriteHtml(w)
|
doc.WriteHtml(w)
|
||||||
|
10
markdown.go
10
markdown.go
@ -26,8 +26,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Markdown Extensions:
|
// Markdown Options:
|
||||||
type Extensions struct {
|
type Options struct {
|
||||||
Smart bool
|
Smart bool
|
||||||
Notes bool
|
Notes bool
|
||||||
FilterHTML bool
|
FilterHTML bool
|
||||||
@ -36,9 +36,9 @@ type Extensions struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse converts a Markdown document into a tree for later output processing.
|
// Parse converts a Markdown document into a tree for later output processing.
|
||||||
func Parse(r io.Reader, ext Extensions) *Doc {
|
func Parse(r io.Reader, opt Options) *Doc {
|
||||||
d := new(Doc)
|
d := new(Doc)
|
||||||
d.extension = ext
|
d.extension = opt
|
||||||
|
|
||||||
d.parser = new(yyParser)
|
d.parser = new(yyParser)
|
||||||
d.parser.Doc = d
|
d.parser.Doc = d
|
||||||
@ -47,7 +47,7 @@ func Parse(r io.Reader, ext Extensions) *Doc {
|
|||||||
s := preformat(r)
|
s := preformat(r)
|
||||||
|
|
||||||
d.parseRule(ruleReferences, s)
|
d.parseRule(ruleReferences, s)
|
||||||
if ext.Notes {
|
if opt.Notes {
|
||||||
d.parseRule(ruleNotes, s)
|
d.parseRule(ruleNotes, s)
|
||||||
}
|
}
|
||||||
raw := d.parseMarkdown(s)
|
raw := d.parseMarkdown(s)
|
||||||
|
@ -92,7 +92,7 @@ const (
|
|||||||
|
|
||||||
type Doc struct {
|
type Doc struct {
|
||||||
parser *yyParser
|
parser *yyParser
|
||||||
extension Extensions
|
extension Options
|
||||||
|
|
||||||
tree *element /* Results of parse. */
|
tree *element /* Results of parse. */
|
||||||
references *element /* List of link references found. */
|
references *element /* List of link references found. */
|
||||||
|
@ -92,7 +92,7 @@ const (
|
|||||||
|
|
||||||
type Doc struct {
|
type Doc struct {
|
||||||
parser *yyParser
|
parser *yyParser
|
||||||
extension Extensions
|
extension Options
|
||||||
|
|
||||||
tree *element /* Results of parse. */
|
tree *element /* Results of parse. */
|
||||||
references *element /* List of link references found. */
|
references *element /* List of link references found. */
|
||||||
|
Loading…
Reference in New Issue
Block a user