You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
719 B

  1. package main
  2. import (
  3. "io/ioutil"
  4. "os"
  5. "path/filepath"
  6. "github.com/fatih/color"
  7. blackfriday "gopkg.in/russross/blackfriday.v2"
  8. )
  9. func check(err error) {
  10. if err != nil {
  11. color.Red(err.Error())
  12. }
  13. }
  14. func readDir(dirpath string) []string {
  15. var elems []string
  16. _ = filepath.Walk(dirpath, func(path string, f os.FileInfo, err error) error {
  17. elems = append(elems, path)
  18. return nil
  19. })
  20. return elems
  21. }
  22. func readFile(path string) string {
  23. dat, err := ioutil.ReadFile(path)
  24. if err != nil {
  25. color.Red(path)
  26. }
  27. check(err)
  28. return string(dat)
  29. }
  30. func fileToHTML(path string) (string, error) {
  31. mdcontent := readFile(path)
  32. htmlcontent := string(blackfriday.Run([]byte(mdcontent)))
  33. return htmlcontent, nil
  34. }