Package groovy.markdown
Class MarkdownSlurper
java.lang.Object
groovy.markdown.MarkdownSlurper
Parses CommonMark Markdown into a
MarkdownDocument backed by nested lists and maps.
Usage:
def doc = new groovy.markdown.MarkdownSlurper().parseText('# Hello')
assert doc.headings[0].text == 'Hello'
GFM-style tables are supported via an optional extension. Call
enableTables(true) after adding
org.commonmark:commonmark-ext-gfm-tables to the runtime classpath.- Since:
- 6.0.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionenableTables(boolean enable) Enable GFM-style tables.Parses Markdown content from a file.parse(InputStream stream) Parses Markdown content from an input stream.Parses Markdown content from a reader.Parses Markdown content from a path.Parses Markdown text into aMarkdownDocument.
-
Constructor Details
-
MarkdownSlurper
public MarkdownSlurper()
-
-
Method Details
-
enableTables
Enable GFM-style tables. Requirescommonmark-ext-gfm-tableson the classpath.- Parameters:
enable- whether to enable table parsing- Returns:
- this slurper for chaining
- Throws:
MarkdownRuntimeException- ifenableis true but the extension jar is missing
-
parseText
Parses Markdown text into aMarkdownDocument.- Parameters:
md- the Markdown text to parse- Returns:
- the parsed document, or an empty document when the input is null or empty
-
parse
Parses Markdown content from a reader.- Parameters:
reader- the reader supplying Markdown content- Returns:
- the parsed document
-
parse
Parses Markdown content from an input stream. The caller remains responsible for closing the stream.- Parameters:
stream- the input stream supplying Markdown content- Returns:
- the parsed document
-
parse
Parses Markdown content from a file.- Parameters:
file- the file to read- Returns:
- the parsed document
- Throws:
IOException- if the file cannot be read
-
parse
Parses Markdown content from a path.- Parameters:
path- the path to read- Returns:
- the parsed document
- Throws:
IOException- if the path cannot be read
-