predown

command module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2018 License: MIT Imports: 13 Imported by: 0

README

predown

GitHub release MIT License Go Report Card Build Status

Preprocess Markdown files using Go templates and TOML configuration.

Usage

# Print merged data to stdout

$ > predown template.md
$ > predown template.md --data data.toml
$ > predown template.md --data data.toml --wrap wrapper.frontmatter

# Pipe merged data to file

$ > predown template.md > output.md

# Create file and store data

$ > predown template.md output.md
$ > predown template.md output.md --data data.toml
$ > predown template.md output.md --data data.toml --wrap wrapper.frontmatter
Example

Let's assume you have example.md, data.toml, and wrapper.frontmatter files like these:

example.md
# Headline

Variable Example from `data.toml` is **{{ .Example }}**.

## Table

| Name | Age |
| ---- | --- |
{{- range .People }}
| {{ .Name }} | {{ .Age }} |
{{- end }}

Nice, isn't it? ;)
data.toml
Example = "Foo"

[[People]]

Name = "Frank"
Age = 21

[[People]]

Name = "Claude"
Age = 45

[[People]]

Name = "Natascha"
Age = 37
wrapper.frontmatter
---
Example: {{ .Data.Example }}
---

{{ .Content }}
Command

Using predown, you can merge the data from data.toml with example.md, and wrap everything in wrapper.frontmatter afterwords.

$ > predown template.md output.md \
    --data data.toml \
    --wrap wrapper.frontmatter

This will create a file called output.md with the following content:

---
Example: Foo
---

Headline
========

Variable Example from `data.toml` is **Foo**.

Table
-----

| Name     | Age |
|----------|-----|
| Frank    | 21  |
| Claude   | 45  |
| Natascha | 37  |

Nice, isn't it? ;)

As you can see, the Markdown file will be tidied up. This can be very handy if you work with tables in your Markdown files. After running predown, they nicely align …

Install

Bash

To download the latest binary for your system (linux or darwin), just use the following curl request:

$ > curl -sSLfo predown \
    ` \
      curl -sSLf \
      https://api.github.com/repos/sbstjn/predown/releases/latest \
      | grep browser_download_url \
      | cut -d '"' -f 4 \
      | grep \`uname -s | tr A-Z a-z\` \
    `
$ > chmod +x predown
$ > ./predown --version
Makefile

To add predown to your existing setup, you can update your Makefile to download the binary file.

PREDOWN= ./predown

$(PREDOWN):
  @ curl -sSLfo $(PREDOWN) \
    ` \
      curl -sSLf https://api.github.com/repos/sbstjn/predown/releases/latest \
      | grep browser_download_url \
      | cut -d '"' -f 4 \
      | grep $(shell uname -s | tr A-Z a-z) \
    `
    @ chmod +x $(PREDOWN)
    @ $(PREDOWN) --version

License

Feel free to use the code, it's released using the MIT license.

Contribution

You are welcome to contribute to this project! 😘

To make sure you have a pleasant experience, please read the code of conduct. It outlines core values and beliefs and will make working together a happier experience.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL