Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Winkler committed Apr 29, 2016
2 parents 7b8c5e7 + 9e03544 commit 1ae72d9
Show file tree
Hide file tree
Showing 13 changed files with 190 additions and 86 deletions.
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
:version: 1.0.0
: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.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"]
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/markup-document-builder/images/download.svg[link="https://bintray.com/swagger2markup/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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,27 +266,53 @@ public interface MarkupDocBuilder {
* @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 #listing(String, String) listing(String, null)}.
* This is an alias for {@link #block(String, MarkupBlockStyle, String, MarkupAdmonition) block(String, MarkupBlockStyle.LISTING, null, null)}.
* This is an alias for {@link #listingBlock(String, String) listingBlock(String, null)}.
*
* @param text multi-line text
* @return this builder
*/
MarkupDocBuilder listing(String text);
MarkupDocBuilder listingBlock(String text);

/**
* Builds a source code block using the specified {@code language}.<br>
* Line breaks are respected.
* Builds a literal text line.<br>
* This is an alias for {@link #literalTextLine(String, boolean) literalTextLine(text, false)}.
*
* @param text multi-line text
* @param language source code language. Simple listing if {@code language} == null.
* @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 listing(String text, String language);
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)}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,25 @@ public String getAnchorPrefix() {
}

protected void documentTitle(Markup markup, String title) {
Validate.notBlank(title, "title must not be null");
Validate.notBlank(title, "title must not be blank");
documentBuilder.append(markup).append(replaceNewLinesWithWhiteSpace(title)).append(newLine).append(newLine);
}

protected void sectionTitleWithAnchorLevel(Markup markup, int level, String title, String anchor) {
Validate.notBlank(title, "title must not be null");
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);
if (anchor != null)
anchor(replaceNewLinesWithWhiteSpace(anchor)).newLine();
documentBuilder.append(StringUtils.repeat(markup.toString(), level + 1)).append(" ").append(replaceNewLinesWithWhiteSpace(title)).append(newLine);
}

@Override
public MarkupDocBuilder sectionTitleLevel(int level, String title) {
return sectionTitleWithAnchorLevel(level, title, null);
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
Expand Down Expand Up @@ -188,7 +191,7 @@ public MarkupDocBuilder sectionTitleWithAnchorLevel5(String title) {

@Override
public MarkupDocBuilder textLine(String text, boolean forceLineBreak) {
Validate.notBlank(text, "text must not be null");
Validate.notNull(text, "text must not be null");
text(replaceNewLines(text));
newLine(forceLineBreak);
return this;
Expand All @@ -202,30 +205,30 @@ public MarkupDocBuilder textLine(String text) {

@Override
public MarkupDocBuilder text(String text) {
Validate.notBlank(text, "text must not be null");
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 null");
Validate.notBlank(text, "text must not be blank");
return block(replaceNewLines(text), style, null, null);
}

@Override
public MarkupDocBuilder listing(String text) {
Validate.notBlank(text, "text must not be null");
return listing(replaceNewLines(text), null);
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) {
Validate.notBlank(text, "text must not be null");
Validate.notBlank(text, "text must not be blank");
if (!StringUtils.isBlank(begin.toString()))
documentBuilder.append(begin).append(newLine);
documentBuilder.append(replaceNewLines(text)).append(newLine);
Expand All @@ -235,7 +238,7 @@ protected void delimitedBlockText(Markup begin, String text, Markup end) {
}

protected void delimitedTextWithoutLineBreaks(Markup begin, String text, Markup end) {
Validate.notBlank(text, "text must not be null");
Validate.notBlank(text, "text must not be blank");
if (!StringUtils.isBlank(begin.toString()))
documentBuilder.append(begin);
documentBuilder.append(replaceNewLines(text));
Expand All @@ -251,13 +254,30 @@ 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 null");
Validate.notBlank(text, "text must not be blank");
boldText(replaceNewLines(text));
newLine(forceLineBreak);
return this;
Expand Down Expand Up @@ -285,7 +305,7 @@ public MarkupDocBuilder italicTextLine(String text) {
}

protected void unorderedList(Markup markup, List<String> list) {
Validate.notEmpty(list, "list must not be null");
Validate.notEmpty(list, "list must not be empty");
documentBuilder.append(newLine);
for (String listEntry : list) {
unorderedListItem(markup, listEntry);
Expand All @@ -294,17 +314,17 @@ protected void unorderedList(Markup markup, List<String> list) {
}

protected void unorderedListItem(Markup markup, String item) {
Validate.notBlank(item, "item must not be null");
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 null");
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public enum AsciiDoc implements Markup {
TABLE_COLUMN_DELIMITER("|"),
TITLE("="),
DOCUMENT_TITLE("= "),
LITERAL("`"),
BOLD("*"),
ITALIC("_"),
LIST_ENTRY("* "),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ public MarkupDocBuilder documentTitle(String 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);
Expand All @@ -82,7 +88,7 @@ public MarkupDocBuilder sectionTitleWithAnchorLevel(int level, String title, Str

@Override
public MarkupDocBuilder paragraph(String text, boolean hardbreaks) {
Validate.notBlank(text, "text must not be null");
Validate.notBlank(text, "text must not be blank");
if (hardbreaks)
documentBuilder.append("[%hardbreaks]").append(newLine);
text = text.trim();
Expand All @@ -105,6 +111,12 @@ public String toString() {
return this;
}

@Override
public MarkupDocBuilder literalText(String text) {
boldText(AsciiDoc.LITERAL, text);
return this;
}

@Override
public MarkupDocBuilder boldText(String text) {
boldText(AsciiDoc.BOLD, text);
Expand All @@ -130,7 +142,7 @@ public MarkupDocBuilder unorderedListItem(String item) {
}

@Override
public MarkupDocBuilder listing(String text, String language) {
public MarkupDocBuilder listingBlock(String text, String language) {
if (language != null)
documentBuilder.append(String.format("[source,%s]", language)).append(newLine);
block(text, MarkupBlockStyle.LISTING);
Expand Down Expand Up @@ -171,8 +183,11 @@ public MarkupDocBuilder crossReferenceRaw(String document, String anchor, String
if (document != null)
documentBuilder.append(document).append("#");
documentBuilder.append(anchor);
if (text != null)
if (text != null) {
documentBuilder.append(",").append(text);
if (text.endsWith(">"))
documentBuilder.append(" ");
}
documentBuilder.append(AsciiDoc.CROSS_REFERENCE_END);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
public enum ConfluenceMarkup implements Markup {
TABLE_COLUMN_DELIMITER("|"),
LITERAL("{noformat}"),
BOLD("*"),
ITALIC("_"),
LIST_ENTRY("* "),
Expand Down
Loading

0 comments on commit 1ae72d9

Please sign in to comment.