skip to main content

NAME

shorthand - tutorial

DESCRIPTION

Shorthand is a simple label or macro expander. This is a brief tutorial an using it.

Timestamp in Markdown file

If the content of the markdown file template/report.md was


    Report Date: @now@

    # Topic: The current local time.

    This report highlights the current local time of rendering this document

    The current local time is @now@

Put the definitions in a file, now.shorthand

    :bash: @now@ date
    :import: @report@ template/report.md
    @report@

and run it through shorthand

    shorthand now.shorthand | pandoc -s > reports/report-time.html

What this command does is read the definitions and it replaces all occurrences of “@now@” in the markdown document with the output from the Unix program date.

The output (before piping to Pandoc) would look something like

    Report Date: Sat Aug 29 11:25:48 PDT 2015

    # Topic: The current local time.

    This report highlights the current local time of rendering this document

    The current local time is Sat Aug 29 11:25:48 PDT 2015

Notice that both “@now@” are replace with the same date information.

In the end of the definitions file we also have an @report@. First it is defined as an “import” and then it is rendered. The “import” reads the template, evaluates the template rendering the result at the second @report@. This result is what is passed via a pipe to Pandoc to generate the HTML page reports/report-time.html

embedding shorthand definitions

We can make that command line easier by embedding the definitions in our template.

You could also embed the shorthand definitions command straight in the markdown itself. with something like

    :bash: @now@ date

    Report Date: @now@

    # Topic: The current local time.

    This report highlights the current local time of rendering this document

    The current local time is @now

That simpler command is much shorter. This is the more typical usage.

    shorthand testdata/report.md | pandoc -s > testdata/report.html

Installation

shorthand can be installed with the go get command.

    go get github.com/rsdoiel/shorthand/...

ALSO SEE