# MarkdownHelper
## What's This?
[![Gem Version](https://badge.fury.io/rb/markdown_helper.svg)](https://badge.fury.io/rb/markdown_helper)
Class MarkdownHelper
supports:
* [File inclusion](#file-inclusion): to include text from other files, as code-block or markdown.
* [Image path resolution](#image-path-resolution): to resolve relative image paths to absolute URL paths (so they work even in gem documentation).
* [Image attributes](#image-attributes): image attributes are passed through to an HTML img
tag.
## How It Works
The markdown helper reads a markdown document (template) and writes another markdown document.
The template can contain certain instructions that call for file inclusions and image resolutions.
## Commented or Pristine?
By default, the output markdown has added comments that show:
* The path to the template file.
* The path to each included file.
* The image description (original) for each resolved image file path.
You can suppress those comments using the pristine
option.
## File Inclusion
![include_icon](images/include.png | width=50)
This markdown helper enables file inclusion in GitHub markdown.
(Actually, this README file itself is built using file inclusion.)
Use the markdown helper to merge external files into a markdown (.md) file.
### Merged Text Formats
#### Highlighted Code Block
@[ruby](include.rb)
#### Plain Code Block
@[:code_block](include.rb)
[Note: In the gem documentation, RubyDoc.info chooses to highlight this code block regardless. Go figure.]
#### Comment
Comment text is written into the output between the comment delimiters \
#### Verbatim
Verbatim text is included unadorned. Most often, verbatim text is markdown to be rendered as part of the markdown page.
### Usage
#### CLI
@[:code_block](../bin/usage/include.txt)
#### API
@[ruby](include_usage.rb)
#### Include Descriptions
Specify each file inclusion at the beginning of a line via an *include description*, which has the form:
@[
*format*]\(
*relative_file_path*)
where:
* *format* (in square brackets) is one of the following:
* Highlighting mode such as [ruby]
, to include a highlighted code block. This can be any Ace mode mentioned in [GitHub Languages](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml).
* [:code_block]
, to include a plain code block.
* [:verbatim]
, to include text verbatim (to be rendered as markdown).
* *relative_file_path* points to the file to be included.
##### Example Include Descriptions
@[code_block](include.md)
## Image Path Resolution
![image_icon](images/image.png | width=50)
This markdown helper enables image path resolution in GitHub markdown.
(Actually, this README file itself is built using image path resolution.)
Use the markdown helper to resolve image relative paths in a markdown (.md) file.
This matters because when markdown becomes part of a Ruby gem, its images will have been relocated in the documentation at RubyDoc.info, breaking the relative paths. The resolved (absolute) urls, however, will still be valid.
### Usage
#### CLI
@[:code_block](../bin/usage/resolve.txt)
#### API
@[ruby](resolve_usage.rb)
#### Image Descriptions
Specify each image at the beginning of a line via an *image description*, which has the form:
![*alt_text*]\(
*relative_file_path* |
*attributes*)
where:
* *alt_text* is the usual alt text for an HTML image.
* *relative_file_path* points to the file to be included.
* *attributes* specify image attributes. See [Image Attributes](#image-attributes) below.
##### Example Image Descriptions
@[code_block](resolve.md)
## Image Attributes
![html_icon](images/html.png | width=50)
This markdown helper enables HTML image attributes in GitHub markdown [image descriptions](https://github.github.com/gfm/#image-description).
(Actually, this README file itself is built using image attributes.)
Use the markdown helper to add image attributes in a markdown (.md) file.
### Usage
#### CLI
@[:code_block](../bin/usage/resolve.txt)
#### API
@[ruby](resolve_usage.rb)
#### Image Descriptions
Specify each image at the beginning of a line via an *image description*, which has the form:
![*alt_text*]\(
*relative_file_path* |
*attributes*)
where:
* *alt_text* is the usual alt text for an HTML image.
* *relative_file_path* points to the file to be included.
* *attributes* are whitespace-separated name-value pairs in the form *name*=
*value*. These are passed through to the generated img
HTML element.
##### Example Image Descriptions
@[code_block](resolve.md)
## What Should Be Next?
I have opened some enhancement Issues in the GitHub [MarkdownHelper](https://github.com/BurdetteLamar/MarkdownHelper) project:
* [Pagination](https://github.com/BurdetteLamar/MarkdownHelper/issues/40): series of markdown pages connected by prev/next navigation links.
* [Partial file inclusion](https://github.com/BurdetteLamar/MarkdownHelper/issues/38): including only specified lines from a file (instead of the whole file).
* [Ruby-entity inclusion](https://github.com/BurdetteLamar/MarkdownHelper/issues/39): like file inclusion, but including a Ruby class, module, or method.
* [File TOC](https://github.com/BurdetteLamar/MarkdownHelper/issues/36): table of contents of all headers in a markdown page.
* [Project TOC](https://github.com/BurdetteLamar/MarkdownHelper/issues/37): table of contents of all markdown pages in project.
Feel free to comment on any of these, or to add more Issues (enhancement or otherwise).