-
-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #172 from fnonnenmacher/markdown-exporter
Markdown Exporter (#159)
- Loading branch information
Showing
7 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
buildscript { | ||
dependencies { | ||
//for the markdown conversion | ||
classpath 'nl.jworks.markdown_to_asciidoc:markdown_to_asciidoc:1.0' | ||
} | ||
repositories { | ||
jcenter() | ||
} | ||
} | ||
|
||
//tag::exportMarkdown[] | ||
task exportMarkdown( | ||
description: 'exports all markdown files to AsciiDoc', | ||
group: 'docToolchain', | ||
type: Copy | ||
) { | ||
from srcDir | ||
|
||
include("**/*.md") //include only markdown files | ||
includeEmptyDirs = false | ||
rename(/(.+).md/, '$1.adoc') //rename all files from *.md to *.adoc | ||
filter(Markdown2AdocFilter) // convert the content of the files | ||
|
||
into targetDir | ||
} | ||
|
||
class Markdown2AdocFilter extends FilterReader { | ||
Markdown2AdocFilter(Reader input) { | ||
super(new StringReader(nl.jworks.markdown_to_asciidoc.Converter.convertMarkdownToAsciiDoc(input.text))) | ||
} | ||
} | ||
//end::exportMarkdown[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# exportMarkdown | ||
|
||
The *exportMarkdown* task can be used to include [markdown](http://markdown.de) files into the documentation. | ||
|
||
The task is scanning the directory `/src/docs` for markdown files (`*.md`) and converts them into AsciiDoc files. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
ifndef::imagesdir[:imagesdir: ../images] | ||
|
||
include::../../../build/docs/exportMarkdownDocs.adoc[] | ||
|
||
== Source | ||
|
||
.exportMarkdown.gradle | ||
[source,groovy] | ||
---- | ||
include::../../../scripts/exportMarkdown.gradle[tags=exportMarkdown] | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package docToolchain | ||
|
||
import org.gradle.testkit.runner.GradleRunner | ||
import spock.lang.Specification | ||
|
||
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS | ||
|
||
class ExportMarkdownSpec extends Specification { | ||
|
||
|
||
public static final File exportedMarkdownFile = new File('./build/docs/exportMarkdownDocs.adoc') | ||
|
||
void 'test conversion of sample markdown file'() { | ||
|
||
given: 'a clean the environment' | ||
exportedMarkdownFile.delete() | ||
|
||
when: 'executing the gradle task `exportMarkdown`' | ||
def result = GradleRunner.create() | ||
.withProjectDir(new File('.')) | ||
.withArguments('exportMarkdown') | ||
.build() | ||
|
||
then: 'the task has been successfully executed' | ||
result.task(":exportMarkdown").outcome == SUCCESS | ||
|
||
and: 'the AsciiDoc file has been created' | ||
exportedMarkdownFile.exists() | ||
|
||
and: 'its content is in AsciiDoc syntax' | ||
exportedMarkdownFile.text.startsWith('= exportMarkdown') | ||
} | ||
} |