This plugin provides a facility for converting Markdown into HTML, as well as
converting HTML back into Markdown. It is based on the grails-markdown
plugin by Ted Naleid.
plugins {
id 'org.kordamp.gradle.markdown' version '2.2.0'
}
Usage
The plugin adds 2 tasks named markdownToHtml and htmlToMarkdown. These task expose
three properties as part of their configuration
markdownToHtml
sourceDir - where the markdown sources are. Type: File. Default: src/markdown.
outputDir - where generated html go. Type: File. Default: $buildDir/gen-html.
configuration - a Map with further config tweaks. Explained in the next section.
inputEncoding - the file encoding used to read all files inside sourceDir.
outputEncoding - the file encoding used to write all files to outputDir.
parsingTimeout - how much time (ms) PegDown should wait whjen processint instructions. Defaults to 2000L
Sources may have any of the following extensions in order to be discovered
.md
.markdown
Non markdown files will be copied "as is" to outputDir.
htmlToMarkdown
sourceDir - where the html sources are. Type: File. Default: src/html.
outputDir - where generated markdown go. Type: File. Default: $buildDir/gen-markdown.
configuration - a Map with further config tweaks. Explained in the next section.
inputEncoding - the file encoding used to read all files inside sourceDir.
outputEncoding - the file encoding used to write all files to outputDir.
Sources may have any of the following extensions in order to be discovered
.html
Non html files will be copied "as is" to outputDir.
Configuration
The default configuration is almost 100% pure Markdown, with one caveat:
NOTE: The Markdown engine does not allow in-word emphasis.
This means that when you write an_emphasized_word, you don't get anemphasizedword.
You just get an_emphasized_word. This is true no matter the character used
(_ or *), or for italics or bold.
Markdown makes simple hardwraps a little difficult, requiring the user to write
two spaces at the end of a line to get a linebreak. This is convenient when
writing in a terminal, but inconvenient if your editor handles soft-wraps internally.
Enabling hardwraps means that all linebreaks are kept.
If tables are allowed, you can create tables using Markdown Extra or
Multimarkdown syntax. This also converts tables from HTML back into clean,
easy-to-read plain text tables.
An example in Markdown:
| | Grouping ||
| First Header | Second Header | Third Header |
|:------------ |:-------------:| ------------:|
| Content | *Long Cell* ||
| Content | **Cell** | Cell |
| New Section | More | Data |
| And more | And more ||
Removes tables when converting HTML to Markdown, instead of leaving them as-is.
Base URI
markdownToHtml.baseUri = 'http://example.com'
You can override the default base URI (which is determined by your configuration).
The base URI is used when converting relative links.
Setting it to false will simply remove relative links.
Customize Pegdown
markdownToHtml.customizePegdown = { int extensions -> ... }
Allows for customization of the Pegdown extensions before creating a
PegdownProcessor using a closure. This closure will be called at the time the
PegdownProcessor is first needed, not necessarily at startup.
Allows for customization of the Remark Options before creating a Remark using
a closure. This closure will be called at the time the Remark is first needed,
not necessarily at startup.
请发表评论