Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
609dcbc7d5 | ||
|
|
4e61063106 | ||
|
|
b7cad8a7c8 | ||
|
|
97b068150d | ||
|
|
c1327e6b90 | ||
|
|
68c101fced | ||
|
|
02ea0f4e54 | ||
|
|
3933836290 | ||
|
|
9471093dce | ||
|
|
15a96a7338 | ||
|
|
e6dc1b63d0 | ||
|
|
1dd8dd2d25 | ||
|
|
2657b03de0 | ||
|
|
5e8096b6e6 | ||
|
|
3b880a6a0d | ||
|
|
7a87b33776 | ||
|
|
e5a94cc9d2 | ||
|
|
a52661bb77 |
36
README.adoc
36
README.adoc
@@ -1,13 +1,13 @@
|
||||
= MarkupDocBuilder
|
||||
:author: Robert Winkler
|
||||
:version: 0.1.1
|
||||
:version: 0.1.4
|
||||
: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:http://img.shields.io/:version-{version}-blue.svg["Semantic Versioning", link="https://bintray.com/robwin/maven/markup-document-builder/0.1.1/view"] 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/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://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 and Markdown). 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.
|
||||
|
||||
@@ -33,7 +33,7 @@ The project is published in JCenter and Maven Central.
|
||||
<dependency>
|
||||
<groupId>io.github.robwin</groupId>
|
||||
<artifactId>markup-document-builder</artifactId>
|
||||
<version>0.1.1</version>
|
||||
<version>0.1.4</version>
|
||||
</dependency>
|
||||
----
|
||||
|
||||
@@ -45,7 +45,7 @@ repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
compile "io.github.robwin:markup-document-builder:0.1.1"
|
||||
compile "io.github.robwin:markup-document-builder:0.1.4"
|
||||
----
|
||||
|
||||
=== Using MarkupDocBuilder
|
||||
@@ -56,14 +56,14 @@ The MarkupDocBuilder allows to build an AsciiDoc or Markdown document via the Bu
|
||||
----
|
||||
public class MarkupDocBuilderTest {
|
||||
|
||||
List<String> tableCsvRows;
|
||||
List<String> tableRowsInPSV;
|
||||
|
||||
@Before
|
||||
public void setUp(){
|
||||
tableCsvRows = new ArrayList<>();
|
||||
tableCsvRows.add("Header 1,Header 2,Header2");
|
||||
tableCsvRows.add("Row 1 Column 1,Row 1 Column 2,Row 1 Column 3");
|
||||
tableCsvRows.add("Row 2 Column 1,Row 2 Column 2,Row 2 Column 3");
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ public class MarkupDocBuilderTest {
|
||||
.paragraph("Paragraph with long text bla bla bla bla bla")
|
||||
.listing("Source code listing")
|
||||
.source("MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC)", "java")
|
||||
.tableWithHeaderRow(tableCsvRows)
|
||||
.tableWithHeaderRow(tableRowsInPSV)
|
||||
.sectionTitleLevel1("Section Level 1b")
|
||||
.sectionTitleLevel2("Section Level 2b")
|
||||
.boldTextLine("Bold text line b")
|
||||
@@ -95,8 +95,8 @@ public class MarkupDocBuilderTest {
|
||||
.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(tableCsvRows)
|
||||
.source("MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN)", "java")
|
||||
.tableWithHeaderRow(tableRowsInPSV)
|
||||
.sectionTitleLevel1("Section Level 1b")
|
||||
.sectionTitleLevel2("Section Level 2b")
|
||||
.boldTextLine("Bold text line b")
|
||||
@@ -113,3 +113,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.
|
||||
|
||||
|
||||
@@ -4,4 +4,16 @@
|
||||
* Initial version with support for AsciiDoc and Markdown
|
||||
|
||||
=== Version 0.1.1
|
||||
* Signed jar files
|
||||
* 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
|
||||
14
build.gradle
14
build.gradle
@@ -6,14 +6,14 @@ buildscript {
|
||||
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 'io.spring.gradle:dependency-management-plugin:0.5.0.RELEASE'
|
||||
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'
|
||||
}
|
||||
}
|
||||
description = 'A Markup (Markdown, AsciiDoc) document builder'
|
||||
version = '0.1.1'
|
||||
version = '0.1.5'
|
||||
group = 'io.github.robwin'
|
||||
|
||||
apply plugin: 'java'
|
||||
@@ -39,16 +39,16 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'commons-io:commons-io'
|
||||
compile 'ch.qos.logback:logback-classic'
|
||||
compile 'org.slf4j:slf4j-api'
|
||||
testCompile 'junit:junit'
|
||||
testCompile 'ch.qos.logback:logback-classic'
|
||||
}
|
||||
|
||||
dependencyManagement {
|
||||
dependencies {
|
||||
"commons-io:commons-io" "2.4"
|
||||
"ch.qos.logback:logback-classic" "1.1.2"
|
||||
"junit:junit" "4.11"
|
||||
dependency "org.slf4j:slf4j-api:1.7.12"
|
||||
dependency "junit:junit:4.11"
|
||||
dependency "ch.qos.logback:logback-classic:1.1.2"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,15 @@ publishing {
|
||||
pom.withXml {
|
||||
def devs = ['RobWin': 'Robert Winkler']
|
||||
def root = asNode()
|
||||
|
||||
root.dependencies.'*'.findAll() {
|
||||
it.scope.text() == 'runtime' && project.configurations.compile.allDependencies.find { dep ->
|
||||
dep.name == it.artifactId.text()
|
||||
}
|
||||
}.each() {
|
||||
it.scope*.value = 'compile'
|
||||
}
|
||||
|
||||
root.appendNode('name', 'markup-document-builder')
|
||||
root.appendNode('packaging', 'jar')
|
||||
root.appendNode('url', 'https://github.com/RobWin/markup-document-builder')
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
*
|
||||
* 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.robwin.markup.builder;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@@ -39,6 +57,10 @@ public abstract class AbstractMarkupDocBuilder implements MarkupDocBuilder {
|
||||
documentBuilder.append(markup).append(title).append(newLine);
|
||||
}
|
||||
|
||||
protected void sectionTitleLevel4(Markup markup, String title){
|
||||
documentBuilder.append(markup).append(title).append(newLine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder textLine(String text){
|
||||
documentBuilder.append(text).append(newLine);
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
*
|
||||
* 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.robwin.markup.builder;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
*
|
||||
* 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.robwin.markup.builder;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -18,6 +36,8 @@ public interface MarkupDocBuilder {
|
||||
|
||||
MarkupDocBuilder sectionTitleLevel3(String title);
|
||||
|
||||
MarkupDocBuilder sectionTitleLevel4(String title);
|
||||
|
||||
MarkupDocBuilder textLine(String text);
|
||||
|
||||
MarkupDocBuilder paragraph(String text);
|
||||
@@ -32,7 +52,9 @@ public interface MarkupDocBuilder {
|
||||
|
||||
MarkupDocBuilder unorderedList(List<String> list);
|
||||
|
||||
MarkupDocBuilder tableWithHeaderRow(List<String> rowsInCSV);
|
||||
MarkupDocBuilder tableWithHeaderRow(List<String> rowsInPSV);
|
||||
|
||||
MarkupDocBuilder crossReference(String text);
|
||||
|
||||
MarkupDocBuilder newLine();
|
||||
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
*
|
||||
* 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.robwin.markup.builder;
|
||||
|
||||
|
||||
@@ -9,7 +27,7 @@ import io.github.robwin.markup.builder.markdown.MarkdownBuilder;
|
||||
*/
|
||||
public final class MarkupDocBuilders {
|
||||
|
||||
private MarkupDocBuilders(){};
|
||||
private MarkupDocBuilders(){}
|
||||
|
||||
public static MarkupDocBuilder documentBuilder(MarkupLanguage markupLanguage){
|
||||
switch(markupLanguage){
|
||||
|
||||
@@ -1,3 +1,22 @@
|
||||
/*
|
||||
*
|
||||
* 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.robwin.markup.builder;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
*
|
||||
* 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.robwin.markup.builder.asciidoc;
|
||||
|
||||
|
||||
@@ -9,15 +27,19 @@ import io.github.robwin.markup.builder.Markup;
|
||||
public enum AsciiDoc implements Markup {
|
||||
LABELED(":: "),
|
||||
TABLE("|==="),
|
||||
TABLE_COLUMN_DELIMITER("|"),
|
||||
LISTING("----"),
|
||||
HARDBREAKS(":hardbreaks:"),
|
||||
DOCUMENT_TITLE("= "),
|
||||
SECTION_TITLE_LEVEL1("== "),
|
||||
SECTION_TITLE_LEVEL2("=== "),
|
||||
SECTION_TITLE_LEVEL3("==== "),
|
||||
SECTION_TITLE_LEVEL4("===== "),
|
||||
BOLD("*"),
|
||||
ITALIC("_"),
|
||||
LIST_ENTRY("* ");
|
||||
LIST_ENTRY("* "),
|
||||
CROSS_REFERENCE_START("<<"),
|
||||
CROSS_REFERENCE_END(">>");
|
||||
|
||||
private final String markup;
|
||||
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
*
|
||||
* 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.robwin.markup.builder.asciidoc;
|
||||
|
||||
import io.github.robwin.markup.builder.AbstractMarkupDocBuilder;
|
||||
@@ -42,6 +60,12 @@ public class AsciiDocBuilder extends AbstractMarkupDocBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleLevel4(String title){
|
||||
sectionTitleLevel3(AsciiDoc.SECTION_TITLE_LEVEL4, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder paragraph(String text){
|
||||
paragraph(AsciiDoc.HARDBREAKS, text);
|
||||
@@ -80,16 +104,22 @@ public class AsciiDocBuilder extends AbstractMarkupDocBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder tableWithHeaderRow(List<String> rowsInCSV){
|
||||
documentBuilder.append("[format=\"csv\", options=\"header\"]").append(newLine);
|
||||
public MarkupDocBuilder tableWithHeaderRow(List<String> rowsInPSV){
|
||||
documentBuilder.append("[options=\"header\"]").append(newLine);
|
||||
documentBuilder.append(AsciiDoc.TABLE).append(newLine);
|
||||
for(String row : rowsInCSV){
|
||||
documentBuilder.append(row).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";
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
*
|
||||
* 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.robwin.markup.builder.markdown;
|
||||
|
||||
import io.github.robwin.markup.builder.Markup;
|
||||
@@ -7,13 +25,14 @@ import io.github.robwin.markup.builder.Markup;
|
||||
*/
|
||||
public enum Markdown implements Markup {
|
||||
HARDBREAKS(""),
|
||||
TABLE_COLUMN("|"),
|
||||
TABLE_COLUMN_DELIMITER("|"),
|
||||
TABLE_ROW("-"),
|
||||
LISTING("```"),
|
||||
DOCUMENT_TITLE("# "),
|
||||
SECTION_TITLE_LEVEL1("## "),
|
||||
SECTION_TITLE_LEVEL2("### "),
|
||||
SECTION_TITLE_LEVEL3("### "),
|
||||
SECTION_TITLE_LEVEL3("#### "),
|
||||
SECTION_TITLE_LEVEL4("##### "),
|
||||
BOLD("**"),
|
||||
ITALIC("*"),
|
||||
LIST_ENTRY("* ");
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
*
|
||||
* 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.robwin.markup.builder.markdown;
|
||||
|
||||
import io.github.robwin.markup.builder.AbstractMarkupDocBuilder;
|
||||
@@ -43,6 +61,12 @@ public class MarkdownBuilder extends AbstractMarkupDocBuilder
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleLevel4(String title){
|
||||
sectionTitleLevel3(Markdown.SECTION_TITLE_LEVEL4, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder paragraph(String text){
|
||||
paragraph(Markdown.HARDBREAKS, text);
|
||||
@@ -82,38 +106,42 @@ public class MarkdownBuilder extends AbstractMarkupDocBuilder
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder tableWithHeaderRow(List<String> rowsInCSV){
|
||||
String headersInCSV = rowsInCSV.get(0);
|
||||
List<String> contentRowsInCSV = rowsInCSV.subList(1, rowsInCSV.size());
|
||||
List<String> headers = Arrays.asList(headersInCSV.split(","));
|
||||
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);
|
||||
for(String header : headers){
|
||||
documentBuilder.append(header).append(Markdown.TABLE_COLUMN);
|
||||
}
|
||||
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);
|
||||
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);
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER.toString());
|
||||
}
|
||||
newLine();
|
||||
// Content
|
||||
for(String contentRow : contentRowsInCSV){
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN);
|
||||
List<String> columns = Arrays.asList(contentRow.split(","));
|
||||
for(String columnText : columns){
|
||||
documentBuilder.append(columnText).append(Markdown.TABLE_COLUMN);
|
||||
}
|
||||
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";
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
*
|
||||
* 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.robwin.markup.builder;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -14,14 +32,14 @@ import java.util.List;
|
||||
*/
|
||||
public class MarkupDocBuilderTest {
|
||||
|
||||
List<String> tableCsvRows;
|
||||
List<String> tableRowsInPSV;
|
||||
|
||||
@Before
|
||||
public void setUp(){
|
||||
tableCsvRows = new ArrayList<>();
|
||||
tableCsvRows.add("Header 1,Header 2,Header2");
|
||||
tableCsvRows.add("Row 1 Column 1,Row 1 Column 2,Row 1 Column 3");
|
||||
tableCsvRows.add("Row 2 Column 1,Row 2 Column 2,Row 2 Column 3");
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +53,7 @@ public class MarkupDocBuilderTest {
|
||||
.paragraph("Paragraph with long text bla bla bla bla bla")
|
||||
.listing("Source code listing")
|
||||
.source("MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC)", "java")
|
||||
.tableWithHeaderRow(tableCsvRows)
|
||||
.tableWithHeaderRow(tableRowsInPSV)
|
||||
.sectionTitleLevel1("Section Level 1b")
|
||||
.sectionTitleLevel2("Section Level 2b")
|
||||
.boldTextLine("Bold text line b")
|
||||
@@ -53,8 +71,8 @@ public class MarkupDocBuilderTest {
|
||||
.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(tableCsvRows)
|
||||
.source("MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN)", "java")
|
||||
.tableWithHeaderRow(tableRowsInPSV)
|
||||
.sectionTitleLevel1("Section Level 1b")
|
||||
.sectionTitleLevel2("Section Level 2b")
|
||||
.boldTextLine("Bold text line b")
|
||||
|
||||
Reference in New Issue
Block a user