Skip to content
Permalink
Browse files

Args, CI, and other stuff

  • Loading branch information...
Depado committed May 21, 2018
1 parent e41fa0f commit 5584cf0b1e603c03f8f6c56d1bf61cfc6dc65c84
Showing with 200 additions and 28 deletions.
  1. +23 −0 .drone.yml
  2. +2 −1 .gitignore
  3. +118 −1 Gopkg.lock
  4. +7 −0 README.md
  5. 0 {templates → css}/temp.css
  6. +50 −26 main.go
@@ -0,0 +1,23 @@
workspace:
base: /go
path: src/github.com/Depado/chromarkdown

pipeline:
prerequisites:
image: "golang:latest"
commands:
- go version
- go get -u github.com/golang/dep/cmd/dep
- dep ensure -vendor-only

linter:
image: "golang:latest"
commands:
- go get -u github.com/alecthomas/gometalinter
- gometalinter --install --force
- gometalinter --vendor --deadline=100s ./...

test:
image: "golang:latest"
commands:
- go test -cover -failfast ./...
@@ -15,5 +15,6 @@
.glide/
vendor/
chromarkdown
in.md
out.html
*-packr.go
input.md

Some generated files are not rendered by default. Learn more.

@@ -1,2 +1,9 @@
# chromarkdown

![Go Version](https://img.shields.io/badge/Go%20Version-latest-brightgreen.svg)
[![Go Report Card](https://goreportcard.com/badge/github.com/Depado/chromarkdown)](https://goreportcard.com/report/github.com/Depado/chromarkdown)
[![Build Status](https://drone.depado.eu/api/badges/Depado/chromarkdown/status.svg)](https://drone.depado.eu/Depado/chromarkdown)
[![codecov](https://codecov.io/gh/Depado/chromarkdown/branch/master/graph/badge.svg)](https://codecov.io/gh/Depado/chromarkdown)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Depado/chromarkdown/blob/master/LICENSE)
[![Godoc](https://godoc.org/github.com/Depado/chromarkdown?status.svg)](https://godoc.org/github.com/Depado/chromarkdown)
[![Say Thanks!](https://img.shields.io/badge/Say%20Thanks-!-1EAEDB.svg)](https://saythanks.io/to/Depado)
File renamed without changes.
76 main.go
@@ -8,26 +8,31 @@ import (

"github.com/Depado/bfchroma"
"github.com/alecthomas/chroma/formatters/html"
"github.com/gobuffalo/packr"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
bf "gopkg.in/russross/blackfriday.v2"
)

// Built in extensions for the markdown renderer
var exts = bf.NoIntraEmphasis | bf.Tables | bf.FencedCode | bf.Autolink |
bf.Strikethrough | bf.SpaceHeadings | bf.BackslashLineBreak |
bf.DefinitionLists | bf.Footnotes

// Built in flags for the markdown renderer
var flags = bf.UseXHTML | bf.Smartypants | bf.SmartypantsFractions |
bf.SmartypantsDashes | bf.SmartypantsLatexDashes | bf.TOC

// GlobCSS is a byte slice containing the style CSS of the renderer
var GlobCSS template.CSS

// render takes a []byte input and runs the mardown render (with the bfchroma
// plugin enabled and with default values)
func render(input []byte) []byte {
r := bfchroma.NewRenderer(
bfchroma.WithoutAutodetect(),
bfchroma.Extend(
bf.NewHTMLRenderer(bf.HTMLRendererParameters{Flags: flags}),
),
bfchroma.Extend(bf.NewHTMLRenderer(bf.HTMLRendererParameters{Flags: flags})),
bfchroma.Style("monokai"),
bfchroma.ChromaOptions(html.WithClasses()),
)
@@ -45,29 +50,48 @@ func render(input []byte) []byte {
)
}

func main() {
var err error
var fd *os.File
var t *template.Template
var in []byte
var rootCmd = &cobra.Command{
Use: "chromarkdown [input file]",
Short: "Chromarkdown is a simple markdown-to-html renderer",
Long: `Chromarkdown uses a combination of blackfriday and chroma to render an input markdown file.
It generates standalone HTML files that includes fonts, a grid system and extra CSS.`,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
var err error
var fd *os.File
var t *template.Template
var in []byte

if fd, err = os.Create("out.html"); err != nil {
logrus.WithError(err).Fatal("Couldn't create file")
}
defer fd.Close()
box := packr.NewBox("./templates")
if t, err = template.New("output").Parse(box.String("index.tmpl")); err != nil {
logrus.WithError(err).Fatal("Couldn't parse template")
}

if in, err = ioutil.ReadFile("in.md"); err != nil {
logrus.WithError(err).Fatal("Couldn't read in.md")
}
if t, err = template.ParseFiles("templates/index.tmpl"); err != nil {
logrus.WithError(err).Fatal("Couldn't parse template")
}
err = t.ExecuteTemplate(fd, "index.tmpl", map[string]interface{}{
"title": "Output",
"rendered": template.HTML(string(render(in))),
"css": GlobCSS,
})
if err != nil {
logrus.WithError(err).Fatal("Couldn't execute template")
}
if fd, err = os.Create(viper.GetString("output")); err != nil {
logrus.WithError(err).Fatal("Couldn't create file")
}
defer fd.Close()

if in, err = ioutil.ReadFile(args[0]); err != nil {
logrus.WithError(err).Fatal("Couldn't read in.md")
}
err = t.ExecuteTemplate(fd, "output", map[string]interface{}{
"title": viper.GetString("title"),
"rendered": template.HTML(string(render(in))),
"css": GlobCSS,
})
if err != nil {
logrus.WithError(err).Fatal("Couldn't execute template")
}
},
}

func init() {
rootCmd.PersistentFlags().StringP("output", "o", "out.html", "specify the path of the output HTML")
rootCmd.PersistentFlags().StringP("title", "t", "Ouput", "Specify the title of the HTML page")
viper.BindPFlags(rootCmd.PersistentFlags())
}

func main() {
rootCmd.Execute()
}

0 comments on commit 5584cf0

Please sign in to comment.
You can’t perform that action at this time.