Skip to content

Commit

Permalink
feat: add contribs/gnorender
Browse files Browse the repository at this point in the history
Signed-off-by: moul <[email protected]>
  • Loading branch information
moul committed Oct 19, 2023
1 parent 89428c5 commit 34d4141
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 0 deletions.
25 changes: 25 additions & 0 deletions contribs/gno-render/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module github.com/gnolang/gno3/contribs/gno-render

go 1.20

require github.com/MichaelMure/go-term-markdown v0.1.4

require (
github.com/MichaelMure/go-term-text v0.3.1 // indirect
github.com/alecthomas/chroma v0.7.1 // indirect
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 // indirect
github.com/disintegration/imaging v1.6.2 // indirect
github.com/dlclark/regexp2 v1.1.6 // indirect
github.com/eliukblau/pixterm/pkg/ansimage v0.0.0-20191210081756-9fb6cf8c2f75 // indirect
github.com/fatih/color v1.9.0 // indirect
github.com/gomarkdown/markdown v0.0.0-20191123064959-2c17d62f5098 // indirect
github.com/kyokomi/emoji/v2 v2.2.8 // indirect
github.com/lucasb-eyer/go-colorful v1.0.3 // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.11 // indirect
github.com/mattn/go-runewidth v0.0.12 // indirect
github.com/rivo/uniseg v0.1.0 // indirect
golang.org/x/image v0.0.0-20191206065243-da761ea9ff43 // indirect
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 // indirect
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 // indirect
)
70 changes: 70 additions & 0 deletions contribs/gno-render/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions contribs/gno-render/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import (
"fmt"
"io/ioutil"
"os"

markdown "github.com/MichaelMure/go-term-markdown"
)

func main() {
println(os.Args)
// If no arguments are provided, read from stdin
if len(os.Args) == 1 {
fileContent, err := ioutil.ReadAll(os.Stdin)
checkErr(err)
renderMarkdown("stdin.gno", fileContent)
}

// Iterate through command-line arguments (file paths)
for _, filePath := range os.Args[1:] {
fileContent, err := ioutil.ReadFile(filePath)
checkErr(err)
renderMarkdown(filePath, fileContent)
}
}

func renderMarkdown(filePath string, fileContent []byte) {
fmt.Printf("-- %s --\n", filePath)

result := markdown.Render(string(fileContent), 80, 6)
fmt.Println(string(result))
}

func checkErr(err error) {
if err != nil {
panic(err)
}
}

0 comments on commit 34d4141

Please sign in to comment.