Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide a public APIThis also introduces a simple program, md2gmn, th…
…at is meant for testingthe renderer on Markdown files. Nonetheless, it can be used as astandalone tool as well.
- Loading branch information
Showing
5 changed files
with
53 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// md2gmn converts Markdown text files to text/gemini. | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"io/ioutil" | ||
"os" | ||
|
||
gemini "git.tdem.in/tdemin/gmnhg" | ||
) | ||
|
||
func main() { | ||
var ( | ||
input string | ||
file *os.File | ||
) | ||
flag.StringVar(&input, "f", "", "input file") | ||
flag.Parse() | ||
|
||
if input != "" { | ||
var err error | ||
file, err = os.Open(input) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} else { | ||
file = os.Stdin | ||
} | ||
text, err := ioutil.ReadAll(file) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
os.Stdout.Write(gemini.RenderMarkdown(text)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/gomarkdown/markdown v0.0.0-20201024011455-45c732cc8a6b h1:Om9FdD4lzIJELyJxwr9EWSjaG6GMUNS3iebnhrGevhI= | ||
github.com/gomarkdown/markdown v0.0.0-20201024011455-45c732cc8a6b/go.mod h1:aii0r/K0ZnHv7G0KF7xy1v0A7s2Ljrb5byB7MO5p6TU= | ||
golang.org/dl v0.0.0-20190829154251-82a15e2f2ead/go.mod h1:IUMfjQLJQd4UTqG1Z90tenwKoCX93Gn3MAQJMOSBsDQ= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package gemini | ||
|
||
import ( | ||
"git.tdem.in/tdemin/gmnhg/internal/gemini" | ||
"github.com/gomarkdown/markdown" | ||
"github.com/gomarkdown/markdown/parser" | ||
) | ||
|
||
// RenderMarkdown converts Markdown text to text/gemini using gomarkdown. | ||
// | ||
// gomarkdown doesn't return any errors, nor does this function. | ||
func RenderMarkdown(md []byte) (geminiText []byte) { | ||
ast := markdown.Parse(md, parser.NewWithExtensions(parser.CommonExtensions)) | ||
geminiContent := markdown.Render(ast, gemini.NewRenderer()) | ||
return geminiContent | ||
} |