Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace pegdown dependency with flexmark #439

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions libraries.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ implLibraries = [
commonsText : "org.apache.commons:commons-text:1.8",
guava : 'com.google.guava:guava:27.0.1-android',
jacksonDatabind : 'com.fasterxml.jackson.core:jackson-databind:2.9.10',
mark2Ascii : "nl.jworks.markdown_to_asciidoc:markdown_to_asciidoc:1.1",
paleo : "ch.netzwerg:paleo-core:0.14.0",
pegdown : "org.pegdown:pegdown:1.6.0",
flexmarkJava : "com.vladsch.flexmark:flexmark-all:0.62.2",
slf4j : "org.slf4j:slf4j-api:1.7.28",
swaggerV2 : "io.swagger:swagger-parser:1.0.47",
swaggerV2Converter : "io.swagger.parser.v3:swagger-parser-v2-converter:2.0.15",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ swagger2markup.propertyOrderBy=NATURAL
swagger2markup.responseOrderBy=NATURAL
swagger2markup.listDelimiterEnabled=false
swagger2markup.listDelimiter=,
swagger2markup.asciidoc.pegdown.timeoutMillis=2000

swagger2markup.generatedExamplesEnabled=false
# basic, curl, invoke-webrequest
Expand Down
3 changes: 1 addition & 2 deletions swagger2markup-builder/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ dependencies {
implementation implLibraries.commonsCodec
implementation implLibraries.commonsLang3
implementation implLibraries.commonsIO
implementation implLibraries.mark2Ascii
implementation implLibraries.slf4j
implementation implLibraries.pegdown
implementation implLibraries.flexmarkJava
testImplementation testLibraries.assertjDiff
testImplementation testLibraries.junit
testImplementation testLibraries.logback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,38 +78,4 @@ public static MarkupDocBuilder documentBuilder(MarkupLanguage markupLanguage, Li
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.
* There is a possibility asciidoc generator pegdown (<a href="https://github.com/sirthias/pegdown#parsing-timeouts">optional</a>) can
* take more time. The default is set to two seconds. To override pass value greater than two seconds.
*
* @param markupLanguage the markup language which is used to generate the files
* @param lineSeparator the line separator which should be used
* @param asciidocPegdownTimeoutMillis asciidoc generator timeout
* @return a MarkupDocBuilder
*/
public static MarkupDocBuilder documentBuilder(MarkupLanguage markupLanguage, LineSeparator lineSeparator, int asciidocPegdownTimeoutMillis) {
switch (markupLanguage) {
case MARKDOWN:
if (lineSeparator == null)
return new MarkdownBuilder();
else
return new MarkdownBuilder(lineSeparator.toString());
case ASCIIDOC:
if (lineSeparator == null)
return new AsciiDocBuilder(asciidocPegdownTimeoutMillis);
else
return new AsciiDocBuilder(lineSeparator.toString(), asciidocPegdownTimeoutMillis);
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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,19 @@ public abstract class AbstractMarkupDocBuilder implements MarkupDocBuilder {
protected static final int MAX_TITLE_LEVEL = 5;
protected static final String NEW_LINES = "\\r\\n|\\r|\\n";
protected static final String WHITESPACE = " ";
protected static final int ASCIIDOC_PEGDOWN_DEFUALT_MILLIS = 2000;

protected StringBuilder documentBuilder = new StringBuilder();
protected String newLine;
protected int asciidocPegdownTimeoutMillis;
protected Logger logger = LoggerFactory.getLogger(getClass());

protected String anchorPrefix = null;

public AbstractMarkupDocBuilder() {
this(System.getProperty("line.separator"), ASCIIDOC_PEGDOWN_DEFUALT_MILLIS);
this(System.getProperty("line.separator"));
}

public AbstractMarkupDocBuilder(String newLine) {
this(newLine, ASCIIDOC_PEGDOWN_DEFUALT_MILLIS);
}

public AbstractMarkupDocBuilder(String newLine, int asciidocPegdownTimeoutMillis) {
this.newLine = newLine;
this.asciidocPegdownTimeoutMillis = asciidocPegdownTimeoutMillis;
}

protected abstract MarkupLanguage getMarkupLanguage();
Expand Down Expand Up @@ -420,7 +413,7 @@ protected String convert(String markupText, MarkupLanguage markupLanguage) {
return markupText;
else {
if (markupLanguage == MarkupLanguage.MARKDOWN && getMarkupLanguage() == MarkupLanguage.ASCIIDOC) {
return AsciiDocConverterExtension.convertMarkdownToAsciiDoc(markupText, asciidocPegdownTimeoutMillis) + newLine;
return AsciiDocConverterExtension.convertMarkdownToAsciiDoc(markupText) + newLine;
} else {
return markupText;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,17 @@ public AsciiDocBuilder() {
super();
}

public AsciiDocBuilder(int asciidocPegdownTimeoutMillis) {
super(System.getProperty("line.separator"), asciidocPegdownTimeoutMillis);
}

public AsciiDocBuilder(String newLine) {
super(newLine);
}

public AsciiDocBuilder(String newLine, int asciidocPegdownTimeoutMillis) {
super(newLine, asciidocPegdownTimeoutMillis);
}

protected MarkupLanguage getMarkupLanguage() {
return MarkupLanguage.ASCIIDOC;
}

@Override
public MarkupDocBuilder copy(boolean copyBuffer) {
AsciiDocBuilder builder = new AsciiDocBuilder(newLine, asciidocPegdownTimeoutMillis);
AsciiDocBuilder builder = new AsciiDocBuilder(newLine);

if (copyBuffer)
builder.documentBuilder = new StringBuilder(this.documentBuilder);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
package io.github.swagger2markup.markup.builder.internal.asciidoc;

import org.pegdown.Extensions;
import org.pegdown.PegDownProcessor;
import org.pegdown.ast.RootNode;
import com.vladsch.flexmark.html.HtmlRenderer;
import com.vladsch.flexmark.parser.Parser;
import com.vladsch.flexmark.util.ast.Node;
import com.vladsch.flexmark.util.data.MutableDataSet;

import nl.jworks.markdown_to_asciidoc.Converter;
import nl.jworks.markdown_to_asciidoc.ToAsciiDocSerializer;
public class AsciiDocConverterExtension {

public class AsciiDocConverterExtension extends Converter {
private static final Parser parser;
private static final HtmlRenderer renderer;

static {
MutableDataSet options = new MutableDataSet();
parser = Parser.builder(options).build();
renderer = HtmlRenderer.builder(options).build();
}

/**
* Converts markdown to asciidoc.
*
* @param markdown the markdown source to convert
* @param timeoutMills parsing timeout
* @return asciidoc format
*/
public static String convertMarkdownToAsciiDoc(String markdown, long timeoutMills) {
PegDownProcessor processor = new PegDownProcessor(Extensions.ALL, timeoutMills);
// insert blank line before fenced code block if necessary
if (markdown.contains("```")) {
markdown = markdown.replaceAll("(?m)(?<!\n\n)(\\s*)```(\\w*\n)((?:\\1[^\n]*\n)+)\\1```", "\n$1```$2$3$1```");
}
char[] markDown = markdown.toCharArray();
RootNode rootNode = processor.parseMarkdown(markDown);
return new ToAsciiDocSerializer(rootNode, markdown).toAsciiDoc();
Node document = parser.parse(markdown);
return renderer.render(document);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public class Schema2MarkupProperties {
public static final String RESPONSE_ORDER_BY = PROPERTIES_PREFIX + ".responseOrderBy";
public static final String LINE_SEPARATOR = PROPERTIES_PREFIX + ".lineSeparator";
public static final String PAGE_BREAK_LOCATIONS = PROPERTIES_PREFIX + ".pageBreakLocations";
public static final String ASCIIDOC_PEGDOWN_TIMEOUT = PROPERTIES_PREFIX + ".asciidoc.pegdown.timeoutMillis";

/**
* Prefix for Swagger2Markup extension properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,6 @@ public interface Schema2MarkupConfig {
*/
List<PageBreakLocations> getPageBreakLocations();

/**
* Returns custom timeout value.
*
* @return custom timeout value
*/
int getAsciidocPegdownTimeoutMillis();

/**
* Returns format name which should be used to format request example string.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ public Schema2MarkupConfigBuilder(final Class<T> selfClass,
Configuration swagger2markupConfiguration = schema2MarkupProperties.getConfiguration().subset(PROPERTIES_PREFIX);
Configuration extensionsConfiguration = swagger2markupConfiguration.subset(EXTENSION_PREFIX);
config.extensionsProperties = new Schema2MarkupProperties(extensionsConfiguration);
config.asciidocPegdownTimeoutMillis = schema2MarkupProperties.getRequiredInt(ASCIIDOC_PEGDOWN_TIMEOUT);
}

/**
Expand Down Expand Up @@ -691,7 +690,6 @@ public static class DefaultSchema2MarkupConfig implements Schema2MarkupConfig {
String separatedDefinitionsFolder;
Character listDelimiter;
boolean listDelimiterEnabled;
int asciidocPegdownTimeoutMillis;

List<PageBreakLocations> pageBreakLocations;

Expand Down Expand Up @@ -894,11 +892,6 @@ public List<PageBreakLocations> getPageBreakLocations() {
return pageBreakLocations;
}

@Override
public int getAsciidocPegdownTimeoutMillis() {
return asciidocPegdownTimeoutMillis;
}

@Override
public String getRequestExamplesFormat() {
return requestExamplesFormat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,7 @@ public MarkupDocBuilder createMarkupDocBuilder() {
if (config.getLineSeparator() != null) {
lineSeparator = LineSeparator.valueOf(config.getLineSeparator().name());
}
return MarkupDocBuilders.documentBuilder(markupLanguage, lineSeparator,
config.getAsciidocPegdownTimeoutMillis()).withAnchorPrefix(config.getAnchorPrefix());
return MarkupDocBuilders.documentBuilder(markupLanguage, lineSeparator).withAnchorPrefix(config.getAnchorPrefix());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ swagger2markup.propertyOrderBy=NATURAL
swagger2markup.responseOrderBy=NATURAL
swagger2markup.listDelimiterEnabled=false
swagger2markup.listDelimiter=,
swagger2markup.asciidoc.pegdown.timeoutMillis=2000

swagger2markup.generatedExamplesEnabled=false
# basic, curl, invoke-webrequest
Expand Down