From 8b52bd5513b80d77cd6cb1fcafcb734a7c05a4cb Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Fri, 7 Aug 2015 19:18:13 +0900 Subject: [PATCH] Stubs --- .gitignore | 1 + vimdoc.go | 165 +++++++++++++++++++++++++++++++++++++++++++++++++++++ vimdown.go | 90 +++++++++++++++++++++++++++++ 3 files changed, 256 insertions(+) create mode 100644 .gitignore create mode 100644 vimdoc.go create mode 100644 vimdown.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6cb3968 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +vimdown diff --git a/vimdoc.go b/vimdoc.go new file mode 100644 index 0000000..acc5c9e --- /dev/null +++ b/vimdoc.go @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2015 Alex Yatskov + * Author: Alex Yatskov + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package main + +import ( + "bytes" + "log" + + "github.com/russross/blackfriday" +) + +type vimDoc struct { +} + +func VimDocRenderer() blackfriday.Renderer { + return &vimDoc{} +} + +// Block-level callbacks +func (*vimDoc) BlockCode(out *bytes.Buffer, text []byte, lang string) { + log.Println("stubbing BlockCode") +} + +func (*vimDoc) BlockQuote(out *bytes.Buffer, text []byte) { + log.Println("stubbing BlockQuote") +} + +func (*vimDoc) BlockHtml(out *bytes.Buffer, text []byte) { + log.Println("stubbing BlockHtml") +} + +func (*vimDoc) Header(out *bytes.Buffer, text func() bool, level int, id string) { + log.Println("stubbing Header") +} + +func (*vimDoc) HRule(out *bytes.Buffer) { + log.Println("stubbing HRule") +} + +func (*vimDoc) List(out *bytes.Buffer, text func() bool, flags int) { + log.Println("stubbing List") +} + +func (*vimDoc) ListItem(out *bytes.Buffer, text []byte, flags int) { + log.Println("stubbing ListItem") +} + +func (*vimDoc) Paragraph(out *bytes.Buffer, text func() bool) { + log.Println("stubbing Paragraph") +} + +func (*vimDoc) Table(out *bytes.Buffer, header []byte, body []byte, columnData []int) { + log.Println("stubbing Table") +} + +func (*vimDoc) TableRow(out *bytes.Buffer, text []byte) { + log.Println("stubbing TableRow") +} + +func (*vimDoc) TableHeaderCell(out *bytes.Buffer, text []byte, flags int) { + log.Println("stubbing TableHeaderCell") +} + +func (*vimDoc) TableCell(out *bytes.Buffer, text []byte, flags int) { + log.Println("stubbing TableCell") +} + +func (*vimDoc) Footnotes(out *bytes.Buffer, text func() bool) { + log.Println("stubbing Footnotes") +} + +func (*vimDoc) FootnoteItem(out *bytes.Buffer, name, text []byte, flags int) { + log.Println("stubbing FootnoteItem") +} + +func (*vimDoc) TitleBlock(out *bytes.Buffer, text []byte) { + log.Println("stubbing TitleBlock") +} + +// Span-level callbacks +func (*vimDoc) AutoLink(out *bytes.Buffer, link []byte, kind int) { + log.Println("stubbing AutoLink") +} + +func (*vimDoc) CodeSpan(out *bytes.Buffer, text []byte) { + log.Println("stubbing CodeSpan") +} + +func (*vimDoc) DoubleEmphasis(out *bytes.Buffer, text []byte) { + log.Println("stubbing DoubleEmphasis") +} + +func (*vimDoc) Emphasis(out *bytes.Buffer, text []byte) { + log.Println("stubbing Emphasis") +} + +func (*vimDoc) Image(out *bytes.Buffer, link []byte, title []byte, alt []byte) { + log.Println("stubbing Image") +} + +func (*vimDoc) LineBreak(out *bytes.Buffer) { + log.Println("stubbing LineBreak") +} + +func (*vimDoc) Link(out *bytes.Buffer, link []byte, title []byte, content []byte) { + log.Println("stubbing Link") +} + +func (*vimDoc) RawHtmlTag(out *bytes.Buffer, tag []byte) { + log.Println("stubbing RawHtmlTag") +} + +func (*vimDoc) TripleEmphasis(out *bytes.Buffer, text []byte) { + log.Println("stubbing TripleEmphasis") +} + +func (*vimDoc) StrikeThrough(out *bytes.Buffer, text []byte) { + log.Println("stubbing StrikeThrough") +} + +func (*vimDoc) FootnoteRef(out *bytes.Buffer, ref []byte, id int) { + log.Println("stubbing FootnoteRef") +} + +// Low-level callbacks +func (*vimDoc) Entity(out *bytes.Buffer, entity []byte) { + log.Println("stubbing Entity") +} + +func (*vimDoc) NormalText(out *bytes.Buffer, text []byte) { + log.Println("stubbing NormalText") +} + +// Header and footer +func (*vimDoc) DocumentHeader(out *bytes.Buffer) { + log.Println("stubbing DocumentHeader") +} + +func (*vimDoc) DocumentFooter(out *bytes.Buffer) { + log.Println("stubbing DocumentFooter") +} + +func (*vimDoc) GetFlags() int { + return 0 +} diff --git a/vimdown.go b/vimdown.go new file mode 100644 index 0000000..27737fe --- /dev/null +++ b/vimdown.go @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2015 Alex Yatskov + * Author: Alex Yatskov + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package main + +import ( + "flag" + "fmt" + "io/ioutil" + "log" + "os" + + "github.com/russross/blackfriday" +) + +func usage() { + fmt.Fprintf(os.Stderr, "Usage: %s [options] [input] [output]\n", os.Args[0]) + fmt.Fprintf(os.Stderr, "http://foosoft.net/projects/vimdown/\n\n") + fmt.Fprintf(os.Stderr, "Parameters:\n") + flag.PrintDefaults() +} +func main() { + flag.Usage = usage + flag.Parse() + + args := flag.Args() + + var input []byte + var err error + switch len(args) { + case 0: + if input, err = ioutil.ReadAll(os.Stdin); err != nil { + log.Fatal("error reading from stdin") + } + case 1, 2: + if input, err = ioutil.ReadFile(args[0]); err != nil { + log.Fatalf("error reading from %s", args[0]) + } + default: + flag.Usage() + os.Exit(-1) + } + + renderer := VimDocRenderer() + + extensions := 0 + extensions |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS + extensions |= blackfriday.EXTENSION_TABLES + extensions |= blackfriday.EXTENSION_FENCED_CODE + extensions |= blackfriday.EXTENSION_AUTOLINK + extensions |= blackfriday.EXTENSION_STRIKETHROUGH + extensions |= blackfriday.EXTENSION_SPACE_HEADERS + + output := blackfriday.Markdown(input, renderer, extensions) + + var file *os.File + switch len(args) { + case 2: + if file, err = os.Create(args[1]); err != nil { + fmt.Fprintf(os.Stderr, "Error creating %s: %v", args[1], err) + os.Exit(-1) + } + defer file.Close() + default: + file = os.Stdout + } + + if _, err = file.Write(output); err != nil { + log.Fatal("error writing output") + } +}