32markdown Module
32.1Overview
The markdown module provides measures to parse a text formatted in markdown syntax. To utilize it, import the markdown module using import function.
Below is an example to read a document written in Markdown format and then render its HTML text into a file.
import(markdown)
markdown.document('foo.md').render@html('foo.html')
markdown module consists of the following two module files:
markdown.gurd.. a binary module file that provides parser procedures.markdown.gura.. a script module file that renders parsed result in desired formats.
32.2Notes
- While Markdown format is disabled within tags, a text embraced by tags with a name begining with '@' can accept Markdown in it.
32.3Operator
markdown.document << function
32.4markdown.document Class
32.4.1Overview
The markdown.document class provides measures to parse a document written in Markdown format.
You can parse documents written in both string and stream using the following methods:
markdown.document#parse().. Parses document written in a string.markdown.document#read().. Parses document from a stream.
You can get the parsed result by inspecting a property markdown.document#root and its children that are markdown.item instances.
32.4.2Property
The markdown.document instance has following properties:
markdown.document#refs … iterator [read-only]iterator that returns referee items as markdown.item.
markdown.document#root … markdown.item [read-only]32.4.3Constructor
markdown.document(stream?:stream:r) {block?}markdown.document. If stream is specified, the content of the instance shall be initialized with the result of parsing the stream.
32.4.4Method
The markdown.document class provides following methods:
markdown.document#parse(str:string):voidmarkdown.document#read(stream:stream:r):voidmarkdown.document#render@console(colorFlag:boolean => true)Renders the content of markdown document to the console.
In default, it uses colors to highlight items. Specify the argument colorFlag with false to disable the coloring process.
markdown.document#render@html(out:stream:w, easyFormatFlag:boolean => true, captionIndex:boolean => false)Renders the content of markdown document in HTML format.
The result will be put out to the stream speicified by the argument out. If the argument is omitted, it will be put out to the standard output.
Specifying true to easyFormatFlag argument means it will generate an HTML with header tags. The default is true.
The argument captionIndex indicates whether caption indices are added to headers. The default is false.
markdown.document#render@toc() {block}32.5markdown.item Class
32.5.1Overview
The markdown.item class provides information about items that composes a Markdown document.
Below is a table of item type:
| Item Type | Explanation |
|---|---|
root |
container |
h1 |
container |
h2 |
container |
h3 |
container |
h4 |
container |
h5 |
container |
h6 |
container |
p |
container |
blockquote |
container |
em |
container |
strong |
container |
codeblock |
container |
ol |
container |
ul |
container |
li |
container |
line |
container |
a |
container |
img |
text |
text |
text |
code |
text |
entity |
text |
tag |
container/text |
hr |
no-content |
br |
no-content |
referee |
no-content |
32.5.2Property
The markdown.item instance has following properties:
markdown.item#align … symbol [read-only]`none, `left, `center, `right
markdown.item#attrs … string [read-only]markdown.item#children … iterator [read-only]markdown.item#text … string [read-only]markdown.item#title … string [read-only]markdown.item#type … symbol [read-only]markdown.item#url … string [read-only]32.5.3Method
The markdown.item classs provides following methods;
markdown.item#print(indent?:number):voidindent specifies an indentation level and is set to zero when omitted.