Skip to content
Permalink
Browse files

Documentation, screenshot and more flags

  • Loading branch information...
Depado committed May 21, 2018
1 parent 19748a0 commit 1c660847442603a8bb059f3484f84df3814b724a
Showing with 50 additions and 10 deletions.
  1. +34 −1 README.md
  2. BIN img/screenshot.png
  3. +16 −9 main.go
@@ -10,6 +10,8 @@

Build single-file static HTML page with Chroma (syntax highlighting) and Markdown

![screenshot](https://github.com/Depado/chromarkdown/blob/master/img/screenshot.png)

## Introduction

Chromarkdown is a tool to generate single-file static HTML pages from a
@@ -28,6 +30,16 @@ call)

## Build

Chromarkdown is using [dep](https://github.com/golang/dep) for its dependency
management

```sh
$ go get github.com/Depado/chromarkdown
$ cd $GOPATH/Depado/chromarkdown
$ dep ensure
$ packr build
```

For a standalone installation, chromarkdown is using [packr](https://github.com/gobuffalo/packr)
to embed the template in the go binary.

@@ -38,4 +50,25 @@ $ # or, to embed and install:
$ packr install
```

## Install
## Install

## Usage

Once installed you can run the `chromarkdown` command:

```
$ chromarkdown --help
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.
Usage:
chromarkdown [input file] [flags]
Flags:
-h, --help help for chromarkdown
--no-toc Disable the table of content
-o, --output string specify the path of the output HTML (default "out.html")
--theme string Specify the theme for syntax highlighting (default "monokai")
-t, --title string Specify the title of the HTML page (default "Ouput")
```
BIN +22.5 KB img/screenshot.png
Binary file not shown.
25 main.go
@@ -15,34 +15,40 @@ import (
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 {
// Flags and extensions setup for blackfriday
var exts = bf.NoIntraEmphasis | bf.Tables | bf.FencedCode | bf.Autolink |
bf.Strikethrough | bf.SpaceHeadings | bf.BackslashLineBreak |
bf.DefinitionLists | bf.Footnotes
var flags = bf.UseXHTML | bf.Smartypants | bf.SmartypantsFractions |
bf.SmartypantsDashes | bf.SmartypantsLatexDashes
if !viper.GetBool("no-toc") {
flags = flags | bf.TOC
}

// Setup the renderer
r := bfchroma.NewRenderer(
bfchroma.WithoutAutodetect(),
bfchroma.Extend(bf.NewHTMLRenderer(bf.HTMLRendererParameters{Flags: flags})),
bfchroma.Style(viper.GetString("theme")),
bfchroma.ChromaOptions(html.WithClasses()),
)

// GlobalCSS component
if GlobCSS == "" && r.Formatter.Classes {
b := new(bytes.Buffer)
if err := r.Formatter.WriteCSS(b, r.Style); err != nil {
logrus.WithError(err).Warning("Couldn't write CSS")
}
GlobCSS = template.CSS(b.String())
}

// Run the renderer
return bf.Run(
input,
bf.WithRenderer(r),
@@ -90,6 +96,7 @@ 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")
rootCmd.PersistentFlags().String("theme", "monokai", "Specify the theme for syntax highlighting")
rootCmd.PersistentFlags().Bool("no-toc", false, "Disable the table of content")
if err := viper.BindPFlags(rootCmd.PersistentFlags()); err != nil {
logrus.WithError(err).Fatal("Couldn't bind flags")
}

0 comments on commit 1c66084

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