use_case.md
August 28, 2019 ยท View on GitHub
Include Code Block
Use file inclusion to include text as a code block.
File to Be Included
Here's a file containing code to be included:
hello.rb:
class HelloWorld
def initialize(name)
@name = name.capitalize
end
def sayHi
puts "Hello !"
end
end
Includer File
Here's a template file that includes it:
includer.md:
This file includes the code as a code block.
@[:code_block](hello.rb)
The treatment token :code_block specifies that the included text is to be treated as a code block.
Include Via markdown_helper
CLI
markdown_helper include --pristine includer.md included.md
(Option --pristine suppresses comment insertion.)
API
include.rb:
require 'markdown_helper'
# Option :pristine suppresses comment insertion.
markdown_helper = MarkdownHelper.new(:pristine => true)
markdown_helper.include('includer.md', 'included.md')
File with Inclusion
Here's the finished file with the included code block:
This file includes the code as a code block.
```hello.rb```:
```
class HelloWorld
def initialize(name)
@name = name.capitalize
end
def sayHi
puts "Hello !"
end
end
```
And here's the finished markdown, as rendered on this page:
This file includes the code as a code block.
hello.rb:
class HelloWorld
def initialize(name)
@name = name.capitalize
end
def sayHi
puts "Hello !"
end
end