When calling FamlParser.parse
, the result is an Abtract Syntax Tree (AST). There is a single root node:
{
children: [],
parent: null,
t: "Document"
} |
The exact members and their meaning depend on the value of t
(the node type). The root node always has a value of Document
, and it is the only node with that type. The parser differentiates between inline and block nodes.
General Properties
See the individual node type documentations for the exact meaning.
t
is the type of the node
parent
is the parent node of the current node - null
for the root Document
node
children
are child nodes of block nodes. This property does not exist on all node types.
inline_content
may exist on block nodes and indicates content that should be rendered inline within the block. This property does not exist on all node types.
c
is the content of inline nodes. This may be a string or an array of other inline nodes or may not exist at all.
string_content
is used by fenced code blocks to indicate that formatting needs to be kept.
start_column, start_line, end_line
indicate which part of the input text this block contains. This may not exactly match the input though because of normalizing line endings or spaces.
Internal Properties
Any property not documented in the individual node types is used by the parser to maintain state or the result of generic parser code. These undocumented properties are subject to change/removal without notice.
Block Node Types
Document
Exists exactly once, as the root element of the tree.
{
children: [ <Block Nodes> ],
parent: null,
t: "Document"
} |
Paragraph
Usually rendered as a <p>
tag. Can contain inline elements, but not other block elements.
{
inline_content: [
{ c: "Lorem Ipsum", t: "Str" },
{ t: "Linebreak" },
{ c: "Dolor Sic Amet!", t: "Str" }
]
parent: <ParentNode>,
t: "Paragraph"
} |
Header
Usually rendered as <h1>
through <h6>
. May contain multiple inline elements. level
is between 1 and 6.
{
inline_content: [
{ c: "This is ", t: "Str" },
{ c: "an emphasized", t: "Emph" },
{ c: " Header", t: "Str" },
],
level: 1,
parent: <ParentNode>,
t: "Header"
} |
BlockQuote
Usually rendered as <blockquote>
.
{
children: [
{
inline_content: [
{ c: "Lorem Ipsum", t: "Str" },
{ t: "Linebreak" },
{ c: "Dolor Sic Amet!", t: "Str" }
]
parent: <ParentNode>,
t: "Paragraph"
}
],
parent: <ParentNode>,
t: "BlockQuote"
} |
FencedCode
Rendered as a <pre>
with a <code>
element by default. info
is the optional CSS class name to be applied to the inner <code>
element and may be an empty string (which means not to apply a class). The actual content is contained in string_content
.
{
info: "ruby",
parent: <ParentNode>,
string_content: "puts 'Hello, World!'\nputs 'Example'"
t: "FencedCode"
} |
List
Either an <ul>
or <ol>
, depending on the list_data.type
which can be Bullet
or Ordered
. For Ordered
there is a list_data.start
property which indicates the start index. If this is not 1, the HTML Renderer will render <ol start="X">
. children
is an array of ListItem nodes.
// Unordered List
{
children: [ <Array of ListItem nodes> ],
list_data: {
type: "Bullet"
},
parent: <ParentNode>,
t: "List"
}
// Ordered List list_data
list_data: {
start: 1,
type: "Ordered"
} |
ListItem
Rendered as a <li>
. The children
can contain a variety of inline or block nodes.
{
children: [ <Block or Inline Nodes> ],
parent: <ParentNode>,
t: "ListItem"
} |
Inline Node Types
Str
A literal string that needs to be HTML Encoded.
{
c: "Lorem Ipsum Dolor Sic Amet",
t: "Str"
} |
Linebreak
Usually rendered as a <br/>
tag.
Emph
Usually rendered as a <em>
tag. The c
member is an array of other inline elements
{
c: [
{ c: "Lorem Ipsum", t: "Str" },
{ t: "Linebreak" },
{ c: "Dolor Sic Amet!", t: "Str" }
],
t: "Emph"
} |
Strong
Usually rendered as a <strong>
tag. The c
member is an array of other inline elements
{
c: [
{ c: "Lorem Ipsum", t: "Str" },
{ t: "Linebreak" },
{ c: "Dolor Sic Amet!", t: "Str" }
],
t: "Strong"
} |
Entity
A HTML Entity, usually rendered as-is.
Link
Usually rendered as <a href="https://github.com/mstum/faml" title="faml GitHub Page">A Link</a>
. title
may be be undefined if no title was given. label
is an array of inline elements because link labels may be formatted with faml markup.
{
destination: "https://github.com/mstum/faml",
label: [
{ c: "A Link", t: "Str" }
],
t: "Link",
titel: "faml GitHub Page"
} |
Code
This is an inline <code>
block.
{
c: "var foo = new bar()",
t: "Code"
} |