-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: moul <[email protected]>
- Loading branch information
Showing
3 changed files
with
134 additions
and
0 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
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 | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,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) | ||
} | ||
} |