Constructor
new MarkdownNode(src, optionsopt)
A markdown node takes either an Abstract Syntax Tree (AST)
or a markdown string.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
src |
ast
|
string
|
The markdown string that we'll parse into an AST. | |
options |
JSON
|
<optional> |
Options to be passed into MarkdownNode |
Example
import mrk = require("mark-dom");
mrk("# Hello").get(); // Will return "# Hello"
Methods
get() → {String}
Returns the markdown string version of the node you're currently on.
- Source:
Returns:
- Type:
-
String
The String version of the CURRENT node we're on.
Example
// Returns "## Subheader"
mrk(`
# Hello
## Subheader
`).heading("## *").get();
getAll() → {String}
Returns the markdown string version of the entire AST of this piece of
markdown.
- Source:
Returns:
- Type:
-
String
The String version of the ENTIRE compiled Markdown AST.
heading(searchWordopt) → {MarkdownNode}
Gets a new MarkdownNode representing the first heading it finds.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
searchWord |
String
|
<optional> |
A string to search for in the heading. Can use wildcard * syntax. |
Examples
// Returns a MarkdownNode at the heading.
mrk("# Hello").heading("H*");
// Returns a MarkdownNode representing "# First"
mrk(`
# First
some text
# Second
other text
`).heading();
paragraph(searchWordopt) → {MarkdownNode}
Gets a new MarkdownNode representing the first paragraph it finds.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
searchWord |
String
|
<optional> |
A string to search for in the paragraph. Can use wildcard * syntax. |
Returns:
- Type:
-
MarkdownNode
Examples
// Returns a MarkdownNode at the paragraph.
mrk("Hello").paragraph("H*");
// Returns a MarkdownNode representing "First Paragraph"
mrk(`
# First
First Paragraph
# Second
Second Paragraph
`).paragraph();
search(type, searchWordopt)
Gets a new MarkdownNode representing an aribtary AST type.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
type |
String
|
||
searchWord |
String
|
<optional> |
A string to search for in the node. Can use wildcard * syntax. |
Example
// Returns "# Hello"
mrk().set("# Hello").search("# H*").getAll();
set(str) → {MarkdownNode}
Sets the current node's value to the str input
- Source:
Parameters:
Name | Type | Description |
---|---|---|
str |
String
|
Returns:
- Type:
-
MarkdownNode
setTable(array) → {MarkdownNode}
Create a markdown table from an array.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
array |
Array
|
Returns:
- Type:
-
MarkdownNode
table(searchWordopt) → {MarkdownNode}
Gets a new MarkdownNode representing the first paragraph it finds
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
searchWord |
String
|
<optional> |
A string to search for somewhere in the table. Can use wildcard * syntax. |
Returns:
- Type:
-
MarkdownNode
type() → {String}
Returns the type of the node you're currently on.
- Source:
Returns:
- Type:
-
String
the type of node you're currently on.
Examples
mrk("# Hello").heading().type(); // Returns "heading"
mark("Im a paragraph").paragraph().type(); // Returns "paragraph"
mrk("hello").type(); // Returns "root"
value() → {String}
Returns the value of the node you're on.
If get() returns the markdown string of where you're at, this
returns the actual value of where you're at.
- Source:
Returns:
- Type:
-
String
The string value of the node you're on.
Examples
mrk("# Hello I am header").value(); // Returns "Hello I am header"
var m = mrk("# Hello I am header");
const isTrue = m.get() != m.value(); // True