Home

Awesome

<!-- >>>>>> BEGIN GENERATED FILE (include): SOURCE markdown/readme/README.template.md -->

Markdown Helper

Gem

Contents

Installation

gem install markdown_helper

What's a Markdown Helper?

Class <code>MarkdownHelper</code> supports:

How It Works

The markdown helper is a preprocessor that reads a markdown document (template) and writes another markdown document.

The template can contain certain instructions that call for file inclusions.

Restriction: git Only

The helper works only in a git project: the working directory or one of ita parents must be a git directory -- one in which command git rev-parse --git-dir succeeds.

Commented or Pristine?

By default, the output markdown has added comments that show:

You can suppress those comments using the <code>pristine</code> option.

File Inclusion

<img src="images/include.png" alt="include_icon" width="50">

This markdown helper enables file inclusion in GitHub markdown.

(Actually, this README file itself is built using file inclusion.)

See all use cases.

Re-use Text

Keep your markdown DRY (Don't Repeat Yourself) by re-using text. See the use case.

Include Generated Text

In particular, you can include text that's built during your "readme build." See the use case.

Nest Inclusions

You can nest inclusions. See the use case.

Merged Text Formats

Markdown

You can include text that is to be treated simply as markdown. See the use case.

Highlighted Code Block

You can include a code block that's to be highlighted. See the use case.

Plain Code Block

You can also include a code block without highlighting. See the use case.

Comment

You can include text that's to become a comment in the markdown. See the use case.

Details

You can include text that's to become details in the markdown. See the use case.

Pre-Formatted Text

You can include text that's pre-formatted. See the use case.

Usage

CLI

<!-- >>>>>> BEGIN INCLUDED FILE (code_block): SOURCE bin/usage/include.txt -->

include.txt:


Usage: markdown_helper include [options] template_file_path markdown_file_path
        --pristine                   No comments added
        --help                       Display help
    
  where

    * template_file_path is the path to an existing file.
    * markdown_file_path is the path to a file to be created.

  Typically:

    * Both file types are .md.
    * The template file contains file inclusion descriptions.
<!-- <<<<<< END INCLUDED FILE (code_block): SOURCE bin/usage/include.txt -->

API

<!-- >>>>>> BEGIN INCLUDED FILE (ruby): SOURCE markdown/readme/include_usage.rb -->

include_usage.rb:

require 'markdown_helper'

template_file_path = 'highlight_ruby_template.md'
markdown_file_path = 'highlighted_ruby.md'
# Pristine.
markdown_helper = MarkdownHelper.new
markdown_helper.pristine = true
markdown_helper.include(template_file_path, markdown_file_path)
# Also pristine.
markdown_helper = MarkdownHelper.new(:pristine => true)
markdown_helper.include(template_file_path, markdown_file_path)
<!-- <<<<<< END INCLUDED FILE (ruby): SOURCE markdown/readme/include_usage.rb -->

Include Descriptions

Specify each file inclusion at the beginning of a line via an include description, which has the form:

<code>@[</code>format<code>](</code>relative_file_path<code>)</code>

where:

Example Include Descriptions
<!-- >>>>>> BEGIN INCLUDED FILE (code_block): SOURCE markdown/readme/include.md -->

include.md:

@[ruby](my_ruby.rb)

@[:code_block](my_language.xyzzy)

@[:markdown](my_markdown.md)

@[:comment](my_comment.txt)

@[:pre](my_preformatted.txt)
<!-- <<<<<< END INCLUDED FILE (code_block): SOURCE markdown/readme/include.md -->

Page TOC

You can specify the location for an automatically-generated page TOC (table of cotents). See the use case.

Diagnostics

"Noisy" (Not Pristine)

By default, the markdown helper inserts comments indicating inclusions. See the use case.

Missing Includee File

A missing includee file causes an exception that shows an inclusion backtrace. See the use case.

Circular Inclusion

A circular inclusion causes an exception that shows an inclusion backtrace. See the use case.

Run irb

What Should Be Next?

I have opened some enhancement Issues in the GitHub markdown_helper project:

Feel free to comment on any of these, or to add more Issues (enhancement or otherwise).

<!-- <<<<<< END GENERATED FILE (include): SOURCE markdown/readme/README.template.md -->