Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 53 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,48 @@
# Grails Markdown
# 🧩 Grails Markdown

A Grails plugin to provide tag library and service support for markdown. It can be used both for converting markdown into HTML, as well as converting HTML back into markdown.
[![Maven Central](https://img.shields.io/maven-metadata/v.svg?metadataUrl=https://repo1.maven.org/maven2/org/grails/plugins/grails-markdown/maven-metadata.xml&label=maven-central)](https://central.sonatype.com/artifact/org.grails.plugins/grails-markdown)
[![CI](https://github.com/grails-plugins/grails-markdown/actions/workflows/gradle.yml/badge.svg?event=push)](https://github.com/grails-plugins/grails-markdown/actions/workflows/gradle.yml)


A Grails plugin to provide tag library and service support for Markdown. It can be used both for converting Markdown
into HTML, and converting HTML back into Markdown.

See [Daring Fireball][] for syntax basics.

## Installation
```groovy
dependencies {
implemenation: "org.grails.plugins:grails-markdown:4.0.0"
}
```
## Tag Usage

The tag library provides simple usage to convert markdown to HTML on-the-fly.
The tag library provides simple usage to convert Markdown to HTML on-the-fly.

### Tag Body

You can either use the body of the tag to hold the markdown:

<markdown:renderHtml>This is a *test* of markdown.</markdown:renderHtml>

You can either use the body of the tag to hold the Markdown:
```html
<markdown:renderHtml>This is a *test* of Markdown.</markdown:renderHtml>
```
renders:

<p>This is a <em>test</em> of markdown.</p>

```html
<p>This is a <em>test</em> of Markdown.</p>
```
### "text" Attribute

<markdown:renderHtml text="Yet **another** markdown test."/>

```html
<markdown:renderHtml text="Yet **another** Markdown test."/>
```
renders:

<p>Yet <strong>another</strong> markdown test.</p>

```html
<p>Yet <strong>another</strong> Markdown test.</p>
```
### "template" Attribute

You can also use a template that contains the markdown (which is useful for storing documentation):

<markdown:renderHtml template="readme" />

You can also use a template that contains the Markdown (which is useful for storing documentation):
```html
<markdown:renderHtml template="readme" />
```
## String Extensions

The plugin also adds `markdownToHtml()` and `htmlToMarkdown()` methods to the String class.
Expand All @@ -42,44 +53,41 @@ There's also a `markdownService` that provides more fine-grained control. It has

### Convert Markdown to HTML - `markdown(text, [config])`

This method converts markdown into HTML using the [Flexmark][] library. You can optionally provide an alternate configuration to use instead of the default. (See below for configuration options.)
This method converts Markdown into HTML using the [Flexmark][] library. You can optionally provide an alternate configuration to use instead of the default. (See below for configuration options.)

### Convert HTML to Markdown - `htmlToMarkdown(text, [baseUri], [config])`

This method converts HTML (say, from a rich text input) back into Markdown. You can provide an alternate base URI, and an alternate configuration. (See below for configuration options.)

### Sanitize Markdown - `sanitize(text, [config])`

This method allows you to clean up markdown provided from untrusted sources. It's mostly useful if you are allowing the user to include raw HTML with their markdown.

This method allows you to clean up Markdown provided from untrusted sources. It's mostly useful if you are allowing the user to include raw HTML with their Markdown.

## Dependecies

This plugin makes use of the [Flexmark][] and [Pegdown][] (for compatibility with previous versions) libraries.


## Thanks

Thanks to @dani_latorre for the patch adding markdownToHtml functionality on the String class.
Thanks to @dani_latorre for the patch adding `markdownToHtml` functionality on the String class.


# Configuration

The `grails-markdown` application has a variety of options that you can configure either as a general option, in
`Config.groovy`, or per-usage by providing a `Map` of options when using the service directly.

Changing the configuration simultaneously configures both the conversion *to* HTML, as well as converting HTML
*back* into Markdown.
Changing the configuration simultaneously configures both the conversion *to* HTML, and converting HTML *back* into Markdown.

### Hardwraps
### Hard wraps

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
Markdown makes simple hard wraps 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.
Enabling hard wraps means that all linebreaks are kept.

### Auto Links

Expand All @@ -93,9 +101,9 @@ Example Markdown:
http://www.google.com/

Example HTML:

<a href="http://www.google.com/">http://www.google.com/</a>

```html
<a href="https://www.google.com/">https://www.google.com/</a>
```
### Abbreviations

markdown.abbreviations = true // Configuration
Expand All @@ -111,9 +119,9 @@ Example Markdown:
*[HTML]: Hyper-Text Markup Language

Example HTML:

This is <abbr title="Hyper-Text Markup Language">HTML</abbr>

```html
This is <abbr title="Hyper-Text Markup Language">HTML</abbr>
```
### Definition Lists

markdown.definitionLists = true // Configuration
Expand All @@ -127,12 +135,12 @@ Example Markdown:
: A rapid web-application development platform for the JVM.

Example HTML:

<dl>
<dt>Grails</dt>
<dd>A rapid web-application development platform for the JVM.</dd>
</dl>

```html
<dl>
<dt>Grails</dt>
<dd>A rapid web-application development platform for the JVM.</dd>
</dl>
```
### Smart Quotes, Smart Punctation

markdown.smartQuotes = true // Configuration
Expand Down Expand Up @@ -210,9 +218,9 @@ With this option enabled, all raw HTML will be removed when converting Markdown
Removes tables when converting HTML to Markdown, instead of leaving them as-is.

### Base URI

markdown.baseUri = 'http://example.com'

```properties
markdown.baseUri = 'https://example.com'
```
You can override the default base URI (which is determined by your configuration). The base URI is used
when converting relative links.

Expand Down
3 changes: 1 addition & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
projectVersion=4.0.1-SNAPSHOT
grailsVersion=7.0.5
gradleWrapperVersion=8.14.3
grailsVersion=7.2.1
customUserDataVersion=2.2.1
develocityVersion=4.0
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
6 changes: 3 additions & 3 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading