Skip to content

Commit e8fdf0b

Browse files
Merge pull request #1 from diffbot/performance-fixes
Use a string function rather than regex for better performance
2 parents cc3a2f5 + 5003bed commit e8fdf0b

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

flexmark-html2md-converter/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<version>0.64.8</version>
88
</parent>
99

10+
<groupId>com.diffbot</groupId>
1011
<artifactId>flexmark-html2md-converter</artifactId>
1112
<name>flexmark-java HTML to Markdown extensible converter</name>
1213
<description>flexmark-java customizable extension to convert HTML to Markdown</description>

flexmark-html2md-converter/src/main/java/com/vladsch/flexmark/html2md/converter/internal/HtmlConverterCoreNodeRenderer.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ private void handleTableCaption(Element element, HtmlNodeConverterContext contex
11991199
}
12001200

12011201
private void handleTableCell(Element element, HtmlNodeConverterContext context, HtmlMarkdownWriter out) {
1202-
String cellText = context.processTextNodes(element).trim().replaceAll("\\s*\n\\s*", " ");
1202+
String cellText = replaceMultipleBlankSpace(context.processTextNodes(element).trim());
12031203
int colSpan = 1;
12041204
int rowSpan = 1;
12051205
CellAlignment alignment = null;
@@ -1260,6 +1260,25 @@ private void handleTableCell(Element element, HtmlNodeConverterContext context,
12601260
}
12611261
}
12621262

1263+
private String replaceMultipleBlankSpace(String cellText) {
1264+
StringBuilder result = new StringBuilder();
1265+
boolean wasSpace = false;
1266+
1267+
for (char c : cellText.toCharArray()) {
1268+
if (Character.isWhitespace(c)) {
1269+
if (!wasSpace) {
1270+
result.append(' ');
1271+
wasSpace = true;
1272+
}
1273+
} else {
1274+
result.append(c);
1275+
wasSpace = false;
1276+
}
1277+
}
1278+
1279+
return result.toString();
1280+
}
1281+
12631282
private boolean matchingText(Pattern pattern, String text, String[] match) {
12641283
Matcher matcher = pattern.matcher(text);
12651284
if (matcher.matches()) {

pom.xml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,10 @@
9393

9494
<distributionManagement>
9595
<snapshotRepository>
96-
<id>ossrh</id>
97-
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
96+
<id>diffbot-nexus-snapshots</id>
9897
</snapshotRepository>
9998
<repository>
100-
<id>ossrh</id>
101-
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
99+
<id>diffbot-nexus-releases</id>
102100
</repository>
103101
</distributionManagement>
104102

0 commit comments

Comments
 (0)