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.
See Daring Fireball for syntax basics.
This plugin makes use of the Pegdown and Remark libraries.
Use the following snippet
buildscript {
repositories {
jcenter()
maven { url 'http://dl.bintray.com/content/aalmiray/kordamp' }
}
dependencies {
classpath 'org.kordamp:markdown-gradle-plugin:0.1.1'
}
}
apply plugin: 'org.kordamp.gradle.markdown'
The plugin adds 2 tasks named markdownToHtml
and htmlToMarkdown
. These task expose
three properties as part of their configuration
- 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
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
.
- 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
Sources may have any of the following extensions in order to be discovered
- .html
Non html files will be copied "as is" to outputDir
.
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 getanemphasizedword
. You just getan_emphasized_word
. This is true no matter the character used (_
or*
), or for italics or bold.
markdown.hardwraps = true // Configuration
[hardwraps: true] // Custom Map
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.
markdown.autoLinks = true // Configuration
[autoLinks: true] // Custom Map
Auto Linking enables conversion of HTTP and HTTPS urls into links without explicit link generation.
Example Markdown:
http://gradle.org/
Example HTML:
<a href="http://gradle.org/">http://gradle.org/</a>
markdown.abbreviations = true // Configuration
[abbreviations: true] // Custom Map
Enables abbreviations are in the Markdown Extra style. These allow the Markdown
output to generate <abbr>
tags.
Example Markdown:
This is HTML
*[HTML]: Hyper-Text Markup Language
Example HTML:
This is <abbr title="Hyper-Text Markup Language">HTML</abbr>
markdown.definitionLists = true // Configuration
[definitionLists: true] // Custom Map
Enables <dl>
lists in the Markdown Extra style.
Example Markdown:
Gradle
: Gradle is build automation evolved.
Example HTML:
<dl>
<dt>Gradle</dt>
<dd>Gradle is build automation evolved.</dd>
</dl>
markdown.smartQuotes = true // Configuration
[smartQuotes: true] // Custom Map
markdown.smartPunctuation = true // Configuration
[smartPunctuation: true] // Custom Map
// or, for both use
markdown.smart = true // Configuration
[smart: true] // Custom Map
Enables conversion of simple quotes and punctuation into HTML entities and back
again, such as converting "Foo"
into “Foo”
, or ---
into —
.
markdown.fencedCodeBlocks = true // Configuration
[fencedCodeBlocks: true] // Custom Map
Allows the use of several tildes (~
) to delineate code blocks, instead of
forcing the users to indent each line four spaces.
Note: If enabled, all code blocks will use fences when converting HTML back into Markdown.
markdown.tables = true // Configuration
[tables: true] // Custom Map
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 ||
The all
option easily enables these items:
- Hardwraps
- Auto Links
- Abbreviations
- Definition Lists
- Smart Quotes
- Smart Punctuation
- Fenced Code Blocks
- Tables
markdown.removeHtml = true // Configuration
[removeHtml: true] // Custom Map
With this option enabled, all raw HTML will be removed when converting Markdown to HTML.
markdown.removeTables = true // Configuration
[removeTables: true] // Custom Map
Removes tables when converting HTML to Markdown, instead of leaving them as-is.
markdown.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.
markdown.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.
markdown.customizeRemark = { com.overzealous.remark.Options options -> ... }
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.
- Publish plugin to Gradle Plugin Portal
- First release.