Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6afe41b7a9 | ||
|
|
f5aadc2319 | ||
|
|
0730b94c24 | ||
|
|
59c63e8ac0 |
@@ -1,6 +1,6 @@
|
||||
= MarkupDocBuilder
|
||||
:author: Robert Winkler
|
||||
:version: 1.0.0
|
||||
:version: 1.1.1
|
||||
:hardbreaks:
|
||||
|
||||
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"]
|
||||
@@ -29,9 +29,8 @@ 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>{version}</version>
|
||||
</dependency>
|
||||
@@ -45,7 +44,7 @@ repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
compile "io.github.robwin:markup-document-builder:{version}"
|
||||
compile "io.github.swagger2markup:markup-document-builder:{version}"
|
||||
----
|
||||
|
||||
=== Using MarkupDocBuilder
|
||||
|
||||
@@ -22,4 +22,8 @@
|
||||
* 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.
|
||||
* Added a method to add page breaks.
|
||||
|
||||
== Version 1.1.2
|
||||
* Improve code blocks in markdown
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ buildscript {
|
||||
}
|
||||
}
|
||||
description = 'A Markup (Markdown, AsciiDoc) document builder'
|
||||
version = '1.1.1-SNAPSHOT'
|
||||
version = '1.1.2'
|
||||
group = 'io.github.swagger2markup'
|
||||
|
||||
apply plugin: 'java'
|
||||
@@ -64,5 +64,5 @@ tasks.asciidoctor {
|
||||
}
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
gradleVersion = '2.12'
|
||||
gradleVersion = '4.3.1'
|
||||
}
|
||||
|
||||
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 Mar 31 16:37:14 CEST 2016
|
||||
#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.12-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3.1-all.zip
|
||||
|
||||
68
gradlew
vendored
68
gradlew
vendored
@@ -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,26 +59,11 @@ case "`uname`" in
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
# 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
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
@@ -85,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
|
||||
@@ -150,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
|
||||
|
||||
@@ -231,8 +231,8 @@ public interface MarkupDocBuilder {
|
||||
/**
|
||||
* Builds a text paragraph.<br>
|
||||
*
|
||||
* @param text multi-line text
|
||||
* @param hardbreaks force hardbreaks on all lines
|
||||
* @param text multi-line text
|
||||
* @param hardbreaks force hardbreaks on all lines
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder paragraph(String text, boolean hardbreaks);
|
||||
@@ -256,24 +256,26 @@ public interface MarkupDocBuilder {
|
||||
/**
|
||||
* 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.
|
||||
* @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
|
||||
* @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.
|
||||
@@ -319,7 +321,7 @@ public interface MarkupDocBuilder {
|
||||
* @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)}.
|
||||
@@ -521,7 +523,7 @@ public interface MarkupDocBuilder {
|
||||
* 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>
|
||||
* <li> Markdown -> AsciiDoc </li>
|
||||
* </ul>
|
||||
* Newlines are normalized in the process.
|
||||
*
|
||||
|
||||
@@ -209,7 +209,7 @@ public abstract class AbstractMarkupDocBuilder implements MarkupDocBuilder {
|
||||
documentBuilder.append(replaceNewLines(text));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder paragraph(String text) {
|
||||
return paragraph(text, false);
|
||||
@@ -227,13 +227,29 @@ public abstract class AbstractMarkupDocBuilder implements MarkupDocBuilder {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -385,7 +401,7 @@ public abstract class AbstractMarkupDocBuilder implements MarkupDocBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder importMarkup(Reader markupText, MarkupLanguage markupLanguage){
|
||||
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);
|
||||
|
||||
@@ -83,7 +83,7 @@ public class MarkdownBuilder extends AbstractMarkupDocBuilder {
|
||||
sectionTitleLevel(Markdown.TITLE, level, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel(int level, String title, String anchor) {
|
||||
sectionTitleWithAnchorLevel(Markdown.TITLE, level, title, anchor);
|
||||
@@ -112,6 +112,8 @@ public class MarkdownBuilder extends AbstractMarkupDocBuilder {
|
||||
|
||||
@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) {
|
||||
@@ -122,18 +124,27 @@ public class MarkdownBuilder extends AbstractMarkupDocBuilder {
|
||||
if (admonition != null || title != null)
|
||||
documentBuilder.append(" : ").append(newLine);
|
||||
|
||||
delimitedBlockText(new Markup() {
|
||||
Markup m = new Markup() {
|
||||
public String toString() {
|
||||
return BLOCK_STYLE.get(style);
|
||||
}
|
||||
}, text);
|
||||
};
|
||||
|
||||
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) {
|
||||
if (language != null)
|
||||
text = language + " :" + newLine + text;
|
||||
text = newLine + text;
|
||||
if (language != null) {
|
||||
text = language + text;
|
||||
}
|
||||
block(text, MarkupBlockStyle.LISTING);
|
||||
return this;
|
||||
}
|
||||
@@ -143,7 +154,7 @@ public class MarkdownBuilder extends AbstractMarkupDocBuilder {
|
||||
boldText(Markdown.LITERAL, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder boldText(String text) {
|
||||
boldText(Markdown.BOLD, text);
|
||||
|
||||
@@ -129,6 +129,19 @@ public class MarkupDocBuilderTest {
|
||||
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);
|
||||
|
||||
@@ -52,8 +52,7 @@ Line2
|
||||
Source code listing
|
||||
```
|
||||
|
||||
```
|
||||
java :
|
||||
```java
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN)
|
||||
```
|
||||
|
||||
|
||||
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