Compare commits
165 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6afe41b7a9 | ||
|
|
f5aadc2319 | ||
|
|
0730b94c24 | ||
|
|
59c63e8ac0 | ||
|
|
c404740bf1 | ||
|
|
23c72721ad | ||
|
|
67b5698a16 | ||
|
|
6662eb6e9d | ||
|
|
d712b615d1 | ||
|
|
393fd48d2f | ||
|
|
e5aea526cd | ||
|
|
83d3ee5a50 | ||
|
|
fec017886f | ||
|
|
6ee11e2876 | ||
|
|
4ba4b962e5 | ||
|
|
71710a4ba6 | ||
|
|
f8bc0d38e7 | ||
|
|
1ae72d99d1 | ||
|
|
7b8c5e76bf | ||
|
|
9e03544f8c | ||
|
|
c246352b59 | ||
|
|
962d934f2c | ||
|
|
706eeb3d64 | ||
|
|
d081d64fc5 | ||
|
|
05f217d2a4 | ||
|
|
539c5e5191 | ||
|
|
c53d38c148 | ||
|
|
21b1568dfc | ||
|
|
9bc01c9665 | ||
|
|
f7e84d840f | ||
|
|
6c86494091 | ||
|
|
7caa2c5894 | ||
|
|
e37627e92f | ||
|
|
bf0b218616 | ||
|
|
7583d369e0 | ||
|
|
4dd49e0fb8 | ||
|
|
a483e7e713 | ||
|
|
e81c273828 | ||
|
|
f5999f31d7 | ||
|
|
56f5db0634 | ||
|
|
5758aa056a | ||
|
|
15dfd7edca | ||
|
|
48127855f6 | ||
|
|
f52ec1a63c | ||
|
|
2a5d9a4e5c | ||
|
|
60b73ac3e9 | ||
|
|
81ad4f78dd | ||
|
|
0e6620260b | ||
|
|
72bc8134c8 | ||
|
|
78f0629514 | ||
|
|
cc4a5b729b | ||
|
|
ca172a2cd7 | ||
|
|
e7f52fe7a4 | ||
|
|
6bb076e1b6 | ||
|
|
0c056c7b87 | ||
|
|
0e87a0a6f6 | ||
|
|
c697fde3d1 | ||
|
|
cd152f9154 | ||
|
|
fd72686689 | ||
|
|
599b0857c4 | ||
|
|
60000737c0 | ||
|
|
5db9da3f11 | ||
|
|
90dd731b4c | ||
|
|
ef9d453ccf | ||
|
|
32cd13e379 | ||
|
|
7bcc6dbab0 | ||
|
|
14184423b9 | ||
|
|
f527e33264 | ||
|
|
7e0d5bcb31 | ||
|
|
9ce6fc6a80 | ||
|
|
4cac8a5d3b | ||
|
|
495b8dd8af | ||
|
|
e7bdd0774d | ||
|
|
935ab9e4e2 | ||
|
|
7895b8008d | ||
|
|
b00a7f4ecf | ||
|
|
cd8074a78f | ||
|
|
c8fc1e0fdc | ||
|
|
2dd33a73ec | ||
|
|
9a70f7b668 | ||
|
|
71dead5b52 | ||
|
|
3509f735e3 | ||
|
|
d8431b4cc5 | ||
|
|
9cb1e4d1d4 | ||
|
|
e43e4f15da | ||
|
|
b7bdb1aea3 | ||
|
|
8b6694d789 | ||
|
|
f45d2f3f6e | ||
|
|
85a98f2fbf | ||
|
|
d46f784b78 | ||
|
|
c9d7f701e7 | ||
|
|
913b100f6b | ||
|
|
689505e0d7 | ||
|
|
038edb8d94 | ||
|
|
dddd5fc75c | ||
|
|
1596fd5daf | ||
|
|
0666af6e1f | ||
|
|
8413192332 | ||
|
|
1e43d3a140 | ||
|
|
778e8bf4af | ||
|
|
8c7015757f | ||
|
|
c69948c78a | ||
|
|
52639d9907 | ||
|
|
bbb957c91d | ||
|
|
80ce77826e | ||
|
|
04fb517fa0 | ||
|
|
3c4ccc8eae | ||
|
|
4c1a64b20c | ||
|
|
577c0a4f94 | ||
|
|
f3d797c1a9 | ||
|
|
bff7be0714 | ||
|
|
3d31f71f69 | ||
|
|
9f4d384221 | ||
|
|
730d4bfc19 | ||
|
|
d26789dd8b | ||
|
|
60cba6d2b8 | ||
|
|
882c673a0e | ||
|
|
8097b3ad21 | ||
|
|
260dc04a61 | ||
|
|
4719827fac | ||
|
|
050f600598 | ||
|
|
8233565b6b | ||
|
|
337c8ba403 | ||
|
|
5b5a58ee7f | ||
|
|
3799cf362c | ||
|
|
c6d9d074cd | ||
|
|
2b4e085de0 | ||
|
|
14652f7d0f | ||
|
|
9077a1d422 | ||
|
|
6ef0f8d28c | ||
|
|
732eeca873 | ||
|
|
11dfce66a5 | ||
|
|
517504a030 | ||
|
|
ba6126087d | ||
|
|
b7187f4d83 | ||
|
|
1d62c72512 | ||
|
|
885a43fa89 | ||
|
|
1d06f41be8 | ||
|
|
816df10aca | ||
|
|
ded602de20 | ||
|
|
ba7089cf05 | ||
|
|
7d8fb9e494 | ||
|
|
c48ed138fd | ||
|
|
ff085c43f7 | ||
|
|
c7fb29902f | ||
|
|
51a1eb2805 | ||
|
|
0c136c2987 | ||
|
|
74bd2b0d2e | ||
|
|
48c48ba56b | ||
|
|
6293b6a996 | ||
|
|
6093d4ab92 | ||
|
|
119abf008d | ||
|
|
609dcbc7d5 | ||
|
|
4e61063106 | ||
|
|
b7cad8a7c8 | ||
|
|
97b068150d | ||
|
|
c1327e6b90 | ||
|
|
68c101fced | ||
|
|
02ea0f4e54 | ||
|
|
3933836290 | ||
|
|
9471093dce | ||
|
|
15a96a7338 | ||
|
|
e6dc1b63d0 | ||
|
|
1dd8dd2d25 | ||
|
|
2657b03de0 |
@@ -1,7 +1,12 @@
|
||||
language: java
|
||||
jdk:
|
||||
- oraclejdk7
|
||||
- oraclejdk8
|
||||
before_install:
|
||||
- chmod +x gradlew
|
||||
after_success:
|
||||
- ./gradlew jacocoTestReport coveralls
|
||||
- ./gradlew artifactoryPublish -PbintrayUsername="${BINTRAY_USER}" -PbintrayApiKey="${BINTRAY_KEY}"
|
||||
env:
|
||||
global:
|
||||
- secure: Gw8S2a4VumGXAWAmGAh0jOU3WxiG54mKPEI/XZVc+CjcYyb5MtcgzDi0snmfXOAcjME2vJDqi+6tYF8jjQFkb2Tm5qCSVZxbRPeyPv8d9lJL2ZIDpz7TAgBiWJiJmVMFjo0FGzWp7csJwl1KMJUlH18Sz4tgmLA4YgxoLf70Gtk=
|
||||
- secure: CIcQiSraUwXtbE3dAZ61xITqYL4kORjN37NfDz747ceaFn4u4Mui7dJ7k8GhujW3Cm/N8NalJ/MwlbK0sHIv0bGmi/CNwn15xE2ymJXoSHEihAUiKm2ql6k/hHp7T5LkUafLWbrIGQc4ch4jJRqsNaK1ouLpZLTzHromiiQZXZw=
|
||||
|
||||
27
README.adoc
27
README.adoc
@@ -1,13 +1,13 @@
|
||||
= MarkupDocBuilder
|
||||
:author: Robert Winkler
|
||||
:version: 0.1.2
|
||||
:version: 1.1.1
|
||||
:hardbreaks:
|
||||
|
||||
image:https://travis-ci.org/RobWin/markup-document-builder.svg["Build Status", link="https://travis-ci.org/RobWin/markup-document-builder"] image:https://coveralls.io/repos/RobWin/markup-document-builder/badge.svg["Coverage Status", link="https://coveralls.io/r/RobWin/markup-document-builder"] image:https://api.bintray.com/packages/robwin/maven/markup-document-builder/images/download.svg[link="https://bintray.com/robwin/maven/markup-document-builder/_latestVersion"] image:http://img.shields.io/badge/license-ASF2-blue.svg["Apache License 2", link="http://www.apache.org/licenses/LICENSE-2.0.txt"]
|
||||
image:https://travis-ci.org/Swagger2Markup/markup-document-builder.svg?branch=master["Build Status", link="https://travis-ci.org/Swagger2Markup/markup-document-builder"] image:https://coveralls.io/repos/Swagger2Markup/markup-document-builder/badge.svg["Coverage Status", link="https://coveralls.io/r/Swagger2Markup/markup-document-builder"] image:https://api.codacy.com/project/badge/grade/c56a372454164f21b1b2eec8eb48b370["Codacy code quality", link="https://www.codacy.com/app/robwin/markup-document-builder"] image:https://api.bintray.com/packages/swagger2markup/Maven/io.github.swagger2markup%3Amarkup-document-builder/images/download.svg[link="https://bintray.com/swagger2markup/Maven/io.github.swagger2markup%3Amarkup-document-builder/_latestVersion"] image:http://img.shields.io/badge/license-ASF2-blue.svg["Apache License 2", link="http://www.apache.org/licenses/LICENSE-2.0.txt"] image:https://img.shields.io/badge/Twitter-rbrtwnklr-blue.svg["Twitter", link="https://twitter.com/rbrtwnklr"]
|
||||
|
||||
== Overview
|
||||
|
||||
This project is a Markup document builder (AsciiDoc and Markdown). The primary goal of this project is to simplify the creation of Markup documents.
|
||||
This project is a Markup document builder (AsciiDoc, Markdown and ConfluenceWiki). The primary goal of this project is to simplify the creation of Markup documents. The builder is used by https://github.com/RobWin/swagger2markup[swagger2markup].
|
||||
|
||||
The project requires at least JDK 7.
|
||||
|
||||
@@ -17,7 +17,7 @@ The project is published in JCenter and Maven Central.
|
||||
|
||||
==== Maven
|
||||
|
||||
[source,xml]
|
||||
[source,xml, subs="specialcharacters,attributes"]
|
||||
----
|
||||
<repositories>
|
||||
<repository>
|
||||
@@ -29,23 +29,22 @@ The project is published in JCenter and Maven Central.
|
||||
<url>http://jcenter.bintray.com</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.github.robwin</groupId>
|
||||
<groupId>io.github.swagger2markup</groupId>
|
||||
<artifactId>markup-document-builder</artifactId>
|
||||
<version>0.1.2</version>
|
||||
<version>{version}</version>
|
||||
</dependency>
|
||||
----
|
||||
|
||||
==== Gradle
|
||||
|
||||
[source,groovy]
|
||||
[source,groovy, subs="attributes"]
|
||||
----
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
compile "io.github.robwin:markup-document-builder:0.1.2"
|
||||
compile "io.github.swagger2markup:markup-document-builder:{version}"
|
||||
----
|
||||
|
||||
=== Using MarkupDocBuilder
|
||||
@@ -113,3 +112,13 @@ You can generate your PDF or HTML documentation via https://github.com/asciidoct
|
||||
|
||||
image::images/asciidoc_html.jpg[asciidoc_html]
|
||||
|
||||
== License
|
||||
|
||||
Copyright 2015 Robert Winkler
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
|
||||
|
||||
@@ -5,3 +5,25 @@
|
||||
|
||||
=== Version 0.1.1
|
||||
* Signed jar files
|
||||
|
||||
=== Version 0.1.2
|
||||
* Removed logback from compile dependency
|
||||
|
||||
=== Version 0.1.3
|
||||
* Removed commons.io from compile dependency
|
||||
|
||||
=== Version 0.1.4
|
||||
* Fixed SECTION_TITLE_LEVEL3 in Markdown enum
|
||||
|
||||
=== Version 0.1.5
|
||||
* Added SECTION_TITLE_LEVEL4
|
||||
|
||||
== Version 1.1.0
|
||||
* Changed bold to ** and italic to __ so that special chars in the text are possible
|
||||
|
||||
== Version 1.1.1
|
||||
* Added a method to add page breaks.
|
||||
|
||||
== Version 1.1.2
|
||||
* Improve code blocks in markdown
|
||||
|
||||
|
||||
74
build.gradle
74
build.gradle
@@ -4,33 +4,29 @@ buildscript {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.2'
|
||||
classpath 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.6'
|
||||
classpath 'io.spring.gradle:dependency-management-plugin:0.3.1.RELEASE'
|
||||
classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.3'
|
||||
classpath 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.11'
|
||||
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.0.1'
|
||||
classpath 'org.asciidoctor:asciidoctorj:1.5.2'
|
||||
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
|
||||
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
|
||||
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.0.0"
|
||||
}
|
||||
}
|
||||
description = 'A Markup (Markdown, AsciiDoc) document builder'
|
||||
version = '0.1.2'
|
||||
group = 'io.github.robwin'
|
||||
version = '1.1.2'
|
||||
group = 'io.github.swagger2markup'
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'org.asciidoctor.convert'
|
||||
apply plugin: 'jacoco'
|
||||
apply plugin: 'com.github.kt3k.coveralls'
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
apply plugin: 'com.jfrog.bintray'
|
||||
apply from: 'gradle/publishing.gradle'
|
||||
apply from: 'gradle/coverage.gradle'
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
sourceCompatibility = "1.7"
|
||||
targetCompatibility = "1.7"
|
||||
sourceCompatibility = "1.8"
|
||||
targetCompatibility = "1.8"
|
||||
options.deprecation = true
|
||||
options.encoding = 'UTF-8'
|
||||
options.compilerArgs << "-Xlint:unchecked"
|
||||
options.compilerArgs << "-Xdoclint:none"
|
||||
}
|
||||
|
||||
repositories {
|
||||
@@ -39,32 +35,17 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'commons-io:commons-io'
|
||||
compile 'ch.qos.logback:logback-classic'
|
||||
testCompile 'junit:junit'
|
||||
}
|
||||
|
||||
dependencyManagement {
|
||||
dependencies {
|
||||
"commons-io:commons-io" "2.4"
|
||||
"ch.qos.logback:logback-classic" "1.1.2"
|
||||
"junit:junit" "4.11"
|
||||
}
|
||||
}
|
||||
|
||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
classifier = 'sources'
|
||||
from sourceSets.main.allSource
|
||||
}
|
||||
|
||||
task javadocJar(type: Jar, dependsOn: javadoc) {
|
||||
classifier = 'javadoc'
|
||||
from javadoc.destinationDir
|
||||
}
|
||||
|
||||
artifacts {
|
||||
archives sourcesJar
|
||||
archives javadocJar
|
||||
compile 'org.slf4j:slf4j-api:1.7.18'
|
||||
//compile 'org.apache.commons:commons-collections4:4.1'
|
||||
compile 'org.apache.commons:commons-lang3:3.4'
|
||||
compile "commons-io:commons-io:2.4"
|
||||
compile "commons-codec:commons-codec:1.10"
|
||||
compile "nl.jworks.markdown_to_asciidoc:markdown_to_asciidoc:1.0"
|
||||
testCompile 'junit:junit:4.11'
|
||||
testCompile 'io.github.robwin:assertj-diff:0.1.1'
|
||||
testCompile "org.mockito:mockito-core:1.9.5"
|
||||
testCompile 'ch.qos.logback:logback-classic:1.1.6'
|
||||
testCompile 'io.github.robwin:assertj-diff:0.1.1'
|
||||
}
|
||||
|
||||
asciidoctor {
|
||||
@@ -78,21 +59,10 @@ asciidoctor {
|
||||
sourceDir "build/tmp"
|
||||
}
|
||||
|
||||
jacocoTestReport {
|
||||
reports {
|
||||
xml.enabled = true // coveralls plugin depends on xml format report
|
||||
html.enabled = true
|
||||
}
|
||||
}
|
||||
|
||||
tasks.coveralls {
|
||||
dependsOn 'check'
|
||||
}
|
||||
|
||||
tasks.asciidoctor {
|
||||
dependsOn 'check'
|
||||
}
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
gradleVersion = '2.2.1'
|
||||
gradleVersion = '4.3.1'
|
||||
}
|
||||
13
gradle/coverage.gradle
Normal file
13
gradle/coverage.gradle
Normal file
@@ -0,0 +1,13 @@
|
||||
apply plugin: 'jacoco'
|
||||
apply plugin: 'com.github.kt3k.coveralls'
|
||||
|
||||
jacocoTestReport {
|
||||
reports {
|
||||
xml.enabled = true // coveralls plugin depends on xml format report
|
||||
html.enabled = true
|
||||
}
|
||||
}
|
||||
|
||||
tasks.coveralls {
|
||||
dependsOn 'check'
|
||||
}
|
||||
@@ -1,24 +1,44 @@
|
||||
import java.text.SimpleDateFormat
|
||||
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'com.jfrog.bintray'
|
||||
apply plugin: "com.jfrog.artifactory"
|
||||
|
||||
Date buildTimeAndDate = new Date()
|
||||
ext {
|
||||
buildDate = new SimpleDateFormat('yyyy-MM-dd').format(buildTimeAndDate)
|
||||
buildTime = new SimpleDateFormat('HH:mm:ss.SSSZ').format(buildTimeAndDate)
|
||||
projectUrl = 'https://github.com/Swagger2Markup/markup-document-builder'
|
||||
licenseUrl = 'https://github.com/Swagger2Markup/markup-document-builder/blob/master/LICENSE.txt'
|
||||
scmUrl = 'https://github.com/Swagger2Markup/markup-document-builder.git'
|
||||
issuesUrl = 'https://github.com/Swagger2Markup/markup-document-builder/issues'
|
||||
}
|
||||
|
||||
def projectArtifactId = 'markup-document-builder'
|
||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
classifier = 'sources'
|
||||
from sourceSets.main.allSource
|
||||
}
|
||||
|
||||
task javadocJar(type: Jar, dependsOn: javadoc) {
|
||||
classifier = 'javadoc'
|
||||
from javadoc.destinationDir
|
||||
}
|
||||
|
||||
artifacts {
|
||||
archives sourcesJar
|
||||
archives javadocJar
|
||||
}
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes(
|
||||
'Built-By': 'Robert Winkler',
|
||||
'Created-By': System.properties['java.version'] + " (" + System.properties['java.vendor'] + " " + System.properties['java.vm.version'] + ")",
|
||||
'Build-Date': project.buildDate,
|
||||
'Build-Time': project.buildTime,
|
||||
'Specification-Title': projectArtifactId,
|
||||
'Specification-Version': project.version,
|
||||
'Implementation-Title': projectArtifactId,
|
||||
'Implementation-Version': project.version
|
||||
'Built-With': "gradle-${project.getGradle().getGradleVersion()}, groovy-${GroovySystem.getVersion()}",
|
||||
'Build-Time': "${new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")}",
|
||||
'Specification-Title': "${project.name}",
|
||||
'Specification-Version': project.version.toString(),
|
||||
'Implementation-Title': "${project.name}",
|
||||
'Implementation-Version': project.version.toString()
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -29,35 +49,6 @@ if (!project.hasProperty('gpgPassphrase')) ext.gpgPassphrase = ''
|
||||
if (!project.hasProperty('ossUser')) ext.ossUser = ''
|
||||
if (!project.hasProperty('ossPassword')) ext.ossPassword = ''
|
||||
|
||||
bintray {
|
||||
user = project.bintrayUsername
|
||||
key = project.bintrayApiKey
|
||||
dryRun = false //Whether to run this as dry-run, without deploying
|
||||
publish = true //If version should be auto published after an upload
|
||||
publications = ['mavenJava']
|
||||
pkg {
|
||||
repo = 'maven'
|
||||
name = 'markup-document-builder'
|
||||
websiteUrl = 'https://github.com/RobWin/markup-document-builder'
|
||||
issueTrackerUrl = 'https://github.com/RobWin/markup-document-builder/issues'
|
||||
vcsUrl = 'https://github.com/RobWin/markup-document-builder.git'
|
||||
desc = 'A Markup (Markdown, AsciiDoc) document builder.'
|
||||
licenses = ['Apache-2.0']
|
||||
version {
|
||||
vcsTag = project.version
|
||||
gpg {
|
||||
sign = true //Determines whether to GPG sign the files. The default is false
|
||||
passphrase = project.gpgPassphrase //Optional. The passphrase for GPG signing'
|
||||
}
|
||||
mavenCentralSync {
|
||||
sync = true //Optional (true by default). Determines whether to sync the version to Maven Central.
|
||||
user = ossUser //OSS user token
|
||||
password = ossPassword //OSS user password
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
@@ -74,17 +65,17 @@ publishing {
|
||||
it.scope*.value = 'compile'
|
||||
}
|
||||
|
||||
root.appendNode('name', 'markup-document-builder')
|
||||
root.appendNode('name', project.name)
|
||||
root.appendNode('packaging', 'jar')
|
||||
root.appendNode('url', 'https://github.com/RobWin/markup-document-builder')
|
||||
root.appendNode('description', 'A Markup (Markdown, AsciiDoc) document builder.')
|
||||
root.appendNode('url', projectUrl)
|
||||
root.appendNode('description', project.description)
|
||||
|
||||
def license = root.appendNode('licenses').appendNode('license')
|
||||
license.appendNode('name', 'Apache-2.0')
|
||||
license.appendNode('url', 'https://github.com/RobWin/markup-document-builder/blob/master/LICENSE.txt')
|
||||
license.appendNode('url', licenseUrl)
|
||||
license.appendNode('distribution', 'repo')
|
||||
|
||||
root.appendNode('scm').appendNode('url', 'https://github.com/RobWin/markup-document-builder.git')
|
||||
root.appendNode('scm').appendNode('url', scmUrl)
|
||||
|
||||
def developers = root.appendNode('developers')
|
||||
devs.each {
|
||||
@@ -98,3 +89,63 @@ publishing {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bintray {
|
||||
user = project.bintrayUsername
|
||||
key = project.bintrayApiKey
|
||||
dryRun = false //Whether to run this as dry-run, without deploying
|
||||
publish = true //If version should be auto published after an upload
|
||||
publications = ['mavenJava']
|
||||
pkg {
|
||||
repo = 'Maven'
|
||||
name = 'io.github.swagger2markup:markup-document-builder'
|
||||
userOrg = 'swagger2markup'
|
||||
websiteUrl = projectUrl
|
||||
issueTrackerUrl = issuesUrl
|
||||
vcsUrl = scmUrl
|
||||
desc = rootProject.description
|
||||
licenses = ['Apache-2.0']
|
||||
version {
|
||||
vcsTag = rootProject.version
|
||||
gpg {
|
||||
sign = true //Determines whether to GPG sign the files. The default is false
|
||||
passphrase = project.gpgPassphrase //Optional. The passphrase for GPG signing'
|
||||
}
|
||||
mavenCentralSync {
|
||||
sync = true //Optional (true by default). Determines whether to sync the version to Maven Central.
|
||||
user = ossUser //OSS user token
|
||||
password = ossPassword //OSS user password
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
artifactory {
|
||||
contextUrl = 'https://oss.jfrog.org'
|
||||
resolve {
|
||||
repository {
|
||||
repoKey = 'libs-release'
|
||||
}
|
||||
}
|
||||
publish {
|
||||
repository {
|
||||
repoKey = 'oss-snapshot-local' //The Artifactory repository key to publish to
|
||||
//when using oss.jfrog.org the credentials are from Bintray. For local build we expect them to be found in
|
||||
//~/.gradle/gradle.properties, otherwise to be set in the build server
|
||||
username = project.hasProperty('bintrayUsername') ? project.bintrayUsername : System.getenv('BINTRAY_USER')
|
||||
password = project.hasProperty('bintrayApiKey') ? project.bintrayApiKey : System.getenv('BINTRAY_KEY')
|
||||
}
|
||||
defaults {
|
||||
publications('mavenJava')
|
||||
}
|
||||
}
|
||||
if (System.properties['https.proxyHost']) {
|
||||
clientConfig.proxy.host = System.properties['https.proxyHost']
|
||||
clientConfig.proxy.port = System.properties['https.proxyPort'].toInteger()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
tasks.artifactoryPublish {
|
||||
dependsOn 'check'
|
||||
}
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
||||
#Thu Feb 19 15:49:46 CET 2015
|
||||
#Mon Dec 04 10:31:36 CET 2017
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3.1-all.zip
|
||||
|
||||
74
gradlew
vendored
Normal file → Executable file
74
gradlew
vendored
Normal file → Executable file
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
#!/usr/bin/env sh
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
@@ -6,12 +6,30 @@
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
@@ -30,6 +48,7 @@ die ( ) {
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
@@ -40,31 +59,11 @@ case "`uname`" in
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
# For Cygwin, ensure paths are in UNIX format before anything is touched.
|
||||
if $cygwin ; then
|
||||
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
|
||||
fi
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >&-
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >&-
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
@@ -90,7 +89,7 @@ location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
@@ -114,6 +113,7 @@ fi
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
@@ -154,11 +154,19 @@ if $cygwin ; then
|
||||
esac
|
||||
fi
|
||||
|
||||
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
|
||||
function splitJvmOpts() {
|
||||
JVM_OPTS=("$@")
|
||||
# Escape application args
|
||||
save ( ) {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
|
||||
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
|
||||
APP_ARGS=$(save "$@")
|
||||
|
||||
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
|
||||
14
gradlew.bat
vendored
14
gradlew.bat
vendored
@@ -8,14 +8,14 @@
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
@@ -46,10 +46,9 @@ echo location of your Java installation.
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windowz variants
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
if "%@eval[2+2]" == "4" goto 4NT_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
@@ -60,11 +59,6 @@ set _SKIP=2
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
goto execute
|
||||
|
||||
:4NT_args
|
||||
@rem Get arguments from the 4NT Shell from JP Software
|
||||
set CMD_LINE_ARGS=%$
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
package io.github.robwin.markup.builder;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public abstract class AbstractMarkupDocBuilder implements MarkupDocBuilder {
|
||||
|
||||
protected StringBuilder documentBuilder = new StringBuilder();
|
||||
protected String newLine = System.getProperty("line.separator");
|
||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
protected void documentTitle(Markup markup, String title){
|
||||
documentBuilder.append(markup).append(title).append(newLine).append(newLine);
|
||||
}
|
||||
|
||||
protected void documentTitleWithAttributes(Markup markup, String title){
|
||||
documentBuilder.append(markup).append(title).append(newLine);
|
||||
}
|
||||
|
||||
protected void sectionTitleLevel1(Markup markup, String title){
|
||||
documentBuilder.append(markup).append(title).append(newLine);
|
||||
}
|
||||
|
||||
protected void sectionTitleLevel2(Markup markup, String title){
|
||||
documentBuilder.append(markup).append(title).append(newLine);
|
||||
}
|
||||
|
||||
protected void sectionTitleLevel3(Markup markup, String title){
|
||||
documentBuilder.append(markup).append(title).append(newLine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder textLine(String text){
|
||||
documentBuilder.append(text).append(newLine);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected void paragraph(Markup markup, String text){
|
||||
documentBuilder.append(markup).append(newLine).append(text).append(newLine).append(newLine);
|
||||
}
|
||||
|
||||
protected void listing(Markup markup, String text){
|
||||
delimitedTextLine(markup, text);
|
||||
}
|
||||
|
||||
protected void delimitedTextLine(Markup markup, String text){
|
||||
documentBuilder.append(markup).append(newLine).append(text).append(newLine).append(markup).append(newLine).append(newLine);
|
||||
}
|
||||
|
||||
protected void delimitedTextLineWithoutLineBreaks(Markup markup, String text){
|
||||
documentBuilder.append(markup).append(text).append(markup).append(newLine);
|
||||
}
|
||||
|
||||
protected void preserveLineBreaks(Markup markup){
|
||||
documentBuilder.append(markup).append(newLine);
|
||||
}
|
||||
|
||||
protected void boldTextLine(Markup markup, String text){
|
||||
delimitedTextLineWithoutLineBreaks(markup, text);
|
||||
}
|
||||
|
||||
protected void italicTextLine(Markup markup, String text){
|
||||
delimitedTextLineWithoutLineBreaks(markup, text);
|
||||
}
|
||||
|
||||
protected void unorderedList(Markup markup, List<String> list){
|
||||
documentBuilder.append(newLine);
|
||||
for(String listEntry : list){
|
||||
documentBuilder.append(markup).append(listEntry).append(newLine);
|
||||
}
|
||||
documentBuilder.append(newLine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder newLine(){
|
||||
documentBuilder.append(newLine);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return documentBuilder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToFile(String directory, String fileNameWithExtension, Charset charset) throws IOException {
|
||||
Files.createDirectories(Paths.get(directory));
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(directory, fileNameWithExtension), charset)){
|
||||
writer.write(documentBuilder.toString());
|
||||
}
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("{} was written to: {}", fileNameWithExtension, directory);
|
||||
}
|
||||
documentBuilder = new StringBuilder();
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package io.github.robwin.markup.builder;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public interface Markup {
|
||||
public String toString();
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package io.github.robwin.markup.builder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public interface MarkupDocBuilder {
|
||||
MarkupDocBuilder documentTitle(String title);
|
||||
|
||||
MarkupDocBuilder documentTitleWithAttributes(String title);
|
||||
|
||||
MarkupDocBuilder sectionTitleLevel1(String title);
|
||||
|
||||
MarkupDocBuilder sectionTitleLevel2(String title);
|
||||
|
||||
MarkupDocBuilder sectionTitleLevel3(String title);
|
||||
|
||||
MarkupDocBuilder textLine(String text);
|
||||
|
||||
MarkupDocBuilder paragraph(String text);
|
||||
|
||||
MarkupDocBuilder listing(String text);
|
||||
|
||||
MarkupDocBuilder source(String text, String language);
|
||||
|
||||
MarkupDocBuilder boldTextLine(String text);
|
||||
|
||||
MarkupDocBuilder italicTextLine(String text);
|
||||
|
||||
MarkupDocBuilder unorderedList(List<String> list);
|
||||
|
||||
MarkupDocBuilder tableWithHeaderRow(List<String> rowsInPSV);
|
||||
|
||||
MarkupDocBuilder crossReference(String text);
|
||||
|
||||
MarkupDocBuilder newLine();
|
||||
|
||||
/**
|
||||
* Returns a string representation of the document.
|
||||
*/
|
||||
String toString();
|
||||
|
||||
/**
|
||||
* Writes the content of the builder to a file and clears the builder.
|
||||
*
|
||||
* @param directory the directory where the generated file should be stored
|
||||
* @param fileName the name of the file
|
||||
* @param charset the the charset to use for encoding
|
||||
* @throws java.io.IOException if the file cannot be written
|
||||
*/
|
||||
void writeToFile(String directory, String fileName, Charset charset) throws IOException;
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package io.github.robwin.markup.builder;
|
||||
|
||||
|
||||
import io.github.robwin.markup.builder.asciidoc.AsciiDocBuilder;
|
||||
import io.github.robwin.markup.builder.markdown.MarkdownBuilder;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public final class MarkupDocBuilders {
|
||||
|
||||
private MarkupDocBuilders(){};
|
||||
|
||||
public static MarkupDocBuilder documentBuilder(MarkupLanguage markupLanguage){
|
||||
switch(markupLanguage){
|
||||
case MARKDOWN: return new MarkdownBuilder();
|
||||
case ASCIIDOC: return new AsciiDocBuilder();
|
||||
default: return new AsciiDocBuilder();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package io.github.robwin.markup.builder;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public enum MarkupLanguage {
|
||||
ASCIIDOC(".adoc,.asciidoc"),
|
||||
MARKDOWN(".md,.markdown");
|
||||
|
||||
private final String fileNameExtensions;
|
||||
|
||||
/**
|
||||
* @param fileNameExtensions file name suffix
|
||||
*/
|
||||
private MarkupLanguage(final String fileNameExtensions) {
|
||||
this.fileNameExtensions = fileNameExtensions;
|
||||
}
|
||||
|
||||
public List<String> getFileNameExtensions() {
|
||||
return Arrays.asList(fileNameExtensions.split(","));
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package io.github.robwin.markup.builder.asciidoc;
|
||||
|
||||
|
||||
import io.github.robwin.markup.builder.Markup;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public enum AsciiDoc implements Markup {
|
||||
LABELED(":: "),
|
||||
TABLE("|==="),
|
||||
TABLE_COLUMN_DELIMITER("|"),
|
||||
LISTING("----"),
|
||||
HARDBREAKS(":hardbreaks:"),
|
||||
DOCUMENT_TITLE("= "),
|
||||
SECTION_TITLE_LEVEL1("== "),
|
||||
SECTION_TITLE_LEVEL2("=== "),
|
||||
SECTION_TITLE_LEVEL3("==== "),
|
||||
BOLD("*"),
|
||||
ITALIC("_"),
|
||||
LIST_ENTRY("* "),
|
||||
CROSS_REFERENCE_START("<<"),
|
||||
CROSS_REFERENCE_END(">>");
|
||||
|
||||
private final String markup;
|
||||
|
||||
/**
|
||||
* @param markup AsciiDoc markup
|
||||
*/
|
||||
private AsciiDoc(final String markup) {
|
||||
this.markup = markup;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Enum#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return markup;
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
package io.github.robwin.markup.builder.asciidoc;
|
||||
|
||||
import io.github.robwin.markup.builder.AbstractMarkupDocBuilder;
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class AsciiDocBuilder extends AbstractMarkupDocBuilder {
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder documentTitle(String title){
|
||||
documentTitle(AsciiDoc.DOCUMENT_TITLE, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder documentTitleWithAttributes(String title) {
|
||||
documentTitle(AsciiDoc.DOCUMENT_TITLE, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleLevel1(String title){
|
||||
sectionTitleLevel1(AsciiDoc.SECTION_TITLE_LEVEL1, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleLevel2(String title){
|
||||
sectionTitleLevel2(AsciiDoc.SECTION_TITLE_LEVEL2, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleLevel3(String title){
|
||||
sectionTitleLevel3(AsciiDoc.SECTION_TITLE_LEVEL3, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder paragraph(String text){
|
||||
paragraph(AsciiDoc.HARDBREAKS, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder listing(String text){
|
||||
listing(AsciiDoc.LISTING, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder boldTextLine(String text){
|
||||
boldTextLine(AsciiDoc.BOLD, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder italicTextLine(String text) {
|
||||
italicTextLine(AsciiDoc.ITALIC, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder unorderedList(List<String> list){
|
||||
unorderedList(AsciiDoc.LIST_ENTRY, list);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder source(String text, String language){
|
||||
documentBuilder.append(String.format("[source,%s]", language)).append(newLine);
|
||||
listing(AsciiDoc.LISTING, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder tableWithHeaderRow(List<String> rowsInPSV){
|
||||
documentBuilder.append("[options=\"header\"]").append(newLine);
|
||||
documentBuilder.append(AsciiDoc.TABLE).append(newLine);
|
||||
for(String row : rowsInPSV){
|
||||
documentBuilder.append(AsciiDoc.TABLE_COLUMN_DELIMITER).append(row).append(newLine);
|
||||
}
|
||||
documentBuilder.append(AsciiDoc.TABLE).append(newLine).append(newLine);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder crossReference(String text) {
|
||||
documentBuilder.append(AsciiDoc.CROSS_REFERENCE_START).append(text).append(AsciiDoc.CROSS_REFERENCE_END);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToFile(String directory, String fileName, Charset charset) throws IOException {
|
||||
String fileNameWithExtension = fileName + ".adoc";
|
||||
super.writeToFile(directory, fileNameWithExtension, charset);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package io.github.robwin.markup.builder.markdown;
|
||||
|
||||
import io.github.robwin.markup.builder.Markup;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public enum Markdown implements Markup {
|
||||
HARDBREAKS(""),
|
||||
TABLE_COLUMN_DELIMITER("|"),
|
||||
TABLE_ROW("-"),
|
||||
LISTING("```"),
|
||||
DOCUMENT_TITLE("# "),
|
||||
SECTION_TITLE_LEVEL1("## "),
|
||||
SECTION_TITLE_LEVEL2("### "),
|
||||
SECTION_TITLE_LEVEL3("### "),
|
||||
BOLD("**"),
|
||||
ITALIC("*"),
|
||||
LIST_ENTRY("* ");
|
||||
|
||||
private final String markup;
|
||||
|
||||
/**
|
||||
* @param markup AsciiDoc markup
|
||||
*/
|
||||
private Markdown(final String markup) {
|
||||
this.markup = markup;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Enum#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return markup;
|
||||
}
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
package io.github.robwin.markup.builder.markdown;
|
||||
|
||||
import io.github.robwin.markup.builder.AbstractMarkupDocBuilder;
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class MarkdownBuilder extends AbstractMarkupDocBuilder
|
||||
{
|
||||
@Override
|
||||
public MarkupDocBuilder documentTitle(String title){
|
||||
documentTitle(Markdown.DOCUMENT_TITLE, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder documentTitleWithAttributes(String title) {
|
||||
documentTitle(Markdown.DOCUMENT_TITLE, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleLevel1(String title){
|
||||
sectionTitleLevel1(Markdown.SECTION_TITLE_LEVEL1, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleLevel2(String title){
|
||||
sectionTitleLevel2(Markdown.SECTION_TITLE_LEVEL2, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleLevel3(String title){
|
||||
sectionTitleLevel3(Markdown.SECTION_TITLE_LEVEL3, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder paragraph(String text){
|
||||
paragraph(Markdown.HARDBREAKS, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder listing(String text){
|
||||
listing(Markdown.LISTING, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder source(String text, String language){
|
||||
documentBuilder.append(Markdown.LISTING).append(language).append(newLine).
|
||||
append(text).append(newLine).
|
||||
append(Markdown.LISTING).append(newLine).append(newLine);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder boldTextLine(String text){
|
||||
boldTextLine(Markdown.BOLD, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder italicTextLine(String text) {
|
||||
italicTextLine(Markdown.ITALIC, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder unorderedList(List<String> list){
|
||||
unorderedList(Markdown.LIST_ENTRY, list);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder tableWithHeaderRow(List<String> rowsInPSV){
|
||||
String headersInPSV = rowsInPSV.get(0);
|
||||
List<String> contentRowsInPSV = rowsInPSV.subList(1, rowsInPSV.size());
|
||||
String[] headersAsArray = headersInPSV.split(String.format("\\%s", Markdown.TABLE_COLUMN_DELIMITER.toString()));
|
||||
List<String> headers = Arrays.asList(headersAsArray);
|
||||
// Header
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER.toString());
|
||||
documentBuilder.append(headersInPSV);
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER.toString());
|
||||
newLine();
|
||||
// Header/Content separator
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER.toString());
|
||||
for(String header : headers){
|
||||
for(int i = 1; i<5; i++) {
|
||||
documentBuilder.append(Markdown.TABLE_ROW);
|
||||
}
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER.toString());
|
||||
}
|
||||
newLine();
|
||||
// Content
|
||||
for(String contentRowInPSV : contentRowsInPSV){
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER.toString());
|
||||
documentBuilder.append(contentRowInPSV);
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER.toString());
|
||||
newLine();
|
||||
}
|
||||
newLine().newLine();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
// TODO
|
||||
public MarkupDocBuilder crossReference(String text) {
|
||||
throw new UnsupportedOperationException("Not yet supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToFile(String directory, String fileName, Charset charset) throws IOException {
|
||||
String fileNameWithExtension = fileName + ".md";
|
||||
super.writeToFile(directory, fileNameWithExtension, charset);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.swagger2markup.markup.builder;
|
||||
|
||||
public enum LineSeparator {
|
||||
/**
|
||||
* Line separator for Unix systems (<tt>\n</tt>).
|
||||
*/
|
||||
UNIX("\n"),
|
||||
/**
|
||||
* Line separator for Windows systems (<tt>\r\n</tt>).
|
||||
*/
|
||||
WINDOWS("\r\n"),
|
||||
/**
|
||||
* Line separator for Macintosh systems (<tt>\r</tt>).
|
||||
*/
|
||||
MAC("\r");
|
||||
|
||||
private String lineSeparator;
|
||||
|
||||
LineSeparator(String lineSeparator) {
|
||||
this.lineSeparator = lineSeparator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return lineSeparator;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package io.github.swagger2markup.markup.builder;
|
||||
|
||||
public enum MarkupAdmonition {
|
||||
NOTE,
|
||||
TIP,
|
||||
IMPORTANT,
|
||||
CAUTION,
|
||||
WARNING
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package io.github.swagger2markup.markup.builder;
|
||||
|
||||
public enum MarkupBlockStyle {
|
||||
SIDEBAR,
|
||||
EXAMPLE,
|
||||
LITERAL,
|
||||
LISTING,
|
||||
PASSTHROUGH
|
||||
}
|
||||
@@ -0,0 +1,599 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.swagger2markup.markup.builder;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.OpenOption;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public interface MarkupDocBuilder {
|
||||
|
||||
/**
|
||||
* Builds a document section {@code title}.
|
||||
*
|
||||
* @param title title
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder documentTitle(String title);
|
||||
|
||||
/**
|
||||
* Builds a section {@code title}.
|
||||
*
|
||||
* @param title title
|
||||
* @param level section title level [1, 5]
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleLevel(int level, String title);
|
||||
|
||||
/**
|
||||
* Builds a section {@code title} with a custom {@code anchor} for later reference.<br>
|
||||
* Specified {@code anchor} will be normalized anyway.
|
||||
*
|
||||
* @param title title
|
||||
* @param level section title level [1, 5]
|
||||
* @param anchor custom anchor. If null, auto-generate the anchor from the normalized title.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleWithAnchorLevel(int level, String title, String anchor);
|
||||
|
||||
/**
|
||||
* Builds a section {@code title} with an auto-generated anchor from the normalized title, for later reference.<br>
|
||||
* This is an alias for {@link #sectionTitleWithAnchorLevel(int, String, String) sectionTitleWithAnchorLevel(level, title, null)}.
|
||||
*
|
||||
* @param title title
|
||||
* @param level section title level [1, 5]
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleWithAnchorLevel(int level, String title);
|
||||
|
||||
/**
|
||||
* Builds a level 1 section {@code title}.
|
||||
*
|
||||
* @param title title
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleLevel1(String title);
|
||||
|
||||
/**
|
||||
* Builds a level 1 section {@code title} with a custom {@code anchor} for later reference.<br>
|
||||
* Specified {@code anchor} will be normalized anyway.
|
||||
*
|
||||
* @param title title
|
||||
* @param anchor custom anchor. If null, auto-generate the anchor from the normalized title.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleWithAnchorLevel1(String title, String anchor);
|
||||
|
||||
/**
|
||||
* Builds a level 1 section {@code title} with an auto-generated anchor from the normalized title, for later reference.<br>
|
||||
* This is an alias for {@link #sectionTitleWithAnchorLevel1(String, String) sectionTitleWithAnchorLevel1(title, null)}.
|
||||
*
|
||||
* @param title title
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleWithAnchorLevel1(String title);
|
||||
|
||||
/**
|
||||
* Builds a level 2 section {@code title}.
|
||||
*
|
||||
* @param title title
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleLevel2(String title);
|
||||
|
||||
/**
|
||||
* Builds a level 2 section {@code title} with a custom {@code anchor} for later reference.<br>
|
||||
* Specified {@code anchor} will be normalized anyway.
|
||||
*
|
||||
* @param title title
|
||||
* @param anchor custom anchor. If null, auto-generate the anchor from the normalized title.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleWithAnchorLevel2(String title, String anchor);
|
||||
|
||||
/**
|
||||
* Builds a level 2 section {@code title} with an auto-generated anchor from the normalized title, for later reference.<br>
|
||||
* This is an alias for {@link #sectionTitleWithAnchorLevel2(String, String) sectionTitleWithAnchorLevel2(title, null)}.
|
||||
*
|
||||
* @param title title
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleWithAnchorLevel2(String title);
|
||||
|
||||
/**
|
||||
* Builds a level 3 section {@code title}.
|
||||
*
|
||||
* @param title title
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleLevel3(String title);
|
||||
|
||||
/**
|
||||
* Builds a level 3 section {@code title} with a custom {@code anchor} for later reference.<br>
|
||||
* Specified {@code anchor} will be normalized anyway.
|
||||
*
|
||||
* @param title title
|
||||
* @param anchor custom anchor. If null, auto-generate the anchor from the normalized title.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleWithAnchorLevel3(String title, String anchor);
|
||||
|
||||
/**
|
||||
* Builds a level 3 section {@code title} with an auto-generated anchor from the normalized title, for later reference.<br>
|
||||
* This is an alias for {@link #sectionTitleWithAnchorLevel3(String, String) sectionTitleWithAnchorLevel3(title, null)}.
|
||||
*
|
||||
* @param title title
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleWithAnchorLevel3(String title);
|
||||
|
||||
/**
|
||||
* Builds a level 4 section {@code title}.
|
||||
*
|
||||
* @param title title
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleLevel4(String title);
|
||||
|
||||
/**
|
||||
* Builds a level 4 section {@code title} with a custom {@code anchor} for later reference.<br>
|
||||
* Specified {@code anchor} will be normalized anyway.
|
||||
*
|
||||
* @param title title
|
||||
* @param anchor custom anchor. If null, auto-generate the anchor from the normalized title.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleWithAnchorLevel4(String title, String anchor);
|
||||
|
||||
/**
|
||||
* Builds a level 4 section {@code title} with an auto-generated anchor from the normalized title, for later reference.<br>
|
||||
* This is an alias for {@link #sectionTitleWithAnchorLevel4(String, String) sectionTitleWithAnchorLevel4(title, null)}.
|
||||
*
|
||||
* @param title title
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleWithAnchorLevel4(String title);
|
||||
|
||||
/**
|
||||
* Builds a level 5 section {@code title}.
|
||||
*
|
||||
* @param title title
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleLevel5(String title);
|
||||
|
||||
/**
|
||||
* Builds a level 5 section {@code title} with a custom {@code anchor} for later reference.<br>
|
||||
* Specified {@code anchor} will be normalized anyway.
|
||||
*
|
||||
* @param title title
|
||||
* @param anchor custom anchor. If null, auto-generate the anchor from the normalized title.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleWithAnchorLevel5(String title, String anchor);
|
||||
|
||||
/**
|
||||
* Builds a level 5 section {@code title} with an auto-generated anchor from the normalized title, for later reference.<br>
|
||||
* This is an alias for {@link #sectionTitleWithAnchorLevel5(String, String) sectionTitleWithAnchorLevel5(title, null)}.
|
||||
*
|
||||
* @param title title
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleWithAnchorLevel5(String title);
|
||||
|
||||
/**
|
||||
* Builds a regular text line.<br>
|
||||
* This is an alias for {@link #textLine(String, boolean) textLine(text, false)}.
|
||||
*
|
||||
* @param text text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder textLine(String text);
|
||||
|
||||
/**
|
||||
* Builds a regular text line.
|
||||
*
|
||||
* @param text text
|
||||
* @param forceLineBreak add an explicit line break if true.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder textLine(String text, boolean forceLineBreak);
|
||||
|
||||
/**
|
||||
* Builds a regular text.
|
||||
*
|
||||
* @param text text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder text(String text);
|
||||
|
||||
/**
|
||||
* Builds a text paragraph.<br>
|
||||
*
|
||||
* @param text multi-line text
|
||||
* @param hardbreaks force hardbreaks on all lines
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder paragraph(String text, boolean hardbreaks);
|
||||
|
||||
/**
|
||||
* Builds a text paragraph.<br>
|
||||
* This is an alias for {@link #paragraph(String, boolean) paragraph(text, false)}.
|
||||
*
|
||||
* @param text multi-line text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder paragraph(String text);
|
||||
|
||||
/**
|
||||
* Insert a page break
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder pageBreak();
|
||||
|
||||
/**
|
||||
* Builds a block of {@code text} with specified {@code style}.
|
||||
*
|
||||
* @param text text
|
||||
* @param style block style
|
||||
* @param title an optional title for the block. No title if null.
|
||||
* @param admonition an optional admonition for the block. No admonition if null.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder block(String text, MarkupBlockStyle style, String title, MarkupAdmonition admonition);
|
||||
|
||||
|
||||
/**
|
||||
* Builds a block of {@code text} with specified {@code style}.<br>
|
||||
* This is an alias for {@link #block(String, MarkupBlockStyle, String, MarkupAdmonition) block(String, MarkupBlockStyle, null, null)}.
|
||||
*
|
||||
* @param text text
|
||||
* @param style block style
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder block(String text, MarkupBlockStyle style);
|
||||
|
||||
|
||||
/**
|
||||
* Builds a source code block using the specified {@code language}.<br>
|
||||
* Line breaks are respected.
|
||||
*
|
||||
* @param text multi-line text
|
||||
* @param language source code language. Simple listing if {@code language} == null.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder listingBlock(String text, String language);
|
||||
|
||||
|
||||
/**
|
||||
* Builds a listing text block.<br>
|
||||
* This is an alias for {@link #listingBlock(String, String) listingBlock(String, null)}.
|
||||
*
|
||||
* @param text multi-line text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder listingBlock(String text);
|
||||
|
||||
/**
|
||||
* Builds a literal text line.<br>
|
||||
* This is an alias for {@link #literalTextLine(String, boolean) literalTextLine(text, false)}.
|
||||
*
|
||||
* @param text text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder literalTextLine(String text);
|
||||
|
||||
/**
|
||||
* Builds a literal text line.
|
||||
*
|
||||
* @param text text
|
||||
* @param forceLineBreak add an explicit line break if true.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder literalTextLine(String text, boolean forceLineBreak);
|
||||
|
||||
/**
|
||||
* Builds a literal text.
|
||||
*
|
||||
* @param text text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder literalText(String text);
|
||||
|
||||
/**
|
||||
* Builds a bold text line.<br>
|
||||
* This is an alias for {@link #boldTextLine(String, boolean) boldTextLine(text, false)}.
|
||||
*
|
||||
* @param text text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder boldTextLine(String text);
|
||||
|
||||
/**
|
||||
* Builds a bold text line.
|
||||
*
|
||||
* @param text text
|
||||
* @param forceLineBreak add an explicit line break if true.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder boldTextLine(String text, boolean forceLineBreak);
|
||||
|
||||
/**
|
||||
* Builds a bold text.
|
||||
*
|
||||
* @param text text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder boldText(String text);
|
||||
|
||||
/**
|
||||
* Builds an italic text line.<br>
|
||||
* This is an alias for {@link #italicTextLine(String, boolean) italicTextLine(text, false)}.
|
||||
*
|
||||
* @param text text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder italicTextLine(String text);
|
||||
|
||||
/**
|
||||
* Builds an italic text line.
|
||||
*
|
||||
* @param text text
|
||||
* @param forceLineBreak add an explicit line break if true.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder italicTextLine(String text, boolean forceLineBreak);
|
||||
|
||||
/**
|
||||
* Builds an italic text.
|
||||
*
|
||||
* @param text text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder italicText(String text);
|
||||
|
||||
/**
|
||||
* Builds an unordered item list
|
||||
*
|
||||
* @param list list of items
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder unorderedList(List<String> list);
|
||||
|
||||
/**
|
||||
* Builds a single list item
|
||||
*
|
||||
* @param item item
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder unorderedListItem(String item);
|
||||
|
||||
/**
|
||||
* Builds a table without column specifiers, using specified cell values.<br>
|
||||
* This is an alias for {@link #tableWithColumnSpecs(List, List) tableWithColumnSpecs(null, cells)}.<br>
|
||||
* Limited support : Markdown does not support table without headers.
|
||||
*
|
||||
* @param cells cell values
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder table(List<List<String>> cells);
|
||||
|
||||
/**
|
||||
* Builds a table with column specifiers, using specified cell values.
|
||||
*
|
||||
* @param columnSpecs list of column specifiers. Ignored if null.
|
||||
* @param cells cell values
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder tableWithColumnSpecs(List<MarkupTableColumn> columnSpecs, List<List<String>> cells);
|
||||
|
||||
/**
|
||||
* Builds a custom {@code anchor} for later reference.<br>
|
||||
* Specified {@code anchor} will be normalized anyway.<br>
|
||||
* Limited support : Markdown does not support default text for anchors, and will ignore {@code text}.
|
||||
*
|
||||
* @param anchor custom anchor
|
||||
* @param text default text to display when a cross-reference does not have text itself. Ignored if null.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder anchor(String anchor, String text);
|
||||
|
||||
/**
|
||||
* Builds a custom {@code anchor} for later reference.<br>
|
||||
* Specified {@code anchor} will be normalized anyway.
|
||||
*
|
||||
* @param anchor custom anchor
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder anchor(String anchor);
|
||||
|
||||
/**
|
||||
* Builds an inter-document cross-reference to {@code document}#{@code anchor} with specified {@code text}.<br>
|
||||
* This is the "raw anchor" version. Use the preferred method {@link #crossReference(String, String, String)} instead.<br>
|
||||
* Specified {@code anchor} is built as-is, without any normalization.
|
||||
*
|
||||
* @param document document to point to. Reference becomes a simple cross-reference if null.
|
||||
* @param anchor anchor to point to
|
||||
* @param text display text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder crossReferenceRaw(String document, String anchor, String text);
|
||||
|
||||
/**
|
||||
* Builds an cross-reference to local document {@code anchor} with specified {@code text}.<br>
|
||||
* This is the "raw anchor" version. Use the preferred method {@link #crossReference(String, String)} instead.<br>
|
||||
* Specified {@code anchor} is built as-is, without any normalization.
|
||||
*
|
||||
* @param anchor anchor to point to
|
||||
* @param text display text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder crossReferenceRaw(String anchor, String text);
|
||||
|
||||
/**
|
||||
* Builds an cross-reference to local document {@code anchor}.<br>
|
||||
* This is the "raw anchor" version. Use the preferred method {@link #crossReference(String)} instead.<br>
|
||||
* Specified {@code anchor} is built as-is, without any normalization.
|
||||
*
|
||||
* @param anchor anchor to point to
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder crossReferenceRaw(String anchor);
|
||||
|
||||
/**
|
||||
* Builds an inter-document cross-reference to {@code document}#{@code anchor} with specified {@code text}.<br>
|
||||
* Specified {@code anchor} will be normalized anyway.
|
||||
*
|
||||
* @param document document to point to. Reference becomes a simple cross-reference if null.
|
||||
* @param anchor anchor to point to
|
||||
* @param text display text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder crossReference(String document, String anchor, String text);
|
||||
|
||||
/**
|
||||
* Builds an cross-reference to local document {@code anchor} with specified {@code text}.<br>
|
||||
* Specified {@code anchor} will be normalized anyway.
|
||||
*
|
||||
* @param anchor anchor to point to
|
||||
* @param text display text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder crossReference(String anchor, String text);
|
||||
|
||||
/**
|
||||
* Builds an cross-reference to local document {@code anchor}.<br>
|
||||
* Specified {@code anchor} will be normalized anyway.
|
||||
*
|
||||
* @param anchor anchor to point to
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder crossReference(String anchor);
|
||||
|
||||
/**
|
||||
* Builds a newline using {@code System.getProperty("line.separator")}.<br>
|
||||
* This is an alias for {@link #newLine(boolean) newLine(false)}.
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder newLine();
|
||||
|
||||
/**
|
||||
* Builds a newline using {@code System.getProperty("line.separator")}.
|
||||
*
|
||||
* @param forceLineBreak add an explicit line break if true.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder newLine(boolean forceLineBreak);
|
||||
|
||||
/**
|
||||
* Import some markup text into this builder.<br>
|
||||
* This is an alias for {@link #importMarkup(Reader, MarkupLanguage, int) importMarkup(markupText, markupLanguage, 0)}.
|
||||
*
|
||||
* @param markupText markup reader to read data from
|
||||
* @param markupLanguage identify the imported markup language
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder importMarkup(Reader markupText, MarkupLanguage markupLanguage);
|
||||
|
||||
/**
|
||||
* Import some markup text into this builder.<br>
|
||||
* If {@code markupLanguage} is different from current builder language, markupText is converted when supported, or conversion is just ignored.<br>
|
||||
* Currently supported conversions :
|
||||
* <ul>
|
||||
* <li> Markdown -> AsciiDoc </li>
|
||||
* </ul>
|
||||
* Newlines are normalized in the process.
|
||||
*
|
||||
* @param markupText markup reader to read data from
|
||||
* @param markupLanguage identify the imported markup language
|
||||
* @param levelOffset adapt section leveling by adding {@code levelOffset} [-5, 5]
|
||||
* @return this builder
|
||||
* @throws IllegalArgumentException if levelOffset is too high for the imported markup
|
||||
*/
|
||||
MarkupDocBuilder importMarkup(Reader markupText, MarkupLanguage markupLanguage, int levelOffset);
|
||||
|
||||
/**
|
||||
* Returns a string representation of the document.
|
||||
*/
|
||||
String toString();
|
||||
|
||||
/**
|
||||
* Configure this builder to prefix all generated anchors with {@code prefix}.
|
||||
*
|
||||
* @param prefix anchor prefix
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder withAnchorPrefix(String prefix);
|
||||
|
||||
/**
|
||||
* @return anchor prefix configuration
|
||||
*/
|
||||
String getAnchorPrefix();
|
||||
|
||||
/**
|
||||
* Builds a new instance of this builder with a state copy.
|
||||
*
|
||||
* @param copyBuffer copy current buffer into the new instance
|
||||
* @return new builder instance with a state copy
|
||||
*/
|
||||
MarkupDocBuilder copy(boolean copyBuffer);
|
||||
|
||||
/**
|
||||
* Add an extension to fileName depending on markup language.
|
||||
*
|
||||
* @param fileName without extension
|
||||
* @return fileName with an extension
|
||||
*/
|
||||
String addFileExtension(String fileName);
|
||||
|
||||
/**
|
||||
* Add an extension to file depending on markup language.
|
||||
*
|
||||
* @param file without extension
|
||||
* @return file with an extension
|
||||
*/
|
||||
Path addFileExtension(Path file);
|
||||
|
||||
/**
|
||||
* Writes the content of the builder to a file.<br>
|
||||
* An extension will be dynamically added to fileName depending on the markup language.
|
||||
*
|
||||
* @param file the generated file without extension
|
||||
* @param charset the the charset to use for encoding
|
||||
* @param options the file open options
|
||||
*/
|
||||
void writeToFile(Path file, Charset charset, OpenOption... options);
|
||||
|
||||
/**
|
||||
* Writes the content of the builder to a file.
|
||||
*
|
||||
* @param file the generated file
|
||||
* @param charset the the charset to use for encoding
|
||||
* @param options the file open options
|
||||
*/
|
||||
void writeToFileWithoutExtension(Path file, Charset charset, OpenOption... options);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.swagger2markup.markup.builder;
|
||||
|
||||
import io.github.swagger2markup.markup.builder.internal.asciidoc.AsciiDocBuilder;
|
||||
import io.github.swagger2markup.markup.builder.internal.confluenceMarkup.ConfluenceMarkupBuilder;
|
||||
import io.github.swagger2markup.markup.builder.internal.markdown.MarkdownBuilder;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public final class MarkupDocBuilders {
|
||||
|
||||
private MarkupDocBuilders() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a MarkupDocBuilder which uses the system line separator.
|
||||
*
|
||||
* @param markupLanguage the markup language which is used to generate the files
|
||||
* @return a MarkupDocBuilder
|
||||
*/
|
||||
public static MarkupDocBuilder documentBuilder(MarkupLanguage markupLanguage) {
|
||||
switch (markupLanguage) {
|
||||
case MARKDOWN:
|
||||
return new MarkdownBuilder();
|
||||
case ASCIIDOC:
|
||||
return new AsciiDocBuilder();
|
||||
case CONFLUENCE_MARKUP:
|
||||
return new ConfluenceMarkupBuilder();
|
||||
default:
|
||||
throw new IllegalArgumentException(String.format("Unsupported markup language %s", markupLanguage));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a MarkupDocBuilder which uses a custom line separator.
|
||||
* If the custom line separator is null, it uses the system line separator.
|
||||
*
|
||||
* @param markupLanguage the markup language which is used to generate the files
|
||||
* @param lineSeparator the line separator which should be used
|
||||
* @return a MarkupDocBuilder
|
||||
*/
|
||||
public static MarkupDocBuilder documentBuilder(MarkupLanguage markupLanguage, LineSeparator lineSeparator) {
|
||||
switch (markupLanguage) {
|
||||
case MARKDOWN:
|
||||
if (lineSeparator == null)
|
||||
return new MarkdownBuilder();
|
||||
else
|
||||
return new MarkdownBuilder(lineSeparator.toString());
|
||||
case ASCIIDOC:
|
||||
if (lineSeparator == null)
|
||||
return new AsciiDocBuilder();
|
||||
else
|
||||
return new AsciiDocBuilder(lineSeparator.toString());
|
||||
case CONFLUENCE_MARKUP:
|
||||
if (lineSeparator == null)
|
||||
return new ConfluenceMarkupBuilder();
|
||||
else
|
||||
return new ConfluenceMarkupBuilder(lineSeparator.toString());
|
||||
default:
|
||||
throw new IllegalArgumentException(String.format("Unsupported markup language %s", markupLanguage));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
package io.github.swagger2markup.markup.builder;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public enum MarkupLanguage {
|
||||
ASCIIDOC(".adoc,.asciidoc"),
|
||||
MARKDOWN(".md,.markdown"),
|
||||
CONFLUENCE_MARKUP(".txt");
|
||||
|
||||
private final String fileNameExtensions;
|
||||
|
||||
/**
|
||||
* @param fileNameExtensions file name suffix
|
||||
*/
|
||||
private MarkupLanguage(final String fileNameExtensions) {
|
||||
this.fileNameExtensions = fileNameExtensions;
|
||||
}
|
||||
|
||||
public List<String> getFileNameExtensions() {
|
||||
return Arrays.asList(fileNameExtensions.split(","));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package io.github.swagger2markup.markup.builder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MarkupTableColumn {
|
||||
public String header;
|
||||
public boolean headerColumn = false;
|
||||
public Integer widthRatio = 0;
|
||||
public Map<MarkupLanguage, String> markupSpecifiers = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Empty constructor
|
||||
*/
|
||||
public MarkupTableColumn() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Header constructor.
|
||||
*
|
||||
* @param header header name
|
||||
*/
|
||||
public MarkupTableColumn(String header) {
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Header and specifiers constructor.
|
||||
*
|
||||
* @param header header
|
||||
* @param headerColumn set column as an header column.
|
||||
* @param widthRatio width ratio
|
||||
*/
|
||||
public MarkupTableColumn(String header, boolean headerColumn, Integer widthRatio) {
|
||||
this.header = header;
|
||||
this.headerColumn = headerColumn;
|
||||
this.widthRatio = widthRatio;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set header name for this column.
|
||||
*
|
||||
* @param header header name
|
||||
* @return this builder
|
||||
*/
|
||||
public MarkupTableColumn withHeader(String header) {
|
||||
this.header = header;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set column as an header column.<br>
|
||||
* Limited support : Markdown does not support header column and will ignore it.
|
||||
*
|
||||
* @param headerColumn configuration value
|
||||
* @return this builder
|
||||
*/
|
||||
public MarkupTableColumn withHeaderColumn(boolean headerColumn) {
|
||||
this.headerColumn = headerColumn;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set column width ratio for this column.<br>
|
||||
* Limited support : Markdown does not support column width specifiers and will ignore {@code widthRatio}.
|
||||
*
|
||||
* @param widthRatio width ratio integer value [0-100]. Accept relative width specifiers (e.g.: 1, 2, 3, .. with sum of width ratios for all columns != 100).
|
||||
* @return this builder
|
||||
*/
|
||||
public MarkupTableColumn withWidthRatio(Integer widthRatio) {
|
||||
this.widthRatio = widthRatio;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides all other specifiers for the specified {@code language} with this language-dependent {@code specifiers} string.<br>
|
||||
* This method should be used as a last resort.
|
||||
*
|
||||
* @param language apply the {@code specifiers} to this language only
|
||||
* @param specifiers RAW language-dependent specifiers string for the column
|
||||
* @return this builder
|
||||
*/
|
||||
public MarkupTableColumn withMarkupSpecifiers(MarkupLanguage language, String specifiers) {
|
||||
this.markupSpecifiers.put(language, specifiers);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,546 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.swagger2markup.markup.builder.internal;
|
||||
|
||||
import io.github.swagger2markup.markup.builder.MarkupBlockStyle;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.markup.builder.MarkupLanguage;
|
||||
import nl.jworks.markdown_to_asciidoc.Converter;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.OpenOption;
|
||||
import java.nio.file.Path;
|
||||
import java.text.Normalizer;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public abstract class AbstractMarkupDocBuilder implements MarkupDocBuilder {
|
||||
|
||||
/**
|
||||
* Explicit line break default behavior for line returns, when not specified. Please, change documentation accordingly.
|
||||
*/
|
||||
protected static final boolean LINE_BREAK_DEFAULT = false;
|
||||
|
||||
protected static final Pattern ANCHOR_UNIGNORABLE_PATTERN = Pattern.compile("[^0-9a-zA-Z-_]+");
|
||||
protected static final Pattern ANCHOR_IGNORABLE_PATTERN = Pattern.compile("[\\s@#&(){}\\[\\]!$*%+=/:.;,?\\\\<>|]+");
|
||||
protected static final String ANCHOR_SEPARATION_CHARACTERS = "_-";
|
||||
protected static final int MAX_TITLE_LEVEL = 5;
|
||||
protected static final String NEW_LINES = "\\r\\n|\\r|\\n";
|
||||
protected static final String WHITESPACE = " ";
|
||||
|
||||
protected StringBuilder documentBuilder = new StringBuilder();
|
||||
protected String newLine;
|
||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
protected String anchorPrefix = null;
|
||||
|
||||
public AbstractMarkupDocBuilder() {
|
||||
this(System.getProperty("line.separator"));
|
||||
}
|
||||
|
||||
public AbstractMarkupDocBuilder(String newLine) {
|
||||
this.newLine = newLine;
|
||||
}
|
||||
|
||||
protected abstract MarkupLanguage getMarkupLanguage();
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder withAnchorPrefix(String prefix) {
|
||||
this.anchorPrefix = prefix;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAnchorPrefix() {
|
||||
return this.anchorPrefix;
|
||||
}
|
||||
|
||||
protected void documentTitle(Markup markup, String title) {
|
||||
Validate.notBlank(title, "title must not be blank");
|
||||
documentBuilder.append(markup).append(replaceNewLinesWithWhiteSpace(title)).append(newLine).append(newLine);
|
||||
}
|
||||
|
||||
protected void sectionTitleLevel(Markup markup, int level, String title) {
|
||||
Validate.notBlank(title, "title must not be blank");
|
||||
Validate.inclusiveBetween(1, MAX_TITLE_LEVEL, level);
|
||||
documentBuilder.append(newLine);
|
||||
documentBuilder.append(StringUtils.repeat(markup.toString(), level + 1)).append(" ").append(replaceNewLinesWithWhiteSpace(title)).append(newLine);
|
||||
}
|
||||
|
||||
protected void sectionTitleWithAnchorLevel(Markup markup, int level, String title, String anchor) {
|
||||
Validate.notBlank(title, "title must not be blank");
|
||||
Validate.inclusiveBetween(1, MAX_TITLE_LEVEL, level);
|
||||
documentBuilder.append(newLine);
|
||||
if (anchor == null)
|
||||
anchor = title;
|
||||
anchor(replaceNewLinesWithWhiteSpace(anchor)).newLine();
|
||||
documentBuilder.append(StringUtils.repeat(markup.toString(), level + 1)).append(" ").append(replaceNewLinesWithWhiteSpace(title)).append(newLine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel(int level, String title) {
|
||||
return sectionTitleWithAnchorLevel(level, title, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleLevel1(String title) {
|
||||
return sectionTitleLevel(1, title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel1(String title, String anchor) {
|
||||
return sectionTitleWithAnchorLevel(1, title, anchor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel1(String title) {
|
||||
return sectionTitleWithAnchorLevel1(title, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleLevel2(String title) {
|
||||
return sectionTitleLevel(2, title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel2(String title, String anchor) {
|
||||
return sectionTitleWithAnchorLevel(2, title, anchor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel2(String title) {
|
||||
return sectionTitleWithAnchorLevel2(title, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleLevel3(String title) {
|
||||
return sectionTitleLevel(3, title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel3(String title, String anchor) {
|
||||
return sectionTitleWithAnchorLevel(3, title, anchor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel3(String title) {
|
||||
return sectionTitleWithAnchorLevel3(title, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleLevel4(String title) {
|
||||
return sectionTitleLevel(4, title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel4(String title, String anchor) {
|
||||
return sectionTitleWithAnchorLevel(4, title, anchor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel4(String title) {
|
||||
return sectionTitleWithAnchorLevel4(title, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleLevel5(String title) {
|
||||
return sectionTitleLevel(5, title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel5(String title, String anchor) {
|
||||
return sectionTitleWithAnchorLevel(5, title, anchor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel5(String title) {
|
||||
return sectionTitleWithAnchorLevel5(title, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder textLine(String text, boolean forceLineBreak) {
|
||||
Validate.notNull(text, "text must not be null");
|
||||
text(replaceNewLines(text));
|
||||
newLine(forceLineBreak);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder textLine(String text) {
|
||||
textLine(text, LINE_BREAK_DEFAULT);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder text(String text) {
|
||||
Validate.notNull(text, "text must not be null");
|
||||
documentBuilder.append(replaceNewLines(text));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder paragraph(String text) {
|
||||
return paragraph(text, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder block(String text, MarkupBlockStyle style) {
|
||||
Validate.notBlank(text, "text must not be blank");
|
||||
return block(replaceNewLines(text), style, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder listingBlock(String text) {
|
||||
Validate.notBlank(text, "text must not be blank");
|
||||
return listingBlock(replaceNewLines(text), null);
|
||||
}
|
||||
|
||||
protected void delimitedBlockText(Markup begin, String text, Markup end, boolean skipLeadingNewline) {
|
||||
Validate.notBlank(text, "text must not be blank");
|
||||
if (!StringUtils.isBlank(begin.toString()))
|
||||
documentBuilder.append(begin);
|
||||
if (!skipLeadingNewline)
|
||||
documentBuilder.append(newLine);
|
||||
|
||||
documentBuilder.append(replaceNewLines(text)).append(newLine);
|
||||
if (!StringUtils.isBlank(end.toString()))
|
||||
documentBuilder.append(end).append(newLine);
|
||||
documentBuilder.append(newLine);
|
||||
|
||||
}
|
||||
|
||||
protected void delimitedBlockText(Markup begin, String text, Markup end) {
|
||||
Validate.notBlank(text, "text must not be blank");
|
||||
if (!StringUtils.isBlank(begin.toString()))
|
||||
documentBuilder.append(begin).append(newLine);
|
||||
|
||||
documentBuilder.append(replaceNewLines(text)).append(newLine);
|
||||
if (!StringUtils.isBlank(end.toString()))
|
||||
documentBuilder.append(end).append(newLine);
|
||||
|
||||
documentBuilder.append(newLine);
|
||||
}
|
||||
|
||||
protected void delimitedTextWithoutLineBreaks(Markup begin, String text, Markup end) {
|
||||
Validate.notBlank(text, "text must not be blank");
|
||||
if (!StringUtils.isBlank(begin.toString()))
|
||||
documentBuilder.append(begin);
|
||||
documentBuilder.append(replaceNewLines(text));
|
||||
if (!StringUtils.isBlank(end.toString()))
|
||||
documentBuilder.append(end);
|
||||
}
|
||||
|
||||
protected void delimitedBlockText(Markup markup, String text) {
|
||||
delimitedBlockText(markup, text, markup);
|
||||
}
|
||||
|
||||
protected void delimitedTextWithoutLineBreaks(Markup markup, String text) {
|
||||
delimitedTextWithoutLineBreaks(markup, text, markup);
|
||||
}
|
||||
|
||||
protected void literalText(Markup markup, String text) {
|
||||
delimitedTextWithoutLineBreaks(markup, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder literalTextLine(String text, boolean forceLineBreak) {
|
||||
Validate.notBlank(text, "text must not be blank");
|
||||
literalText(replaceNewLines(text));
|
||||
newLine(forceLineBreak);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder literalTextLine(String text) {
|
||||
return literalTextLine(text, LINE_BREAK_DEFAULT);
|
||||
}
|
||||
|
||||
protected void boldText(Markup markup, String text) {
|
||||
delimitedTextWithoutLineBreaks(markup, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder boldTextLine(String text, boolean forceLineBreak) {
|
||||
Validate.notBlank(text, "text must not be blank");
|
||||
boldText(replaceNewLines(text));
|
||||
newLine(forceLineBreak);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder boldTextLine(String text) {
|
||||
return boldTextLine(text, LINE_BREAK_DEFAULT);
|
||||
}
|
||||
|
||||
protected void italicText(Markup markup, String text) {
|
||||
delimitedTextWithoutLineBreaks(markup, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder italicTextLine(String text, boolean forceLineBreak) {
|
||||
italicText(text);
|
||||
newLine(forceLineBreak);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder italicTextLine(String text) {
|
||||
return italicTextLine(text, LINE_BREAK_DEFAULT);
|
||||
}
|
||||
|
||||
protected void unorderedList(Markup markup, List<String> list) {
|
||||
Validate.notEmpty(list, "list must not be empty");
|
||||
documentBuilder.append(newLine);
|
||||
for (String listEntry : list) {
|
||||
unorderedListItem(markup, listEntry);
|
||||
}
|
||||
documentBuilder.append(newLine);
|
||||
}
|
||||
|
||||
protected void unorderedListItem(Markup markup, String item) {
|
||||
Validate.notBlank(item, "item must not be blank");
|
||||
documentBuilder.append(markup).append(item).append(newLine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder anchor(String anchor) {
|
||||
Validate.notBlank(anchor, "anchor must not be blank");
|
||||
return anchor(anchor, null);
|
||||
}
|
||||
|
||||
/*
|
||||
* Generic normalization algorithm for all markups (less common denominator character set).
|
||||
* Key points :
|
||||
* - Anchor is normalized (Normalized.Form.NFD)
|
||||
* - Punctuations (excluding [-_]) and spaces are replaced with escape character (depends on markup : Markup.E)
|
||||
* - Beginning, ending separation characters [-_] are ignored, repeating separation characters are simplified (keep first one)
|
||||
* - Anchor is trimmed and lower cased
|
||||
* - If the anchor still contains forbidden characters (non-ASCII, ...), replace the whole anchor with an hash (MD5).
|
||||
* - Add the anchor prefix if configured
|
||||
*/
|
||||
protected String normalizeAnchor(Markup spaceEscape, String anchor) {
|
||||
String normalizedAnchor = defaultString(anchorPrefix) + anchor.trim();
|
||||
normalizedAnchor = Normalizer.normalize(normalizedAnchor, Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
|
||||
normalizedAnchor = ANCHOR_IGNORABLE_PATTERN.matcher(normalizedAnchor).replaceAll(spaceEscape.toString());
|
||||
normalizedAnchor = normalizedAnchor.replaceAll(String.format("([%1$s])([%1$s]+)", ANCHOR_SEPARATION_CHARACTERS), "$1");
|
||||
normalizedAnchor = StringUtils.strip(normalizedAnchor, ANCHOR_SEPARATION_CHARACTERS);
|
||||
normalizedAnchor = normalizedAnchor.trim().toLowerCase();
|
||||
|
||||
String validAnchor = ANCHOR_UNIGNORABLE_PATTERN.matcher(normalizedAnchor).replaceAll("");
|
||||
if (validAnchor.length() != normalizedAnchor.length())
|
||||
normalizedAnchor = DigestUtils.md5Hex(normalizedAnchor);
|
||||
else
|
||||
normalizedAnchor = validAnchor;
|
||||
|
||||
return normalizedAnchor;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder crossReferenceRaw(String anchor, String text) {
|
||||
return crossReferenceRaw(null, anchor, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder crossReferenceRaw(String anchor) {
|
||||
return crossReferenceRaw(null, anchor, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder crossReference(String anchor, String text) {
|
||||
return crossReference(null, anchor, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder crossReference(String anchor) {
|
||||
return crossReference(null, anchor, null);
|
||||
}
|
||||
|
||||
protected void newLine(Markup markup, boolean forceLineBreak) {
|
||||
if (forceLineBreak)
|
||||
documentBuilder.append(markup);
|
||||
documentBuilder.append(newLine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder newLine() {
|
||||
newLine(LINE_BREAK_DEFAULT);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder importMarkup(Reader markupText, MarkupLanguage markupLanguage) {
|
||||
Validate.notNull(markupText, "markupText must not be null");
|
||||
Validate.notNull(markupLanguage, "markupLanguage must not be null");
|
||||
return importMarkup(markupText, markupLanguage, 0);
|
||||
}
|
||||
|
||||
protected String convert(String markupText, MarkupLanguage markupLanguage) {
|
||||
if (markupLanguage == getMarkupLanguage())
|
||||
return markupText;
|
||||
else {
|
||||
if (markupLanguage == MarkupLanguage.MARKDOWN && getMarkupLanguage() == MarkupLanguage.ASCIIDOC) {
|
||||
return Converter.convertMarkdownToAsciiDoc(markupText) + newLine;
|
||||
} else {
|
||||
return markupText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void importMarkupStyle1(Pattern titlePattern, Markup titlePrefix, Reader markupText, MarkupLanguage markupLanguage, int levelOffset) {
|
||||
Validate.isTrue(levelOffset <= MAX_TITLE_LEVEL, String.format("Specified levelOffset (%d) > max levelOffset (%d)", levelOffset, MAX_TITLE_LEVEL));
|
||||
Validate.isTrue(levelOffset >= -MAX_TITLE_LEVEL, String.format("Specified levelOffset (%d) < min levelOffset (%d)", levelOffset, -MAX_TITLE_LEVEL));
|
||||
|
||||
StringBuffer leveledText = new StringBuffer();
|
||||
try (BufferedReader bufferedReader = new BufferedReader(markupText)) {
|
||||
String readLine;
|
||||
while ((readLine = bufferedReader.readLine()) != null) {
|
||||
Matcher titleMatcher = titlePattern.matcher(readLine);
|
||||
|
||||
while (titleMatcher.find()) {
|
||||
int titleLevel = titleMatcher.group(1).length() - 1;
|
||||
String title = titleMatcher.group(2);
|
||||
|
||||
if (titleLevel + levelOffset > MAX_TITLE_LEVEL)
|
||||
throw new IllegalArgumentException(String.format("Specified levelOffset (%d) set title '%s' level (%d) > max title level (%d)", levelOffset, title, titleLevel, MAX_TITLE_LEVEL));
|
||||
if (titleLevel + levelOffset < 0)
|
||||
throw new IllegalArgumentException(String.format("Specified levelOffset (%d) set title '%s' level (%d) < 0", levelOffset, title, titleLevel));
|
||||
else
|
||||
titleMatcher.appendReplacement(leveledText, Matcher.quoteReplacement(String.format("%s %s", StringUtils.repeat(titlePrefix.toString(), 1 + titleLevel + levelOffset), title)));
|
||||
}
|
||||
titleMatcher.appendTail(leveledText);
|
||||
leveledText.append(newLine);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to import Markup", e);
|
||||
}
|
||||
|
||||
if (!StringUtils.isBlank(leveledText)) {
|
||||
documentBuilder.append(newLine);
|
||||
documentBuilder.append(convert(leveledText.toString(), markupLanguage));
|
||||
documentBuilder.append(newLine);
|
||||
}
|
||||
}
|
||||
|
||||
protected void importMarkupStyle2(Pattern titlePattern, String titleFormat, boolean startFrom0, Reader markupText, MarkupLanguage markupLanguage, int levelOffset) {
|
||||
Validate.isTrue(levelOffset <= MAX_TITLE_LEVEL, String.format("Specified levelOffset (%d) > max levelOffset (%d)", levelOffset, MAX_TITLE_LEVEL));
|
||||
Validate.isTrue(levelOffset >= -MAX_TITLE_LEVEL, String.format("Specified levelOffset (%d) < min levelOffset (%d)", levelOffset, -MAX_TITLE_LEVEL));
|
||||
|
||||
StringBuffer leveledText = new StringBuffer();
|
||||
try (BufferedReader bufferedReader = new BufferedReader(markupText)) {
|
||||
String readLine;
|
||||
while ((readLine = bufferedReader.readLine()) != null) {
|
||||
Matcher titleMatcher = titlePattern.matcher(readLine);
|
||||
|
||||
while (titleMatcher.find()) {
|
||||
int titleLevel = Integer.valueOf(titleMatcher.group(1)) - (startFrom0 ? 0 : 1);
|
||||
String title = titleMatcher.group(2);
|
||||
|
||||
if (titleLevel + levelOffset > MAX_TITLE_LEVEL)
|
||||
throw new IllegalArgumentException(String.format("Specified levelOffset (%d) set title '%s' level (%d) > max title level (%d)", levelOffset, title, titleLevel, MAX_TITLE_LEVEL));
|
||||
if (titleLevel + levelOffset < 0)
|
||||
throw new IllegalArgumentException(String.format("Specified levelOffset (%d) set title '%s' level (%d) < 0", levelOffset, title, titleLevel));
|
||||
else
|
||||
titleMatcher.appendReplacement(leveledText, Matcher.quoteReplacement(String.format(titleFormat, (startFrom0 ? 0 : 1) + titleLevel + levelOffset, title)));
|
||||
}
|
||||
titleMatcher.appendTail(leveledText);
|
||||
leveledText.append(newLine);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to import Markup", e);
|
||||
}
|
||||
|
||||
if (!StringUtils.isBlank(leveledText)) {
|
||||
documentBuilder.append(newLine);
|
||||
documentBuilder.append(convert(leveledText.toString(), markupLanguage));
|
||||
documentBuilder.append(newLine);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder table(List<List<String>> cells) {
|
||||
Validate.notEmpty(cells, "cells must not be null");
|
||||
return tableWithColumnSpecs(null, cells);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return documentBuilder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path addFileExtension(Path file) {
|
||||
return file.resolveSibling(addFileExtension(file.getFileName().toString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 2 newLines are needed at the end of file for file to be included without protection.
|
||||
*/
|
||||
@Override
|
||||
public void writeToFileWithoutExtension(Path file, Charset charset, OpenOption... options) {
|
||||
try {
|
||||
Files.createDirectories(file.getParent());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed create directory", e);
|
||||
}
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(file, charset, options)) {
|
||||
writer.write(toString());
|
||||
writer.write(newLine);
|
||||
writer.write(newLine);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to write file", e);
|
||||
}
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Markup document written to: {}", file);
|
||||
}
|
||||
}
|
||||
|
||||
public String replaceNewLines(String content, String replacement) {
|
||||
return content.replaceAll(NEW_LINES, Matcher.quoteReplacement(replacement));
|
||||
}
|
||||
|
||||
public String replaceNewLines(String content) {
|
||||
return replaceNewLines(content, newLine);
|
||||
}
|
||||
|
||||
public String replaceNewLinesWithWhiteSpace(String content) {
|
||||
return replaceNewLines(content, WHITESPACE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToFile(Path file, Charset charset, OpenOption... options) {
|
||||
writeToFileWithoutExtension(file.resolveSibling(addFileExtension(file.getFileName().toString())), charset, options);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.swagger2markup.markup.builder.internal;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public interface Markup {
|
||||
String toString();
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.swagger2markup.markup.builder.internal.asciidoc;
|
||||
|
||||
|
||||
import io.github.swagger2markup.markup.builder.internal.Markup;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public enum AsciiDoc implements Markup {
|
||||
TABLE("|==="),
|
||||
TABLE_COLUMN_DELIMITER("|"),
|
||||
TITLE("="),
|
||||
DOCUMENT_TITLE("= "),
|
||||
LITERAL("`"),
|
||||
BOLD("**"),
|
||||
ITALIC("__"),
|
||||
LIST_ENTRY("* "),
|
||||
CROSS_REFERENCE_START("<<"),
|
||||
CROSS_REFERENCE_END(">>"),
|
||||
ANCHOR_START("[["),
|
||||
ANCHOR_END("]]"),
|
||||
SPACE_ESCAPE("_"),
|
||||
LINE_BREAK(" +");
|
||||
|
||||
private final String markup;
|
||||
|
||||
/**
|
||||
* @param markup AsciiDoc markup
|
||||
*/
|
||||
AsciiDoc(final String markup) {
|
||||
this.markup = markup;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Enum#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return markup;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,266 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.swagger2markup.markup.builder.internal.asciidoc;
|
||||
|
||||
import io.github.swagger2markup.markup.builder.*;
|
||||
import io.github.swagger2markup.markup.builder.internal.AbstractMarkupDocBuilder;
|
||||
import io.github.swagger2markup.markup.builder.internal.Markup;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Reader;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.*;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class AsciiDocBuilder extends AbstractMarkupDocBuilder {
|
||||
|
||||
private static final Pattern TITLE_PATTERN = Pattern.compile(String.format("^(%s{1,%d})\\s+(.*)$", AsciiDoc.TITLE, MAX_TITLE_LEVEL + 1));
|
||||
|
||||
private static final Map<MarkupBlockStyle, String> BLOCK_STYLE = new HashMap<MarkupBlockStyle, String>() {{
|
||||
put(MarkupBlockStyle.EXAMPLE, "====");
|
||||
put(MarkupBlockStyle.LISTING, "----");
|
||||
put(MarkupBlockStyle.LITERAL, "....");
|
||||
put(MarkupBlockStyle.PASSTHROUGH, "++++");
|
||||
put(MarkupBlockStyle.SIDEBAR, "****");
|
||||
}};
|
||||
|
||||
public AsciiDocBuilder() {
|
||||
super();
|
||||
}
|
||||
|
||||
public AsciiDocBuilder(String newLine) {
|
||||
super(newLine);
|
||||
}
|
||||
|
||||
protected MarkupLanguage getMarkupLanguage() {
|
||||
return MarkupLanguage.ASCIIDOC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder copy(boolean copyBuffer) {
|
||||
AsciiDocBuilder builder = new AsciiDocBuilder(newLine);
|
||||
|
||||
if (copyBuffer)
|
||||
builder.documentBuilder = new StringBuilder(this.documentBuilder);
|
||||
|
||||
return builder.withAnchorPrefix(anchorPrefix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder documentTitle(String title) {
|
||||
documentTitle(AsciiDoc.DOCUMENT_TITLE, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleLevel(int level, String title) {
|
||||
sectionTitleLevel(AsciiDoc.TITLE, level, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel(int level, String title, String anchor) {
|
||||
sectionTitleWithAnchorLevel(AsciiDoc.TITLE, level, title, anchor);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder paragraph(String text, boolean hardbreaks) {
|
||||
Validate.notBlank(text, "text must not be blank");
|
||||
if (hardbreaks)
|
||||
documentBuilder.append("[%hardbreaks]").append(newLine);
|
||||
text = text.trim();
|
||||
documentBuilder.append(replaceNewLines(text)).append(newLine).append(newLine);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder pageBreak() {
|
||||
documentBuilder.append(newLine).append("<<<").append(newLine);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder block(String text, final MarkupBlockStyle style, String title, MarkupAdmonition admonition) {
|
||||
if (admonition != null)
|
||||
documentBuilder.append("[").append(admonition).append("]").append(newLine);
|
||||
if (title != null)
|
||||
documentBuilder.append(".").append(title).append(newLine);
|
||||
|
||||
delimitedBlockText(new Markup() {
|
||||
public String toString() {
|
||||
return BLOCK_STYLE.get(style);
|
||||
}
|
||||
}, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder literalText(String text) {
|
||||
boldText(AsciiDoc.LITERAL, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder boldText(String text) {
|
||||
boldText(AsciiDoc.BOLD, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder italicText(String text) {
|
||||
italicText(AsciiDoc.ITALIC, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder unorderedList(List<String> list) {
|
||||
unorderedList(AsciiDoc.LIST_ENTRY, list);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder unorderedListItem(String item) {
|
||||
unorderedListItem(AsciiDoc.LIST_ENTRY, item);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder listingBlock(String text, String language) {
|
||||
if (language != null)
|
||||
documentBuilder.append(String.format("[source,%s]", language)).append(newLine);
|
||||
block(text, MarkupBlockStyle.LISTING);
|
||||
return this;
|
||||
}
|
||||
|
||||
private String normalizeAnchor(String anchor) {
|
||||
String normalizedAnchor = "_" + normalizeAnchor(AsciiDoc.SPACE_ESCAPE, anchor);
|
||||
|
||||
if (normalizedAnchor.endsWith("-"))
|
||||
normalizedAnchor += "_";
|
||||
|
||||
return normalizedAnchor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Partial workaround for https://github.com/asciidoctor/asciidoctor/issues/844
|
||||
*/
|
||||
private String normalizeDocument(String document) {
|
||||
if (document == null)
|
||||
return null;
|
||||
|
||||
return new File(document).toPath().normalize().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder anchor(String anchor, String text) {
|
||||
documentBuilder.append(AsciiDoc.ANCHOR_START).append(normalizeAnchor(anchor));
|
||||
if (text != null)
|
||||
documentBuilder.append(",").append(text);
|
||||
documentBuilder.append(AsciiDoc.ANCHOR_END);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder crossReferenceRaw(String document, String anchor, String text) {
|
||||
documentBuilder.append(AsciiDoc.CROSS_REFERENCE_START);
|
||||
if (document != null)
|
||||
documentBuilder.append(document).append("#");
|
||||
documentBuilder.append(anchor);
|
||||
if (text != null) {
|
||||
documentBuilder.append(",").append(text);
|
||||
if (text.endsWith(">"))
|
||||
documentBuilder.append(" ");
|
||||
}
|
||||
documentBuilder.append(AsciiDoc.CROSS_REFERENCE_END);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder crossReference(String document, String anchor, String text) {
|
||||
return crossReferenceRaw(normalizeDocument(document), normalizeAnchor(anchor), text);
|
||||
}
|
||||
|
||||
private String formatTableCell(String cell) {
|
||||
cell = replaceNewLines(cell.trim());
|
||||
return cell.replace(AsciiDoc.TABLE_COLUMN_DELIMITER.toString(), "\\" + AsciiDoc.TABLE_COLUMN_DELIMITER.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder tableWithColumnSpecs(List<MarkupTableColumn> columnSpecs, List<List<String>> cells) {
|
||||
Validate.notEmpty(cells, "cells must not be null");
|
||||
Boolean hasHeader = false;
|
||||
List<String> options = new ArrayList<>();
|
||||
List<String> cols = new ArrayList<>();
|
||||
if (columnSpecs != null && !columnSpecs.isEmpty()) {
|
||||
for (MarkupTableColumn col : columnSpecs) {
|
||||
if (!hasHeader && isNotBlank(col.header)) {
|
||||
options.add("header");
|
||||
hasHeader = true;
|
||||
}
|
||||
String languageStyle = col.markupSpecifiers.get(MarkupLanguage.ASCIIDOC);
|
||||
if (languageStyle != null && isNoneBlank(languageStyle)) {
|
||||
cols.add(languageStyle);
|
||||
} else {
|
||||
cols.add(String.valueOf(col.widthRatio) + (col.headerColumn ? "h" : ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
newLine();
|
||||
documentBuilder.append("[options=\"").append(join(options, ",")).append("\", cols=\"").append(join(cols, ",")).append("\"]").append(newLine);
|
||||
documentBuilder.append(AsciiDoc.TABLE).append(newLine);
|
||||
if (hasHeader) {
|
||||
Collection<String> headerList = columnSpecs.stream().map(header -> formatTableCell(defaultString(header.header))).collect(Collectors.toList());
|
||||
documentBuilder.append(AsciiDoc.TABLE_COLUMN_DELIMITER).append(join(headerList, AsciiDoc.TABLE_COLUMN_DELIMITER.toString())).append(newLine);
|
||||
|
||||
}
|
||||
for (List<String> row : cells) {
|
||||
Collection<String> cellList = row.stream().map(cell -> formatTableCell(defaultString(cell))).collect(Collectors.toList());
|
||||
documentBuilder.append(AsciiDoc.TABLE_COLUMN_DELIMITER).append(join(cellList, AsciiDoc.TABLE_COLUMN_DELIMITER.toString())).append(newLine);
|
||||
}
|
||||
documentBuilder.append(AsciiDoc.TABLE).append(newLine);
|
||||
newLine();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder newLine(boolean forceLineBreak) {
|
||||
newLine(AsciiDoc.LINE_BREAK, forceLineBreak);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder importMarkup(Reader markupText, MarkupLanguage markupLanguage, int levelOffset) {
|
||||
importMarkupStyle1(TITLE_PATTERN, AsciiDoc.TITLE, markupText, markupLanguage, levelOffset);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String addFileExtension(String fileName) {
|
||||
return fileName + MarkupLanguage.ASCIIDOC.getFileNameExtensions().get(0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.swagger2markup.markup.builder.internal.confluenceMarkup;
|
||||
|
||||
|
||||
import io.github.swagger2markup.markup.builder.internal.Markup;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public enum ConfluenceMarkup implements Markup {
|
||||
TABLE_COLUMN_DELIMITER("|"),
|
||||
LITERAL("{noformat}"),
|
||||
BOLD("*"),
|
||||
ITALIC("_"),
|
||||
LIST_ENTRY("* "),
|
||||
ANCHOR_START("{anchor:"),
|
||||
ANCHOR_END("}"),
|
||||
SPACE_ESCAPE("_"),
|
||||
LINE_BREAK("\\\\ ");
|
||||
|
||||
private final String markup;
|
||||
|
||||
/**
|
||||
* @param markup AsciiDoc markup
|
||||
*/
|
||||
ConfluenceMarkup(final String markup) {
|
||||
this.markup = markup;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Enum#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return markup;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,345 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.swagger2markup.markup.builder.internal.confluenceMarkup;
|
||||
|
||||
import io.github.swagger2markup.markup.builder.*;
|
||||
import io.github.swagger2markup.markup.builder.internal.AbstractMarkupDocBuilder;
|
||||
import io.github.swagger2markup.markup.builder.internal.Markup;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.*;
|
||||
|
||||
public final class ConfluenceMarkupBuilder extends AbstractMarkupDocBuilder {
|
||||
|
||||
private static final Pattern TITLE_PATTERN = Pattern.compile("^h([0-9])\\.\\s+(.*)$");
|
||||
private static final String TITLE_FORMAT = "h%d. %s";
|
||||
private static final Pattern ESCAPE_CELL_PIPE_PATTERN = Pattern.compile("((\\[.*?(?<!\\\\)\\])|(.))");
|
||||
|
||||
/**
|
||||
* Associate macro name to block style.<br>
|
||||
* ending ':' means the macro supports title attribute.<br>
|
||||
* '>ADMONITION_BLOCK' means value should refer to {@link #ADMONITION_BLOCK_STYLE}.
|
||||
*/
|
||||
private static final Map<MarkupBlockStyle, String> BLOCK_STYLE = new HashMap<MarkupBlockStyle, String>() {{
|
||||
put(MarkupBlockStyle.EXAMPLE, ">ADMONITION_BLOCK");
|
||||
put(MarkupBlockStyle.LISTING, "code:");
|
||||
put(MarkupBlockStyle.LITERAL, "noformat");
|
||||
put(MarkupBlockStyle.PASSTHROUGH, "html");
|
||||
put(MarkupBlockStyle.SIDEBAR, ">ADMONITION_BLOCK");
|
||||
}};
|
||||
|
||||
private static final Map<MarkupAdmonition, String> ADMONITION_BLOCK_STYLE = new HashMap<MarkupAdmonition, String>() {{
|
||||
put(null, "panel:");
|
||||
put(MarkupAdmonition.CAUTION, "note:");
|
||||
put(MarkupAdmonition.IMPORTANT, "alert:");
|
||||
put(MarkupAdmonition.NOTE, "info:");
|
||||
put(MarkupAdmonition.TIP, "tip:");
|
||||
put(MarkupAdmonition.WARNING, "warning:");
|
||||
}};
|
||||
|
||||
public ConfluenceMarkupBuilder() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ConfluenceMarkupBuilder(String newLine) {
|
||||
super(newLine);
|
||||
}
|
||||
|
||||
protected MarkupLanguage getMarkupLanguage() {
|
||||
return MarkupLanguage.CONFLUENCE_MARKUP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder copy(boolean copyBuffer) {
|
||||
ConfluenceMarkupBuilder builder = new ConfluenceMarkupBuilder(newLine);
|
||||
|
||||
if (copyBuffer)
|
||||
builder.documentBuilder = new StringBuilder(this.documentBuilder);
|
||||
|
||||
return builder.withAnchorPrefix(anchorPrefix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder documentTitle(String title) {
|
||||
Validate.notBlank(title, "title must not be blank");
|
||||
documentBuilder.append(String.format(TITLE_FORMAT, 1, title));
|
||||
documentBuilder.append(newLine).append(newLine);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleLevel(int level, String title) {
|
||||
Validate.notBlank(title, "title must not be blank");
|
||||
Validate.inclusiveBetween(1, MAX_TITLE_LEVEL, level);
|
||||
|
||||
documentBuilder.append(newLine);
|
||||
documentBuilder.append(String.format(TITLE_FORMAT, level + 1, replaceNewLinesWithWhiteSpace(title)));
|
||||
documentBuilder.append(newLine);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel(int level, String title, String anchor) {
|
||||
Validate.notBlank(title, "title must not be blank");
|
||||
Validate.inclusiveBetween(1, MAX_TITLE_LEVEL, level);
|
||||
|
||||
documentBuilder.append(newLine);
|
||||
documentBuilder.append(String.format(TITLE_FORMAT, level + 1, replaceNewLinesWithWhiteSpace(title)));
|
||||
if (isBlank(anchor))
|
||||
anchor = title;
|
||||
documentBuilder.append(" ");
|
||||
anchor(replaceNewLinesWithWhiteSpace(anchor));
|
||||
|
||||
documentBuilder.append(newLine);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder paragraph(String text, boolean hardbreaks) {
|
||||
Validate.notBlank(text, "text must not be blank");
|
||||
|
||||
text = text.trim();
|
||||
if (hardbreaks)
|
||||
text = replaceNewLines(text, ConfluenceMarkup.LINE_BREAK + newLine);
|
||||
else
|
||||
text = replaceNewLines(text);
|
||||
documentBuilder.append(text).append(newLine).append(newLine);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder pageBreak() {
|
||||
documentBuilder.append(newLine).append("<div style='page-break-before:always;'></div>").append(newLine);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder block(String text, final MarkupBlockStyle style, String title, MarkupAdmonition admonition) {
|
||||
|
||||
String block = BLOCK_STYLE.get(style);
|
||||
|
||||
boolean admonitionBlock = block.equals(">ADMONITION_BLOCK");
|
||||
if (admonitionBlock) {
|
||||
block = ADMONITION_BLOCK_STYLE.get(admonition);
|
||||
}
|
||||
|
||||
boolean supportTitle = false;
|
||||
if (block.endsWith(":")) {
|
||||
supportTitle = true;
|
||||
block = StringUtils.stripEnd(block, ":");
|
||||
}
|
||||
|
||||
String titleString = null;
|
||||
if (admonition != null && !admonitionBlock) {
|
||||
titleString = StringUtils.capitalize(admonition.name().toLowerCase());
|
||||
}
|
||||
if (title != null) {
|
||||
titleString = (titleString == null ? "" : titleString + " | ") + title;
|
||||
}
|
||||
|
||||
final String finalBlock = block;
|
||||
Markup blockMarkup = new Markup() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("{%s}", finalBlock);
|
||||
}
|
||||
};
|
||||
|
||||
if (!supportTitle) {
|
||||
if (titleString != null)
|
||||
documentBuilder.append(titleString).append(" : ").append(newLine);
|
||||
delimitedBlockText(blockMarkup, text);
|
||||
} else {
|
||||
final String finalTitleString = titleString;
|
||||
delimitedBlockText(new Markup() {
|
||||
@Override
|
||||
public String toString() {
|
||||
if (finalTitleString == null)
|
||||
return String.format("{%s}", finalBlock);
|
||||
else
|
||||
return String.format("{%s:title=%s}", finalBlock, finalTitleString);
|
||||
}
|
||||
}, text, blockMarkup);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder listingBlock(String text, final String language) {
|
||||
Markup blockMarkup = new Markup() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("{%s}", "code");
|
||||
}
|
||||
};
|
||||
|
||||
if (language != null) {
|
||||
delimitedBlockText(new Markup() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("{code:language=%s}", language);
|
||||
}
|
||||
}, text, blockMarkup);
|
||||
} else {
|
||||
delimitedBlockText(blockMarkup, text);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder literalText(String text) {
|
||||
boldText(ConfluenceMarkup.LITERAL, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder boldText(String text) {
|
||||
boldText(ConfluenceMarkup.BOLD, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder italicText(String text) {
|
||||
italicText(ConfluenceMarkup.ITALIC, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder unorderedList(List<String> list) {
|
||||
unorderedList(ConfluenceMarkup.LIST_ENTRY, list);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder unorderedListItem(String item) {
|
||||
unorderedListItem(ConfluenceMarkup.LIST_ENTRY, item);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder tableWithColumnSpecs(List<MarkupTableColumn> columnSpecs, List<List<String>> cells) {
|
||||
Validate.notEmpty(cells, "cells must not be null");
|
||||
documentBuilder.append(newLine);
|
||||
if (columnSpecs != null && !columnSpecs.isEmpty()) {
|
||||
documentBuilder.append("||");
|
||||
for (MarkupTableColumn column : columnSpecs) {
|
||||
documentBuilder.append(formatCellContent(defaultString(column.header))).append("||");
|
||||
}
|
||||
documentBuilder.append(newLine);
|
||||
}
|
||||
for (List<String> row : cells) {
|
||||
documentBuilder.append(ConfluenceMarkup.TABLE_COLUMN_DELIMITER);
|
||||
ListIterator<String> cellIterator = row.listIterator();
|
||||
while (cellIterator.hasNext()) {
|
||||
int cellIndex = cellIterator.nextIndex();
|
||||
if (columnSpecs != null && columnSpecs.size() > cellIndex && columnSpecs.get(cellIndex).headerColumn)
|
||||
documentBuilder.append(ConfluenceMarkup.TABLE_COLUMN_DELIMITER);
|
||||
|
||||
documentBuilder.append(formatCellContent(cellIterator.next())).append(ConfluenceMarkup.TABLE_COLUMN_DELIMITER);
|
||||
}
|
||||
documentBuilder.append(newLine);
|
||||
}
|
||||
documentBuilder.append(newLine);
|
||||
return this;
|
||||
}
|
||||
|
||||
private String formatCellContent(String cell) {
|
||||
cell = replaceNewLines(cell.trim(), ConfluenceMarkup.LINE_BREAK.toString());
|
||||
if (isBlank(cell)) {
|
||||
return " ";
|
||||
}
|
||||
return escapeCellPipes(cell);
|
||||
}
|
||||
|
||||
private String escapeCellPipes(String cell) {
|
||||
Matcher m = ESCAPE_CELL_PIPE_PATTERN.matcher(cell);
|
||||
|
||||
StringBuffer res = new StringBuffer();
|
||||
while (m.find()) {
|
||||
String repl = m.group(1);
|
||||
if (repl.equals(ConfluenceMarkup.TABLE_COLUMN_DELIMITER.toString()))
|
||||
repl = "\\" + ConfluenceMarkup.TABLE_COLUMN_DELIMITER.toString();
|
||||
m.appendReplacement(res, Matcher.quoteReplacement(repl));
|
||||
}
|
||||
m.appendTail(res);
|
||||
|
||||
return res.toString();
|
||||
}
|
||||
|
||||
private String normalizeAnchor(String anchor) {
|
||||
return normalizeAnchor(ConfluenceMarkup.SPACE_ESCAPE, anchor);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder anchor(String anchor, String text) {
|
||||
documentBuilder.append(ConfluenceMarkup.ANCHOR_START).append(normalizeAnchor(anchor)).append(ConfluenceMarkup.ANCHOR_END);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder crossReference(String document, String anchor, String text) {
|
||||
crossReferenceRaw(document, normalizeAnchor(anchor), text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder crossReferenceRaw(String document, String anchor, String text) {
|
||||
documentBuilder.append("[");
|
||||
if (isNotBlank(text)) {
|
||||
documentBuilder.append(text).append("|");
|
||||
}
|
||||
if (isNotBlank(document)) {
|
||||
documentBuilder.append(document);
|
||||
}
|
||||
documentBuilder.append("#").append(anchor);
|
||||
documentBuilder.append("]");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder newLine(boolean forceLineBreak) {
|
||||
newLine(ConfluenceMarkup.LINE_BREAK, forceLineBreak);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder importMarkup(Reader markupText, MarkupLanguage markupLanguage, int levelOffset) {
|
||||
importMarkupStyle2(TITLE_PATTERN, TITLE_FORMAT, false, markupText, markupLanguage, levelOffset);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String addFileExtension(String fileName) {
|
||||
return fileName + MarkupLanguage.CONFLUENCE_MARKUP.getFileNameExtensions().get(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.swagger2markup.markup.builder.internal.markdown;
|
||||
|
||||
import io.github.swagger2markup.markup.builder.internal.Markup;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public enum Markdown implements Markup {
|
||||
TABLE_COLUMN_DELIMITER("|"),
|
||||
TABLE_ROW("-"),
|
||||
LISTING("```"),
|
||||
TITLE("#"),
|
||||
DOCUMENT_TITLE("# "),
|
||||
LITERAL("`"),
|
||||
BOLD("**"),
|
||||
ITALIC("*"),
|
||||
LIST_ENTRY("* "),
|
||||
SPACE_ESCAPE("-"),
|
||||
LINE_BREAK(" ");
|
||||
|
||||
private final String markup;
|
||||
|
||||
/**
|
||||
* @param markup AsciiDoc markup
|
||||
*/
|
||||
private Markdown(final String markup) {
|
||||
this.markup = markup;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Enum#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return markup;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.swagger2markup.markup.builder.internal.markdown;
|
||||
|
||||
import io.github.swagger2markup.markup.builder.*;
|
||||
import io.github.swagger2markup.markup.builder.internal.AbstractMarkupDocBuilder;
|
||||
import io.github.swagger2markup.markup.builder.internal.Markup;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||
import static org.apache.commons.lang3.StringUtils.join;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class MarkdownBuilder extends AbstractMarkupDocBuilder {
|
||||
|
||||
private static final Pattern TITLE_PATTERN = Pattern.compile(String.format("^(%s{1,%d})\\s+(.*)$", Markdown.TITLE, MAX_TITLE_LEVEL + 1));
|
||||
|
||||
private static final Map<MarkupBlockStyle, String> BLOCK_STYLE = new HashMap<MarkupBlockStyle, String>() {{
|
||||
put(MarkupBlockStyle.EXAMPLE, "");
|
||||
put(MarkupBlockStyle.LISTING, Markdown.LISTING.toString());
|
||||
put(MarkupBlockStyle.LITERAL, Markdown.LISTING.toString());
|
||||
put(MarkupBlockStyle.PASSTHROUGH, "");
|
||||
put(MarkupBlockStyle.SIDEBAR, "");
|
||||
}};
|
||||
|
||||
public MarkdownBuilder() {
|
||||
super();
|
||||
}
|
||||
|
||||
public MarkdownBuilder(String newLine) {
|
||||
super(newLine);
|
||||
}
|
||||
|
||||
protected MarkupLanguage getMarkupLanguage() {
|
||||
return MarkupLanguage.MARKDOWN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder copy(boolean copyBuffer) {
|
||||
MarkdownBuilder builder = new MarkdownBuilder(newLine);
|
||||
|
||||
if (copyBuffer)
|
||||
builder.documentBuilder = new StringBuilder(this.documentBuilder);
|
||||
|
||||
return builder.withAnchorPrefix(anchorPrefix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder documentTitle(String title) {
|
||||
documentTitle(Markdown.DOCUMENT_TITLE, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleLevel(int level, String title) {
|
||||
sectionTitleLevel(Markdown.TITLE, level, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel(int level, String title, String anchor) {
|
||||
sectionTitleWithAnchorLevel(Markdown.TITLE, level, title, anchor);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder paragraph(String text, boolean hardbreaks) {
|
||||
Validate.notBlank(text, "text must not be blank");
|
||||
|
||||
text = text.trim();
|
||||
if (hardbreaks)
|
||||
text = replaceNewLines(text, Markdown.LINE_BREAK + newLine);
|
||||
else
|
||||
text = replaceNewLines(text);
|
||||
documentBuilder.append(text).append(newLine).append(newLine);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder pageBreak() {
|
||||
documentBuilder.append(newLine).append("***").append(newLine);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder block(String text, final MarkupBlockStyle style, String title, MarkupAdmonition admonition) {
|
||||
boolean multiline = text.contains(newLine);
|
||||
|
||||
if (admonition != null)
|
||||
documentBuilder.append(StringUtils.capitalize(admonition.name().toLowerCase()));
|
||||
if (title != null) {
|
||||
if (admonition != null)
|
||||
documentBuilder.append(" | ");
|
||||
documentBuilder.append(title);
|
||||
}
|
||||
if (admonition != null || title != null)
|
||||
documentBuilder.append(" : ").append(newLine);
|
||||
|
||||
Markup m = new Markup() {
|
||||
public String toString() {
|
||||
return BLOCK_STYLE.get(style);
|
||||
}
|
||||
};
|
||||
|
||||
if (style == MarkupBlockStyle.LISTING && multiline) {
|
||||
delimitedBlockText(m, text, m, true);
|
||||
} else {
|
||||
delimitedBlockText(m, text, m);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder listingBlock(String text, String language) {
|
||||
text = newLine + text;
|
||||
if (language != null) {
|
||||
text = language + text;
|
||||
}
|
||||
block(text, MarkupBlockStyle.LISTING);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder literalText(String text) {
|
||||
boldText(Markdown.LITERAL, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder boldText(String text) {
|
||||
boldText(Markdown.BOLD, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder italicText(String text) {
|
||||
italicText(Markdown.ITALIC, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder unorderedList(List<String> list) {
|
||||
unorderedList(Markdown.LIST_ENTRY, list);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder unorderedListItem(String item) {
|
||||
unorderedListItem(Markdown.LIST_ENTRY, item);
|
||||
return this;
|
||||
}
|
||||
|
||||
private String normalizeAnchor(String anchor) {
|
||||
return normalizeAnchor(Markdown.SPACE_ESCAPE, anchor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder anchor(String anchor, String text) {
|
||||
documentBuilder.append("<a name=\"").append(normalizeAnchor(anchor)).append("\"></a>");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder crossReferenceRaw(String document, String anchor, String text) {
|
||||
if (text == null)
|
||||
text = anchor.trim();
|
||||
documentBuilder.append("[").append(text).append("]").append("(");
|
||||
if (document != null)
|
||||
documentBuilder.append(document);
|
||||
documentBuilder.append("#").append(anchor).append(")");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder crossReference(String document, String anchor, String text) {
|
||||
return crossReferenceRaw(document, normalizeAnchor(anchor), text);
|
||||
}
|
||||
|
||||
private String formatTableCell(String cell) {
|
||||
cell = replaceNewLines(cell.trim(), "<br>");
|
||||
return cell.replace(Markdown.TABLE_COLUMN_DELIMITER.toString(), "\\" + Markdown.TABLE_COLUMN_DELIMITER.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder tableWithColumnSpecs(List<MarkupTableColumn> columnSpecs, List<List<String>> cells) {
|
||||
Validate.notEmpty(cells, "cells must not be null");
|
||||
newLine();
|
||||
if (columnSpecs != null && !columnSpecs.isEmpty()) {
|
||||
Collection<String> headerList = columnSpecs.stream().map(header -> formatTableCell(defaultString(header.header))).collect(Collectors.toList());
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER).append(join(headerList, Markdown.TABLE_COLUMN_DELIMITER.toString())).append(Markdown.TABLE_COLUMN_DELIMITER).append(newLine);
|
||||
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER);
|
||||
columnSpecs.forEach(col -> {
|
||||
documentBuilder.append(StringUtils.repeat(Markdown.TABLE_ROW.toString(), 3));
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER);
|
||||
});
|
||||
documentBuilder.append(newLine);
|
||||
}
|
||||
|
||||
for (List<String> row : cells) {
|
||||
Collection<String> cellList = row.stream().map(cell -> formatTableCell(defaultString(cell))).collect(Collectors.toList());
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER).append(join(cellList, Markdown.TABLE_COLUMN_DELIMITER.toString())).append(Markdown.TABLE_COLUMN_DELIMITER).append(newLine);
|
||||
}
|
||||
newLine();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder newLine(boolean forceLineBreak) {
|
||||
newLine(Markdown.LINE_BREAK, forceLineBreak);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder importMarkup(Reader markupText, MarkupLanguage markupLanguage, int levelOffset) {
|
||||
importMarkupStyle1(TITLE_PATTERN, Markdown.TITLE, markupText, markupLanguage, levelOffset);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String addFileExtension(String fileName) {
|
||||
return fileName + MarkupLanguage.MARKDOWN.getFileNameExtensions().get(0);
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
package io.github.robwin.markup.builder;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class MarkupDocBuilderTest {
|
||||
|
||||
List<String> tableRowsInPSV;
|
||||
|
||||
@Before
|
||||
public void setUp(){
|
||||
tableRowsInPSV = new ArrayList<>();
|
||||
tableRowsInPSV.add("Header 1 | Header 2 | Header2");
|
||||
tableRowsInPSV.add("Row 1, Column 1 | Row 1, Column 2 | Row 1, Column 3");
|
||||
tableRowsInPSV.add("Row 2, Column 1 | Row 2, Column 2 | Row 2, Column 3");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testToAsciiDocFile() throws IOException {
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC);
|
||||
builder.documentTitle("Test title")
|
||||
.sectionTitleLevel1("Section Level 1a")
|
||||
.sectionTitleLevel2("Section Level 2a")
|
||||
.sectionTitleLevel3("Section Level 3a")
|
||||
.paragraph("Paragraph with long text bla bla bla bla bla")
|
||||
.listing("Source code listing")
|
||||
.source("MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC)", "java")
|
||||
.tableWithHeaderRow(tableRowsInPSV)
|
||||
.sectionTitleLevel1("Section Level 1b")
|
||||
.sectionTitleLevel2("Section Level 2b")
|
||||
.boldTextLine("Bold text line b")
|
||||
.italicTextLine("Italic text line b")
|
||||
.unorderedList(Arrays.asList("Entry1", "Entry2", "Entry 2"))
|
||||
.writeToFile("build/tmp", "test", StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToMarkdownDocFile() throws IOException {
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN);
|
||||
builder.documentTitle("Test title")
|
||||
.sectionTitleLevel1("Section Level 1a")
|
||||
.sectionTitleLevel2("Section Level 2a")
|
||||
.sectionTitleLevel3("Section Level 3a")
|
||||
.paragraph("Paragraph with long text bla bla bla bla bla")
|
||||
.listing("Source code listing")
|
||||
.source("MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN)", "java")
|
||||
.tableWithHeaderRow(tableRowsInPSV)
|
||||
.sectionTitleLevel1("Section Level 1b")
|
||||
.sectionTitleLevel2("Section Level 2b")
|
||||
.boldTextLine("Bold text line b")
|
||||
.italicTextLine("Italic text line b")
|
||||
.unorderedList(Arrays.asList("Entry1", "Entry2", "Entry 2"))
|
||||
.writeToFile("build/tmp", "test", StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,538 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.swagger2markup.markup.builder;
|
||||
|
||||
import io.github.swagger2markup.markup.builder.assertions.DiffUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class MarkupDocBuilderTest {
|
||||
|
||||
private final String newLine = System.getProperty("line.separator");
|
||||
|
||||
private List<MarkupTableColumn> tableColumns;
|
||||
private List<List<String>> tableCells;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
tableColumns = Arrays.asList(
|
||||
new MarkupTableColumn().withHeader("Header1"),
|
||||
new MarkupTableColumn().withWidthRatio(2),
|
||||
new MarkupTableColumn().withHeader("Header3").withWidthRatio(1).withHeaderColumn(true));
|
||||
tableCells = new ArrayList<>();
|
||||
tableCells.add(Arrays.asList("Row 1 | Column 1", "Row 1 | Column 2", "Row 1 | Column 3"));
|
||||
tableCells.add(Arrays.asList("Row 2 | Column 1", "Row 2 | Column 2", "Row 2 | Column 3"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAsciiDoc() throws IOException, URISyntaxException {
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC);
|
||||
|
||||
builder = builder.documentTitle("Test title")
|
||||
.sectionTitleLevel(1, "Section Level 1a")
|
||||
.sectionTitleWithAnchorLevel(1, "Section with anchor Level 1a", "level-1a")
|
||||
.sectionTitleWithAnchorLevel(1, "Section with anchor Level 1a")
|
||||
.sectionTitleLevel(2, "Section Level 2a")
|
||||
.sectionTitleWithAnchorLevel(2, "Section with anchor Level 2a", "level-2a")
|
||||
.sectionTitleWithAnchorLevel(2, "Section with anchor Level 2a")
|
||||
.sectionTitleLevel(3, "Section Level 3a")
|
||||
.sectionTitleWithAnchorLevel(3, "Section with anchor Level 3a", "level-3a")
|
||||
.sectionTitleWithAnchorLevel(3, "Section with anchor Level 3a")
|
||||
.sectionTitleLevel(4, "Section Level 4a")
|
||||
.sectionTitleWithAnchorLevel(4, "Section with anchor Level 4a", "level-4a")
|
||||
.sectionTitleWithAnchorLevel(4, "Section with anchor Level 4a")
|
||||
.sectionTitleLevel(5, "Section Level 5a")
|
||||
.sectionTitleWithAnchorLevel(5, "Section with anchor Level 5a", "level-5a")
|
||||
.sectionTitleWithAnchorLevel(5, "Section with anchor Level 5a")
|
||||
.paragraph("Paragraph with long text bla bla bla bla bla")
|
||||
.paragraph("\rLine1\nLine2\r\n", false)
|
||||
.paragraph("\rLine1\nLine2\r\n", true)
|
||||
.listingBlock("Source code listing")
|
||||
.listingBlock("MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN)", "java")
|
||||
.block("Example", MarkupBlockStyle.EXAMPLE)
|
||||
.block("Example", MarkupBlockStyle.EXAMPLE, "Example", null)
|
||||
.block("Example", MarkupBlockStyle.EXAMPLE, null, MarkupAdmonition.IMPORTANT)
|
||||
.block("Listing", MarkupBlockStyle.LISTING, null, MarkupAdmonition.CAUTION)
|
||||
.block("Literal", MarkupBlockStyle.LITERAL, null, MarkupAdmonition.NOTE)
|
||||
.block("Sidebar", MarkupBlockStyle.SIDEBAR, null, MarkupAdmonition.TIP)
|
||||
.block("Passthrough", MarkupBlockStyle.PASSTHROUGH, null, MarkupAdmonition.WARNING)
|
||||
.pageBreak()
|
||||
.table(tableCells)
|
||||
.tableWithColumnSpecs(tableColumns, tableCells)
|
||||
.sectionTitleLevel1("Section Level 1b")
|
||||
.sectionTitleLevel2("Section Level 2b")
|
||||
.textLine("text line", true)
|
||||
.literalTextLine("Literal text line", true)
|
||||
.boldTextLine("Bold text line", true)
|
||||
.italicTextLine("Italic text line", true)
|
||||
.boldText("bold").italicText("italic").text("regular").newLine(true)
|
||||
.unorderedList(Arrays.asList("Entry1", "Entry2", "Entry 2"))
|
||||
.anchor("anchor", "text").newLine()
|
||||
.anchor(" Simple anchor").newLine()
|
||||
.anchor(" \u0240 µ&|ù This .:/-_# ").newLine()
|
||||
.crossReferenceRaw("./document.adoc", "anchor", "text").newLine(true)
|
||||
.crossReferenceRaw(" \u0240 µ&|ù This .:/-_ ").newLine(true)
|
||||
.crossReference("./document.adoc", "anchor", "text").newLine(true)
|
||||
.crossReference(" \u0240 µ&|ù This .:/-_ ").newLine(true);
|
||||
|
||||
Path outputFile = Paths.get("build/test/asciidoc/test");
|
||||
|
||||
builder.writeToFileWithoutExtension(builder.addFileExtension(outputFile), StandardCharsets.UTF_8);
|
||||
builder.writeToFile(outputFile, StandardCharsets.UTF_8);
|
||||
|
||||
Path expectedFile = Paths.get(MarkupDocBuilderTest.class.getResource("/expected/asciidoc/test.adoc").toURI());
|
||||
DiffUtils.assertThatFileIsEqual(expectedFile, builder.addFileExtension(outputFile), "testAsciiDoc.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAsciiDocWithAnchorPrefix() {
|
||||
MarkupDocBuilder builderWithConfig = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC).withAnchorPrefix(" mdb test- ");
|
||||
String prefixMarkup = builderWithConfig.anchor("anchor", "text")
|
||||
.crossReference("anchor", "text")
|
||||
.toString();
|
||||
|
||||
assertEquals("[[_mdb_test-anchor,text]]<<_mdb_test-anchor,text>>", prefixMarkup);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarkdownCodeBlock() throws IOException, URISyntaxException {
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN);
|
||||
|
||||
builder = builder.listingBlock("$o = new Thing();", "php");
|
||||
Path outputFile = Paths.get("build/test/markdown/test2");
|
||||
builder.writeToFileWithoutExtension(builder.addFileExtension(outputFile), StandardCharsets.UTF_8);
|
||||
builder.writeToFile(outputFile, StandardCharsets.UTF_8);
|
||||
|
||||
Path expectedFile = Paths.get(MarkupDocBuilderTest.class.getResource("/expected/markdown/test2.md").toURI());
|
||||
DiffUtils.assertThatFileIsEqual(expectedFile, builder.addFileExtension(outputFile), "testMarkdown2.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarkdown() throws IOException, URISyntaxException {
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN);
|
||||
|
||||
builder = builder.documentTitle("Test title")
|
||||
.sectionTitleLevel(1, "Section Level 1a")
|
||||
.sectionTitleWithAnchorLevel(1, "Section with anchor Level 1a", "level-1a")
|
||||
.sectionTitleWithAnchorLevel(1, "Section with anchor Level 1a")
|
||||
.sectionTitleLevel(2, "Section Level 2a")
|
||||
.sectionTitleWithAnchorLevel(2, "Section with anchor Level 2a", "level-2a")
|
||||
.sectionTitleWithAnchorLevel(2, "Section with anchor Level 2a")
|
||||
.sectionTitleLevel(3, "Section Level 3a")
|
||||
.sectionTitleWithAnchorLevel(3, "Section with anchor Level 3a", "level-3a")
|
||||
.sectionTitleWithAnchorLevel(3, "Section with anchor Level 3a")
|
||||
.sectionTitleLevel(4, "Section Level 4a")
|
||||
.sectionTitleWithAnchorLevel(4, "Section with anchor Level 4a", "level-4a")
|
||||
.sectionTitleWithAnchorLevel(4, "Section with anchor Level 4a")
|
||||
.sectionTitleLevel(5, "Section Level 5a")
|
||||
.sectionTitleWithAnchorLevel(5, "Section with anchor Level 5a", "level-5a")
|
||||
.sectionTitleWithAnchorLevel(5, "Section with anchor Level 5a")
|
||||
.paragraph("Paragraph with long text bla bla bla bla bla")
|
||||
.paragraph("\rLine1\nLine2\r\n", false)
|
||||
.paragraph("\rLine1\nLine2\r\n", true)
|
||||
.listingBlock("Source code listing")
|
||||
.listingBlock("MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN)", "java")
|
||||
.block("Example", MarkupBlockStyle.EXAMPLE)
|
||||
.block("Example", MarkupBlockStyle.EXAMPLE, "Example", null)
|
||||
.block("Example", MarkupBlockStyle.EXAMPLE, null, MarkupAdmonition.IMPORTANT)
|
||||
.block("Listing", MarkupBlockStyle.LISTING, null, MarkupAdmonition.CAUTION)
|
||||
.block("Literal", MarkupBlockStyle.LITERAL, null, MarkupAdmonition.NOTE)
|
||||
.block("Sidebar", MarkupBlockStyle.SIDEBAR, null, MarkupAdmonition.TIP)
|
||||
.block("Passthrough", MarkupBlockStyle.PASSTHROUGH, null, MarkupAdmonition.WARNING)
|
||||
.pageBreak()
|
||||
//.table(tableCells)
|
||||
.tableWithColumnSpecs(tableColumns, tableCells)
|
||||
.sectionTitleLevel1("Section Level 1b")
|
||||
.sectionTitleLevel2("Section Level 2b")
|
||||
.textLine("text line", true)
|
||||
.literalTextLine("Literal text line", true)
|
||||
.boldTextLine("Bold text line", true)
|
||||
.italicTextLine("Italic text line", true)
|
||||
.boldText("bold").italicText("italic").text("regular").newLine(true)
|
||||
.unorderedList(Arrays.asList("Entry1", "Entry2", "Entry 2"))
|
||||
.anchor("anchor", "text").newLine()
|
||||
.anchor(" Simple anchor").newLine()
|
||||
.anchor(" \u0240 µ&|ù This .:/-_# ").newLine()
|
||||
.crossReferenceRaw("./document.md", "anchor", "text").newLine(true)
|
||||
.crossReferenceRaw(" \u0240 µ&|ù This .:/-_ ").newLine(true)
|
||||
.crossReference("./document.md", "anchor", "text").newLine(true)
|
||||
.crossReference(" \u0240 µ&|ù This .:/-_ ").newLine(true);
|
||||
|
||||
Path outputFile = Paths.get("build/test/markdown/test");
|
||||
|
||||
builder.writeToFileWithoutExtension(builder.addFileExtension(outputFile), StandardCharsets.UTF_8);
|
||||
builder.writeToFile(outputFile, StandardCharsets.UTF_8);
|
||||
|
||||
Path expectedFile = Paths.get(MarkupDocBuilderTest.class.getResource("/expected/markdown/test.md").toURI());
|
||||
DiffUtils.assertThatFileIsEqual(expectedFile, builder.addFileExtension(outputFile), "testMarkdown.html");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarkdownWithAnchorPrefix() {
|
||||
MarkupDocBuilder builderWithConfig = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN).withAnchorPrefix(" mdb test- ");
|
||||
String prefixMarkup = builderWithConfig.anchor("anchor", "text")
|
||||
.crossReference("anchor", "text")
|
||||
.toString();
|
||||
|
||||
assertEquals("<a name=\"mdb-test-anchor\"></a>[text](#mdb-test-anchor)", prefixMarkup);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfluenceMarkup() throws IOException, URISyntaxException {
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.CONFLUENCE_MARKUP);
|
||||
|
||||
builder = builder.documentTitle("Test title")
|
||||
.sectionTitleLevel(1, "Section Level 1a")
|
||||
.sectionTitleWithAnchorLevel(1, "Section with anchor Level 1a", "level-1a")
|
||||
.sectionTitleWithAnchorLevel(1, "Section with anchor Level 1a")
|
||||
.sectionTitleLevel(2, "Section Level 2a")
|
||||
.sectionTitleWithAnchorLevel(2, "Section with anchor Level 2a", "level-2a")
|
||||
.sectionTitleWithAnchorLevel(2, "Section with anchor Level 2a")
|
||||
.sectionTitleLevel(3, "Section Level 3a")
|
||||
.sectionTitleWithAnchorLevel(3, "Section with anchor Level 3a", "level-3a")
|
||||
.sectionTitleWithAnchorLevel(3, "Section with anchor Level 3a")
|
||||
.sectionTitleLevel(4, "Section Level 4a")
|
||||
.sectionTitleWithAnchorLevel(4, "Section with anchor Level 4a", "level-4a")
|
||||
.sectionTitleWithAnchorLevel(4, "Section with anchor Level 4a")
|
||||
.sectionTitleLevel(5, "Section Level 5a")
|
||||
.sectionTitleWithAnchorLevel(5, "Section with anchor Level 5a", "level-5a")
|
||||
.sectionTitleWithAnchorLevel(5, "Section with anchor Level 5a")
|
||||
.paragraph("Paragraph with long text bla bla bla bla bla")
|
||||
.paragraph("\rLine1\nLine2\r\n", false)
|
||||
.paragraph("\rLine1\nLine2\r\n", true)
|
||||
.listingBlock("Source code listing")
|
||||
.listingBlock("MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.CONFLUENCE_MARKUP)", "java")
|
||||
.block("Example", MarkupBlockStyle.EXAMPLE)
|
||||
.block("Example", MarkupBlockStyle.EXAMPLE, "Example", null)
|
||||
.block("Example", MarkupBlockStyle.EXAMPLE, null, MarkupAdmonition.IMPORTANT)
|
||||
.block("Listing", MarkupBlockStyle.LISTING, null, MarkupAdmonition.CAUTION)
|
||||
.block("Literal", MarkupBlockStyle.LITERAL, null, MarkupAdmonition.NOTE)
|
||||
.block("Sidebar", MarkupBlockStyle.SIDEBAR, null, MarkupAdmonition.TIP)
|
||||
.block("Passthrough", MarkupBlockStyle.PASSTHROUGH, null, MarkupAdmonition.WARNING)
|
||||
.pageBreak()
|
||||
.table(tableCells)
|
||||
.tableWithColumnSpecs(tableColumns, tableCells)
|
||||
.sectionTitleLevel1("Section Level 1b")
|
||||
.sectionTitleLevel2("Section Level 2b")
|
||||
.textLine("text line", true)
|
||||
.literalTextLine("Literal text line", true)
|
||||
.boldTextLine("Bold text line", true)
|
||||
.italicTextLine("Italic text line", true)
|
||||
.boldText("bold").italicText("italic").text("regular").newLine(true)
|
||||
.unorderedList(Arrays.asList("Entry1", "Entry2", "Entry 2"))
|
||||
.anchor("anchor", "text").newLine()
|
||||
.anchor(" Simple anchor").newLine()
|
||||
.anchor(" \u0240 µ&|ù This .:/-_# ").newLine()
|
||||
.crossReferenceRaw("./document.txt", "anchor", "text").newLine(true)
|
||||
.crossReferenceRaw(" \u0240 µ&|ù This .:/-_ ").newLine(true)
|
||||
.crossReference("./document.txt", "anchor", "text").newLine(true)
|
||||
.crossReference(" \u0240 µ&|ù This .:/-_ ").newLine(true);
|
||||
|
||||
Path outputFile = Paths.get("build/test/confluenceMarkup/test");
|
||||
|
||||
builder.writeToFileWithoutExtension(builder.addFileExtension(outputFile), StandardCharsets.UTF_8);
|
||||
builder.writeToFile(outputFile, StandardCharsets.UTF_8);
|
||||
|
||||
Path expectedFile = Paths.get(MarkupDocBuilderTest.class.getResource("/expected/confluenceMarkup/test.txt").toURI());
|
||||
DiffUtils.assertThatFileIsEqual(expectedFile, builder.addFileExtension(outputFile), "testConfluenceMarkup.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfluenceMarkupWithAnchorPrefix() {
|
||||
MarkupDocBuilder builderWithConfig = MarkupDocBuilders.documentBuilder(MarkupLanguage.CONFLUENCE_MARKUP).withAnchorPrefix(" mdb test- ");
|
||||
String prefixMarkup = builderWithConfig.anchor("anchor", "text")
|
||||
.crossReference("anchor", "text")
|
||||
.toString();
|
||||
|
||||
assertEquals("{anchor:mdb_test-anchor}[text|#mdb_test-anchor]", prefixMarkup);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReplaceNewLinesWithSystemNewLine() {
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN);
|
||||
builder.paragraph("Long text \n bla bla \r bla \r\n bla");
|
||||
Assert.assertEquals("Long text " + newLine + " bla bla " + newLine + " bla " + newLine + " bla" + newLine + newLine, builder.toString());
|
||||
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN);
|
||||
builder.text("Long text \n bla bla \r bla \r\n bla");
|
||||
Assert.assertEquals("Long text " + newLine + " bla bla " + newLine + " bla " + newLine + " bla", builder.toString());
|
||||
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN);
|
||||
builder.textLine("Long text \n bla bla \r bla \r\n bla");
|
||||
Assert.assertEquals("Long text " + newLine + " bla bla " + newLine + " bla " + newLine + " bla" + newLine, builder.toString());
|
||||
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN);
|
||||
builder.italicText("Long text \n bla bla \r bla \r\n bla");
|
||||
Assert.assertEquals("*Long text " + newLine + " bla bla " + newLine + " bla " + newLine + " bla*", builder.toString());
|
||||
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN);
|
||||
builder.italicTextLine("Long text \n bla bla \r bla \r\n bla");
|
||||
Assert.assertEquals("*Long text " + newLine + " bla bla " + newLine + " bla " + newLine + " bla*" + newLine, builder.toString());
|
||||
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN);
|
||||
builder.boldText("Long text \n bla bla \r bla \r\n bla");
|
||||
Assert.assertEquals("**Long text " + newLine + " bla bla " + newLine + " bla " + newLine + " bla**", builder.toString());
|
||||
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN);
|
||||
builder.boldTextLine("Long text \n bla bla \r bla \r\n bla");
|
||||
Assert.assertEquals("**Long text " + newLine + " bla bla " + newLine + " bla " + newLine + " bla**" + newLine, builder.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReplaceTitleNewLinesWithWhiteSpace() {
|
||||
String whitespace = " ";
|
||||
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC);
|
||||
builder.documentTitle("Long title \n bla bla \r bla \r\n bla");
|
||||
Assert.assertEquals("= Long title " + whitespace + " bla bla " + whitespace + " bla " + whitespace + " bla" + newLine + newLine, builder.toString());
|
||||
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC);
|
||||
builder.sectionTitleLevel1("Long title \n bla bla \r bla \r\n bla");
|
||||
Assert.assertEquals(newLine + "== Long title " + whitespace + " bla bla " + whitespace + " bla " + whitespace + " bla" + newLine, builder.toString());
|
||||
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC);
|
||||
builder.sectionTitleLevel2("Long title \n bla bla \r bla \r\n bla");
|
||||
Assert.assertEquals(newLine + "=== Long title " + whitespace + " bla bla " + whitespace + " bla " + whitespace + " bla" + newLine, builder.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldUseProvidedLineSeparator() {
|
||||
String lineSeparator = LineSeparator.UNIX.toString();
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN, LineSeparator.UNIX);
|
||||
builder.paragraph("Long text \n bla bla \r bla \r\n bla");
|
||||
Assert.assertEquals("Long text " + lineSeparator + " bla bla " + lineSeparator + " bla " + lineSeparator + " bla" + lineSeparator + lineSeparator, builder.toString());
|
||||
}
|
||||
|
||||
private void assertImportMarkup(String expected, String text, MarkupLanguage markupLanguage, int levelOffset) {
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(markupLanguage, LineSeparator.UNIX);
|
||||
|
||||
builder.importMarkup(new StringReader(text), markupLanguage, levelOffset);
|
||||
|
||||
Assert.assertEquals(expected, builder.toString());
|
||||
}
|
||||
|
||||
private void assertImportMarkupException(String expected, String text, MarkupLanguage markupLanguage, int levelOffset) {
|
||||
try {
|
||||
assertImportMarkup(expected, text, markupLanguage, levelOffset);
|
||||
fail("IllegalArgumentException expected");
|
||||
} catch (IllegalArgumentException e) {
|
||||
Assert.assertEquals(expected, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImportMarkupAsciiDoc() {
|
||||
assertImportMarkup("", "", MarkupLanguage.ASCIIDOC, 0);
|
||||
assertImportMarkup("", "", MarkupLanguage.ASCIIDOC, 4);
|
||||
assertImportMarkupException("Specified levelOffset (6) > max levelOffset (5)", "", MarkupLanguage.ASCIIDOC, 6);
|
||||
assertImportMarkup("", "", MarkupLanguage.ASCIIDOC, -4);
|
||||
assertImportMarkupException("Specified levelOffset (-6) < min levelOffset (-5)", "", MarkupLanguage.ASCIIDOC, -6);
|
||||
|
||||
assertImportMarkup("\n= title\nline 1\nline 2\n\n", "= title\r\nline 1\r\nline 2", MarkupLanguage.ASCIIDOC, 0);
|
||||
|
||||
assertImportMarkup("\nline 1\nline 2\n\n", "line 1\nline 2", MarkupLanguage.ASCIIDOC, 0);
|
||||
assertImportMarkup("\nline 1\nline 2\n\n", "line 1\nline 2", MarkupLanguage.ASCIIDOC, 4);
|
||||
|
||||
assertImportMarkup("\n= title\nline 1\nline 2\n= title 2\nline 3\n\n", "= title\nline 1\nline 2\n= title 2\nline 3", MarkupLanguage.ASCIIDOC, 0);
|
||||
assertImportMarkup("\n===== title\nline 1\nline 2\n\n", "= title\nline 1\nline 2", MarkupLanguage.ASCIIDOC, 4);
|
||||
assertImportMarkup("\n= title\nline 1\nline 2\n\n", "===== title\nline 1\nline 2", MarkupLanguage.ASCIIDOC, -4);
|
||||
|
||||
assertImportMarkupException("Specified levelOffset (5) set title 'title' level (1) > max title level (5)", "== title\nline 1\nline 2", MarkupLanguage.ASCIIDOC, 5);
|
||||
assertImportMarkupException("Specified levelOffset (-1) set title 'title' level (0) < 0", "= title\nline 1\nline 2", MarkupLanguage.ASCIIDOC, -1);
|
||||
assertImportMarkupException("Specified levelOffset (-3) set title 'title' level (1) < 0", "== title\nline 1\nline 2", MarkupLanguage.ASCIIDOC, -3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImportMarkupMarkdown() {
|
||||
assertImportMarkup("", "", MarkupLanguage.MARKDOWN, 0);
|
||||
assertImportMarkup("", "", MarkupLanguage.MARKDOWN, 4);
|
||||
assertImportMarkup("", "", MarkupLanguage.MARKDOWN, -4);
|
||||
assertImportMarkupException("Specified levelOffset (6) > max levelOffset (5)", "", MarkupLanguage.MARKDOWN, 6);
|
||||
assertImportMarkupException("Specified levelOffset (-6) < min levelOffset (-5)", "", MarkupLanguage.MARKDOWN, -6);
|
||||
|
||||
assertImportMarkup("\n# title\nline 1\nline 2\n\n", "# title\r\nline 1\r\nline 2", MarkupLanguage.MARKDOWN, 0);
|
||||
|
||||
assertImportMarkup("\nline 1\nline 2\n\n", "line 1\nline 2", MarkupLanguage.MARKDOWN, 0);
|
||||
assertImportMarkup("\nline 1\nline 2\n\n", "line 1\nline 2", MarkupLanguage.MARKDOWN, 4);
|
||||
|
||||
assertImportMarkup("\n# title\nline 1\nline 2\n# title 2\nline 3\n\n", "# title\nline 1\nline 2\n# title 2\nline 3", MarkupLanguage.MARKDOWN, 0);
|
||||
assertImportMarkup("\n##### title\nline 1\nline 2\n\n", "# title\nline 1\nline 2", MarkupLanguage.MARKDOWN, 4);
|
||||
assertImportMarkup("\n# title\nline 1\nline 2\n\n", "##### title\nline 1\nline 2", MarkupLanguage.MARKDOWN, -4);
|
||||
|
||||
assertImportMarkupException("Specified levelOffset (5) set title 'title' level (1) > max title level (5)", "## title\nline 1\nline 2", MarkupLanguage.MARKDOWN, 5);
|
||||
assertImportMarkupException("Specified levelOffset (-1) set title 'title' level (0) < 0", "# title\nline 1\nline 2", MarkupLanguage.MARKDOWN, -1);
|
||||
assertImportMarkupException("Specified levelOffset (-3) set title 'title' level (1) < 0", "## title\nline 1\nline 2", MarkupLanguage.MARKDOWN, -3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImportMarkupConfluenceMarkup() {
|
||||
assertImportMarkup("", "", MarkupLanguage.CONFLUENCE_MARKUP, 0);
|
||||
assertImportMarkup("", "", MarkupLanguage.CONFLUENCE_MARKUP, 4);
|
||||
assertImportMarkup("", "", MarkupLanguage.CONFLUENCE_MARKUP, -4);
|
||||
assertImportMarkupException("Specified levelOffset (6) > max levelOffset (5)", "", MarkupLanguage.CONFLUENCE_MARKUP, 6);
|
||||
assertImportMarkupException("Specified levelOffset (-6) < min levelOffset (-5)", "", MarkupLanguage.CONFLUENCE_MARKUP, -6);
|
||||
|
||||
assertImportMarkup("\nh1. title\nline 1\nline 2\n\n", "h1. title\r\nline 1\r\nline 2", MarkupLanguage.CONFLUENCE_MARKUP, 0);
|
||||
|
||||
assertImportMarkup("\nline 1\nline 2\n\n", "line 1\nline 2", MarkupLanguage.CONFLUENCE_MARKUP, 0);
|
||||
assertImportMarkup("\nline 1\nline 2\n\n", "line 1\nline 2", MarkupLanguage.CONFLUENCE_MARKUP, 4);
|
||||
|
||||
assertImportMarkup("\nh1. title\nline 1\nline 2\nh1. title 2\nline 3\n\n", "h1. title\nline 1\nline 2\nh1. title 2\nline 3", MarkupLanguage.CONFLUENCE_MARKUP, 0);
|
||||
assertImportMarkup("\nh5. title\nline 1\nline 2\n\n", "h1. title\nline 1\nline 2", MarkupLanguage.CONFLUENCE_MARKUP, 4);
|
||||
assertImportMarkup("\nh1. title\nline 1\nline 2\n\n", "h5. title\nline 1\nline 2", MarkupLanguage.CONFLUENCE_MARKUP, -4);
|
||||
|
||||
assertImportMarkupException("Specified levelOffset (5) set title 'title' level (1) > max title level (5)", "h2. title\nline 1\nline 2", MarkupLanguage.CONFLUENCE_MARKUP, 5);
|
||||
assertImportMarkupException("Specified levelOffset (-1) set title 'title' level (0) < 0", "h1. title\nline 1\nline 2", MarkupLanguage.CONFLUENCE_MARKUP, -1);
|
||||
assertImportMarkupException("Specified levelOffset (-3) set title 'title' level (1) < 0", "h2. title\nline 1\nline 2", MarkupLanguage.CONFLUENCE_MARKUP, -3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void importMarkupConversion() {
|
||||
// ASCIIDOC -> ASCIIDOC
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC, LineSeparator.UNIX);
|
||||
builder.importMarkup(new StringReader("= Title"), MarkupLanguage.ASCIIDOC);
|
||||
Assert.assertEquals("\n= Title\n\n", builder.toString());
|
||||
|
||||
// ASCIIDOC -> MARKDOWN
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN, LineSeparator.UNIX);
|
||||
builder.importMarkup(new StringReader("= Title"), MarkupLanguage.ASCIIDOC);
|
||||
// Assert.assertEquals("\n# Title\n\n", builder.toString()); // Unsupported
|
||||
Assert.assertEquals("\n= Title\n\n", builder.toString());
|
||||
|
||||
// ASCIIDOC -> CONFLUENCE_MARKUP
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.CONFLUENCE_MARKUP, LineSeparator.UNIX);
|
||||
builder.importMarkup(new StringReader("= Title"), MarkupLanguage.ASCIIDOC);
|
||||
// Assert.assertEquals("\nh1. Title\n\n", builder.toString()); // Unsupported
|
||||
Assert.assertEquals("\n= Title\n\n", builder.toString());
|
||||
|
||||
// MARKDOWN -> ASCIIDOC
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC, LineSeparator.UNIX);
|
||||
builder.importMarkup(new StringReader("# Title"), MarkupLanguage.MARKDOWN);
|
||||
Assert.assertEquals("\n= Title\n\n", builder.toString());
|
||||
|
||||
// MARKDOWN -> MARKDOWN
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN, LineSeparator.UNIX);
|
||||
builder.importMarkup(new StringReader("# Title"), MarkupLanguage.MARKDOWN);
|
||||
Assert.assertEquals("\n# Title\n\n", builder.toString());
|
||||
|
||||
// MARKDOWN -> CONFLUENCE_MARKUP
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.CONFLUENCE_MARKUP, LineSeparator.UNIX);
|
||||
builder.importMarkup(new StringReader("# Title"), MarkupLanguage.MARKDOWN);
|
||||
// Assert.assertEquals("\nh1. Title\n\n", builder.toString()); // Unsupported
|
||||
Assert.assertEquals("\n# Title\n\n", builder.toString());
|
||||
|
||||
// CONFLUENCE_MARKUP -> ASCIIDOC
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC, LineSeparator.UNIX);
|
||||
builder.importMarkup(new StringReader("h1. Title"), MarkupLanguage.CONFLUENCE_MARKUP);
|
||||
// Assert.assertEquals("\n= Title\n\n", builder.toString()); // Unsupported
|
||||
Assert.assertEquals("\nh1. Title\n\n", builder.toString());
|
||||
|
||||
// CONFLUENCE_MARKUP -> MARKDOWN
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN, LineSeparator.UNIX);
|
||||
builder.importMarkup(new StringReader("h1. Title"), MarkupLanguage.CONFLUENCE_MARKUP);
|
||||
// Assert.assertEquals("\n# Title\n\n", builder.toString()); // Unsupported
|
||||
Assert.assertEquals("\nh1. Title\n\n", builder.toString());
|
||||
|
||||
// CONFLUENCE_MARKUP -> CONFLUENCE_MARKUP
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.CONFLUENCE_MARKUP, LineSeparator.UNIX);
|
||||
builder.importMarkup(new StringReader("h1. Title"), MarkupLanguage.CONFLUENCE_MARKUP);
|
||||
Assert.assertEquals("\nh1. Title\n\n", builder.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tableFormatAsciiDoc() throws URISyntaxException, IOException {
|
||||
Path outputFile = Paths.get("build/test/asciidoc/tableFormat.adoc");
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC);
|
||||
|
||||
List<MarkupTableColumn> cols = Arrays.asList(
|
||||
new MarkupTableColumn().withHeader("Header1\nfirst one"),
|
||||
new MarkupTableColumn().withWidthRatio(2),
|
||||
new MarkupTableColumn().withHeader("Header3").withWidthRatio(1).withHeaderColumn(true));
|
||||
List<List<String>> cells = new ArrayList<>();
|
||||
|
||||
cells.add(Arrays.asList("\nRow 2 \\| Column \r\n1\r", "Row 2 || Column 2", "Row 2 | | Column 3"));
|
||||
|
||||
|
||||
builder = builder.tableWithColumnSpecs(cols, cells);
|
||||
builder.writeToFileWithoutExtension(outputFile, StandardCharsets.UTF_8);
|
||||
|
||||
DiffUtils.assertThatFileIsEqual(Paths.get(MarkupDocBuilderTest.class.getResource("/expected/asciidoc/tableFormat.adoc").toURI()), outputFile, "tableFormatAsciiDoc.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tableFormatMarkdown() throws URISyntaxException, IOException {
|
||||
Path outputFile = Paths.get("build/test/markdown/tableFormat.md");
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN);
|
||||
|
||||
List<MarkupTableColumn> cols = Arrays.asList(
|
||||
new MarkupTableColumn().withHeader("Header1\nfirst one"),
|
||||
new MarkupTableColumn().withWidthRatio(2),
|
||||
new MarkupTableColumn().withHeader("Header3").withWidthRatio(1).withHeaderColumn(true));
|
||||
List<List<String>> cells = new ArrayList<>();
|
||||
|
||||
cells.add(Arrays.asList("\nRow 2 \\| Column \r\n1\r", "Row 2 || Column 2", "Row 2 | | Column 3"));
|
||||
|
||||
builder = builder.tableWithColumnSpecs(cols, cells);
|
||||
builder.writeToFileWithoutExtension(outputFile, StandardCharsets.UTF_8);
|
||||
|
||||
DiffUtils.assertThatFileIsEqual(Paths.get(MarkupDocBuilderTest.class.getResource("/expected/markdown/tableFormat.md").toURI()), outputFile, "tableFormatMarkdown.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tableFormatConfluenceMarkup() throws URISyntaxException, IOException {
|
||||
Path outputFile = Paths.get("build/test/confluenceMarkup/tableFormat.txt");
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.CONFLUENCE_MARKUP);
|
||||
|
||||
List<MarkupTableColumn> cols = Arrays.asList(
|
||||
new MarkupTableColumn().withHeader("Header1\nfirst one"),
|
||||
new MarkupTableColumn().withWidthRatio(2),
|
||||
new MarkupTableColumn().withHeader("Header3").withWidthRatio(1).withHeaderColumn(true));
|
||||
List<List<String>> cells = new ArrayList<>();
|
||||
|
||||
cells.add(Arrays.asList("Row 1 [Title|Page#Anchor] | Column 1", "Row 1 [Title1|Page#Anchor][Title2|Page#Anchor] [Title3|Page#Anchor] | Column [Title|Page#Anchor] 2", "Row 1 [Ti\\|t\\]\\[le|Page#Anchor] | Column 3"));
|
||||
cells.add(Arrays.asList("[Title|Page#Anchor]Row 1 | Column 1[Title|Page#Anchor]", "|[Title1|Page#Anchor]Row1 Column2|[Title1|Page#Anchor]", "|Row 1 Column 3|"));
|
||||
cells.add(Arrays.asList("\nRow 2 \\| Column \r\n1\r", "Row 2 || Column 2", "Row 2 | | Column 3"));
|
||||
|
||||
builder = builder.tableWithColumnSpecs(cols, cells);
|
||||
builder.writeToFileWithoutExtension(outputFile, StandardCharsets.UTF_8);
|
||||
|
||||
DiffUtils.assertThatFileIsEqual(Paths.get(MarkupDocBuilderTest.class.getResource("/expected/confluenceMarkup/tableFormat.txt").toURI()), outputFile, "tableFormatConfluenceMarkup.html");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.swagger2markup.markup.builder.assertions;
|
||||
|
||||
import io.github.robwin.diff.DiffAssertions;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class DiffUtils {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(DiffUtils.class);
|
||||
|
||||
public static void assertThatAllFilesAreEqual(Path expectedDirectory, Path actualDirectory, String reportName) {
|
||||
Path reportPath = Paths.get("build/diff-report/", reportName);
|
||||
try {
|
||||
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(expectedDirectory)) {
|
||||
for (Path expectedFile : directoryStream) {
|
||||
Path actualFile = actualDirectory.resolve(expectedFile.getFileName());
|
||||
LOGGER.info("Diffing file {} with {}", actualFile, expectedFile);
|
||||
DiffAssertions.assertThat(actualFile).isEqualTo(expectedFile, reportPath);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to assert that all files are equal", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void assertThatFileIsEqual(Path expectedFile, Path actualFile, String reportName) {
|
||||
Path reportPath = Paths.get("build/diff-report/", reportName);
|
||||
LOGGER.info("Diffing file {} with {}", actualFile, expectedFile);
|
||||
DiffAssertions.assertThat(actualFile).isEqualTo(expectedFile, reportPath);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package io.github.swagger2markup.markup.builder.internal;
|
||||
|
||||
import io.github.swagger2markup.markup.builder.LineSeparator;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilders;
|
||||
import io.github.swagger2markup.markup.builder.MarkupLanguage;
|
||||
import io.github.swagger2markup.markup.builder.internal.asciidoc.AsciiDoc;
|
||||
import io.github.swagger2markup.markup.builder.internal.markdown.Markdown;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class AbstractMarkupDocBuilderTest {
|
||||
|
||||
AbstractMarkupDocBuilder builder;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
builder = mock(AbstractMarkupDocBuilder.class, Mockito.CALLS_REAL_METHODS);
|
||||
builder.newLine = "\n";
|
||||
builder.documentBuilder = new StringBuilder();
|
||||
}
|
||||
|
||||
private String normalize(Markup markup, String anchor) {
|
||||
return builder.normalizeAnchor(markup, anchor);
|
||||
}
|
||||
|
||||
private void assertNormalization(Markup markup, String result, String anchor) {
|
||||
assertEquals(result, normalize(markup, anchor));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalizeAnchorAsciiDoc() throws Exception {
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, "", "");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, "anchor", "anchor");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, "anchor", "aNcHoR");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, "anchor", "_ anchor _");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, "anchor", "- anchor -");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, "a_n-c_h_o-r", "_-a _ - n-_-_-c_-_-_h___o---r_-");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, "classic-simple_anchor", "classic-simple_anchor");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, "an_chor", " an chor ");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, "anchor", "# anchor &");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, DigestUtils.md5Hex("\u0240"), "\u0240");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, normalize(AsciiDoc.SPACE_ESCAPE, "\u0240"), " \u0240 ");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, DigestUtils.md5Hex("µ_u_\u0240this"), " µ&|ù \u0240This .:/-_# ");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, "this_is_a_really_funky_string", "Tĥïŝ ĩš â really fůňķŷ Šťŕĭńġ");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, "", " @#&(){}[]!$*%+=/:.;,?\\<>| ");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, "sub_action_html_query_value", " /sub/action.html/?query=value ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalizeAnchorMarkdown() throws Exception {
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, "", "");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, "anchor", "anchor");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, "anchor", "aNcHoR");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, "anchor", "_ anchor _");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, "anchor", "- anchor -");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, "a-n-c_h_o-r", "_-a _ - n-_-_-c_-_-_h___o---r_-");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, "classic-simple_anchor", "classic-simple_anchor");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, "an-chor", " an chor ");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, "anchor", "# anchor &");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, DigestUtils.md5Hex("\u0240"), "\u0240");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, normalize(Markdown.SPACE_ESCAPE, "\u0240"), " \u0240 ");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, DigestUtils.md5Hex("µ-u-\u0240this"), " µ&|ù \u0240This .:/-_# ");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, "this-is-a-really-funky-string", "Tĥïŝ ĩš â really fůňķŷ Šťŕĭńġ");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, "", " @#&(){}[]!$*%+=/:.;,?\\<>| ");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, "sub-action-html-query-value", " /sub/action.html/?query=value ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopy() {
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC, LineSeparator.UNIX).withAnchorPrefix("anchor-");
|
||||
MarkupDocBuilder copy = builder.copy(false);
|
||||
|
||||
Assert.assertTrue(copy instanceof AbstractMarkupDocBuilder);
|
||||
AbstractMarkupDocBuilder internalCopy = (AbstractMarkupDocBuilder) copy;
|
||||
Assert.assertEquals(LineSeparator.UNIX.toString(), internalCopy.newLine);
|
||||
Assert.assertEquals("anchor-", internalCopy.anchorPrefix);
|
||||
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC, LineSeparator.WINDOWS);
|
||||
copy = builder.copy(false);
|
||||
|
||||
Assert.assertTrue(copy instanceof AbstractMarkupDocBuilder);
|
||||
internalCopy = (AbstractMarkupDocBuilder) copy;
|
||||
Assert.assertEquals(LineSeparator.WINDOWS.toString(), internalCopy.newLine);
|
||||
Assert.assertNull(internalCopy.anchorPrefix);
|
||||
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC, LineSeparator.UNIX);
|
||||
builder.text("This is text");
|
||||
copy = builder.copy(true);
|
||||
|
||||
Assert.assertTrue(copy instanceof AbstractMarkupDocBuilder);
|
||||
internalCopy = (AbstractMarkupDocBuilder) copy;
|
||||
Assert.assertEquals(LineSeparator.UNIX.toString(), internalCopy.newLine);
|
||||
Assert.assertNull(internalCopy.anchorPrefix);
|
||||
Assert.assertEquals("This is text", internalCopy.documentBuilder.toString());
|
||||
|
||||
}
|
||||
}
|
||||
11
src/test/resources/expected/asciidoc/tableFormat.adoc
Normal file
11
src/test/resources/expected/asciidoc/tableFormat.adoc
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
[options="header", cols="0,2,1h"]
|
||||
|===
|
||||
|Header1
|
||||
first one||Header3
|
||||
|Row 2 \\| Column
|
||||
1|Row 2 \|\| Column 2|Row 2 \| \| Column 3
|
||||
|===
|
||||
|
||||
|
||||
|
||||
134
src/test/resources/expected/asciidoc/test.adoc
Normal file
134
src/test/resources/expected/asciidoc/test.adoc
Normal file
@@ -0,0 +1,134 @@
|
||||
= Test title
|
||||
|
||||
|
||||
== Section Level 1a
|
||||
|
||||
[[_level-1a]]
|
||||
== Section with anchor Level 1a
|
||||
|
||||
[[_section_with_anchor_level_1a]]
|
||||
== Section with anchor Level 1a
|
||||
|
||||
=== Section Level 2a
|
||||
|
||||
[[_level-2a]]
|
||||
=== Section with anchor Level 2a
|
||||
|
||||
[[_section_with_anchor_level_2a]]
|
||||
=== Section with anchor Level 2a
|
||||
|
||||
==== Section Level 3a
|
||||
|
||||
[[_level-3a]]
|
||||
==== Section with anchor Level 3a
|
||||
|
||||
[[_section_with_anchor_level_3a]]
|
||||
==== Section with anchor Level 3a
|
||||
|
||||
===== Section Level 4a
|
||||
|
||||
[[_level-4a]]
|
||||
===== Section with anchor Level 4a
|
||||
|
||||
[[_section_with_anchor_level_4a]]
|
||||
===== Section with anchor Level 4a
|
||||
|
||||
====== Section Level 5a
|
||||
|
||||
[[_level-5a]]
|
||||
====== Section with anchor Level 5a
|
||||
|
||||
[[_section_with_anchor_level_5a]]
|
||||
====== Section with anchor Level 5a
|
||||
Paragraph with long text bla bla bla bla bla
|
||||
|
||||
Line1
|
||||
Line2
|
||||
|
||||
[%hardbreaks]
|
||||
Line1
|
||||
Line2
|
||||
|
||||
----
|
||||
Source code listing
|
||||
----
|
||||
|
||||
[source,java]
|
||||
----
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN)
|
||||
----
|
||||
|
||||
====
|
||||
Example
|
||||
====
|
||||
|
||||
.Example
|
||||
====
|
||||
Example
|
||||
====
|
||||
|
||||
[IMPORTANT]
|
||||
====
|
||||
Example
|
||||
====
|
||||
|
||||
[CAUTION]
|
||||
----
|
||||
Listing
|
||||
----
|
||||
|
||||
[NOTE]
|
||||
....
|
||||
Literal
|
||||
....
|
||||
|
||||
[TIP]
|
||||
****
|
||||
Sidebar
|
||||
****
|
||||
|
||||
[WARNING]
|
||||
++++
|
||||
Passthrough
|
||||
++++
|
||||
|
||||
|
||||
<<<
|
||||
|
||||
[options="", cols=""]
|
||||
|===
|
||||
|Row 1 \| Column 1|Row 1 \| Column 2|Row 1 \| Column 3
|
||||
|Row 2 \| Column 1|Row 2 \| Column 2|Row 2 \| Column 3
|
||||
|===
|
||||
|
||||
|
||||
[options="header", cols="0,2,1h"]
|
||||
|===
|
||||
|Header1||Header3
|
||||
|Row 1 \| Column 1|Row 1 \| Column 2|Row 1 \| Column 3
|
||||
|Row 2 \| Column 1|Row 2 \| Column 2|Row 2 \| Column 3
|
||||
|===
|
||||
|
||||
|
||||
== Section Level 1b
|
||||
|
||||
=== Section Level 2b
|
||||
text line +
|
||||
`Literal text line` +
|
||||
**Bold text line** +
|
||||
__Italic text line__ +
|
||||
**bold**__italic__regular +
|
||||
|
||||
* Entry1
|
||||
* Entry2
|
||||
* Entry 2
|
||||
|
||||
[[_anchor,text]]
|
||||
[[_simple_anchor]]
|
||||
[[_8be261a9de7ce958fe46548a62609aeb]]
|
||||
<<./document.adoc#anchor,text>> +
|
||||
<< ɀ µ&|ù This .:/-_ >> +
|
||||
<<document.adoc#_anchor,text>> +
|
||||
<<_8be261a9de7ce958fe46548a62609aeb>> +
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
||Header1\\ first one|| ||Header3||
|
||||
|Row 1 [Title|Page#Anchor] \| Column 1|Row 1 [Title1|Page#Anchor][Title2|Page#Anchor] [Title3|Page#Anchor] \| Column [Title|Page#Anchor] 2||Row 1 [Ti\|t\]\[le|Page#Anchor] \| Column 3|
|
||||
|[Title|Page#Anchor]Row 1 \| Column 1[Title|Page#Anchor]|\|[Title1|Page#Anchor]Row1 Column2\|[Title1|Page#Anchor]||\|Row 1 Column 3\||
|
||||
|Row 2 \\| Column \\ 1|Row 2 \|\| Column 2||Row 2 \| \| Column 3|
|
||||
|
||||
|
||||
|
||||
112
src/test/resources/expected/confluenceMarkup/test.txt
Normal file
112
src/test/resources/expected/confluenceMarkup/test.txt
Normal file
@@ -0,0 +1,112 @@
|
||||
h1. Test title
|
||||
|
||||
|
||||
h2. Section Level 1a
|
||||
|
||||
h2. Section with anchor Level 1a {anchor:level-1a}
|
||||
|
||||
h2. Section with anchor Level 1a {anchor:section_with_anchor_level_1a}
|
||||
|
||||
h3. Section Level 2a
|
||||
|
||||
h3. Section with anchor Level 2a {anchor:level-2a}
|
||||
|
||||
h3. Section with anchor Level 2a {anchor:section_with_anchor_level_2a}
|
||||
|
||||
h4. Section Level 3a
|
||||
|
||||
h4. Section with anchor Level 3a {anchor:level-3a}
|
||||
|
||||
h4. Section with anchor Level 3a {anchor:section_with_anchor_level_3a}
|
||||
|
||||
h5. Section Level 4a
|
||||
|
||||
h5. Section with anchor Level 4a {anchor:level-4a}
|
||||
|
||||
h5. Section with anchor Level 4a {anchor:section_with_anchor_level_4a}
|
||||
|
||||
h6. Section Level 5a
|
||||
|
||||
h6. Section with anchor Level 5a {anchor:level-5a}
|
||||
|
||||
h6. Section with anchor Level 5a {anchor:section_with_anchor_level_5a}
|
||||
Paragraph with long text bla bla bla bla bla
|
||||
|
||||
Line1
|
||||
Line2
|
||||
|
||||
Line1\\
|
||||
Line2
|
||||
|
||||
{code}
|
||||
Source code listing
|
||||
{code}
|
||||
|
||||
{code:language=java}
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.CONFLUENCE_MARKUP)
|
||||
{code}
|
||||
|
||||
{panel}
|
||||
Example
|
||||
{panel}
|
||||
|
||||
{panel:title=Example}
|
||||
Example
|
||||
{panel}
|
||||
|
||||
{alert}
|
||||
Example
|
||||
{alert}
|
||||
|
||||
{code:title=Caution}
|
||||
Listing
|
||||
{code}
|
||||
|
||||
Note :
|
||||
{noformat}
|
||||
Literal
|
||||
{noformat}
|
||||
|
||||
{tip}
|
||||
Sidebar
|
||||
{tip}
|
||||
|
||||
Warning :
|
||||
{html}
|
||||
Passthrough
|
||||
{html}
|
||||
|
||||
|
||||
<div style='page-break-before:always;'></div>
|
||||
|
||||
|Row 1 \| Column 1|Row 1 \| Column 2|Row 1 \| Column 3|
|
||||
|Row 2 \| Column 1|Row 2 \| Column 2|Row 2 \| Column 3|
|
||||
|
||||
|
||||
||Header1|| ||Header3||
|
||||
|Row 1 \| Column 1|Row 1 \| Column 2||Row 1 \| Column 3|
|
||||
|Row 2 \| Column 1|Row 2 \| Column 2||Row 2 \| Column 3|
|
||||
|
||||
|
||||
h2. Section Level 1b
|
||||
|
||||
h3. Section Level 2b
|
||||
text line\\
|
||||
{noformat}Literal text line{noformat}\\
|
||||
*Bold text line*\\
|
||||
_Italic text line_\\
|
||||
*bold*_italic_regular\\
|
||||
|
||||
* Entry1
|
||||
* Entry2
|
||||
* Entry 2
|
||||
|
||||
{anchor:anchor}
|
||||
{anchor:simple_anchor}
|
||||
{anchor:8be261a9de7ce958fe46548a62609aeb}
|
||||
[text|./document.txt#anchor]\\
|
||||
[# ɀ µ&|ù This .:/-_ ]\\
|
||||
[text|./document.txt#anchor]\\
|
||||
[#8be261a9de7ce958fe46548a62609aeb]\\
|
||||
|
||||
|
||||
7
src/test/resources/expected/markdown/tableFormat.md
Normal file
7
src/test/resources/expected/markdown/tableFormat.md
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
|Header1<br>first one||Header3|
|
||||
|---|---|---|
|
||||
|Row 2 \\| Column <br>1|Row 2 \|\| Column 2|Row 2 \| \| Column 3|
|
||||
|
||||
|
||||
|
||||
113
src/test/resources/expected/markdown/test.md
Normal file
113
src/test/resources/expected/markdown/test.md
Normal file
@@ -0,0 +1,113 @@
|
||||
# Test title
|
||||
|
||||
|
||||
## Section Level 1a
|
||||
|
||||
<a name="level-1a"></a>
|
||||
## Section with anchor Level 1a
|
||||
|
||||
<a name="section-with-anchor-level-1a"></a>
|
||||
## Section with anchor Level 1a
|
||||
|
||||
### Section Level 2a
|
||||
|
||||
<a name="level-2a"></a>
|
||||
### Section with anchor Level 2a
|
||||
|
||||
<a name="section-with-anchor-level-2a"></a>
|
||||
### Section with anchor Level 2a
|
||||
|
||||
#### Section Level 3a
|
||||
|
||||
<a name="level-3a"></a>
|
||||
#### Section with anchor Level 3a
|
||||
|
||||
<a name="section-with-anchor-level-3a"></a>
|
||||
#### Section with anchor Level 3a
|
||||
|
||||
##### Section Level 4a
|
||||
|
||||
<a name="level-4a"></a>
|
||||
##### Section with anchor Level 4a
|
||||
|
||||
<a name="section-with-anchor-level-4a"></a>
|
||||
##### Section with anchor Level 4a
|
||||
|
||||
###### Section Level 5a
|
||||
|
||||
<a name="level-5a"></a>
|
||||
###### Section with anchor Level 5a
|
||||
|
||||
<a name="section-with-anchor-level-5a"></a>
|
||||
###### Section with anchor Level 5a
|
||||
Paragraph with long text bla bla bla bla bla
|
||||
|
||||
Line1
|
||||
Line2
|
||||
|
||||
Line1
|
||||
Line2
|
||||
|
||||
```
|
||||
Source code listing
|
||||
```
|
||||
|
||||
```java
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN)
|
||||
```
|
||||
|
||||
Example
|
||||
|
||||
Example :
|
||||
Example
|
||||
|
||||
Important :
|
||||
Example
|
||||
|
||||
Caution :
|
||||
```
|
||||
Listing
|
||||
```
|
||||
|
||||
Note :
|
||||
```
|
||||
Literal
|
||||
```
|
||||
|
||||
Tip :
|
||||
Sidebar
|
||||
|
||||
Warning :
|
||||
Passthrough
|
||||
|
||||
|
||||
***
|
||||
|
||||
|Header1||Header3|
|
||||
|---|---|---|
|
||||
|Row 1 \| Column 1|Row 1 \| Column 2|Row 1 \| Column 3|
|
||||
|Row 2 \| Column 1|Row 2 \| Column 2|Row 2 \| Column 3|
|
||||
|
||||
|
||||
## Section Level 1b
|
||||
|
||||
### Section Level 2b
|
||||
text line
|
||||
`Literal text line`
|
||||
**Bold text line**
|
||||
*Italic text line*
|
||||
**bold***italic*regular
|
||||
|
||||
* Entry1
|
||||
* Entry2
|
||||
* Entry 2
|
||||
|
||||
<a name="anchor"></a>
|
||||
<a name="simple-anchor"></a>
|
||||
<a name="313af8b99da5a524603837deb119d273"></a>
|
||||
[text](./document.md#anchor)
|
||||
[ɀ µ&|ù This .:/-_](# ɀ µ&|ù This .:/-_ )
|
||||
[text](./document.md#anchor)
|
||||
[313af8b99da5a524603837deb119d273](#313af8b99da5a524603837deb119d273)
|
||||
|
||||
|
||||
6
src/test/resources/expected/markdown/test2.md
Normal file
6
src/test/resources/expected/markdown/test2.md
Normal file
@@ -0,0 +1,6 @@
|
||||
```php
|
||||
$o = new Thing();
|
||||
```
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user