Avoid need to escape pipe character in reference tables

pull/18413/head
dreis2211 5 years ago committed by Phillip Webb
parent 664cd15cfd
commit 8a6e254465

@ -45,9 +45,9 @@ class CompoundConfigurationTableEntry extends ConfigurationTableEntry {
@Override
void write(AsciidocBuilder builder) {
builder.append("|");
builder.append("¦");
this.configurationKeys.forEach(builder::appendKey);
builder.newLine().appendln("|").appendln("|+++", this.description, "+++");
builder.newLine().appendln("¦").appendln(+++", this.description, "+++");
}
}

@ -46,9 +46,9 @@ class ConfigurationTable {
String toAsciidocTable() {
AsciidocBuilder builder = new AsciidocBuilder();
builder.appendln("[cols=\"1,1,2\", options=\"header\"]");
builder.appendln("[cols=\"1,1,2\", separator=¦, options=\"header\"]");
builder.appendln("|===");
builder.appendln("|Key|Default Value|Description");
builder.appendln("¦Key¦Default Value¦Description");
builder.appendln();
this.entries.forEach((entry) -> {
entry.write(builder);

@ -54,7 +54,7 @@ class SingleConfigurationTableEntry extends ConfigurationTableEntry {
@Override
void write(AsciidocBuilder builder) {
builder.appendln("|`+", this.key, "+`");
builder.appendln("¦`+", this.key, "+`");
writeDefaultValue(builder);
writeDescription(builder);
builder.appendln();
@ -62,22 +62,21 @@ class SingleConfigurationTableEntry extends ConfigurationTableEntry {
private void writeDefaultValue(AsciidocBuilder builder) {
String defaultValue = (this.defaultValue != null) ? this.defaultValue : "";
defaultValue = defaultValue.replace("\\", "\\\\").replace("|", "{vbar}" + System.lineSeparator());
defaultValue = defaultValue.replace("\\", "\\\\");
if (defaultValue.isEmpty()) {
builder.appendln("|");
builder.appendln("¦");
}
else {
builder.appendln("|`+", defaultValue, "+`");
builder.appendln("¦`+", defaultValue, "+`");
}
}
private void writeDescription(AsciidocBuilder builder) {
if (this.description == null || this.description.isEmpty()) {
builder.append("|");
builder.append("¦");
}
else {
String cleanedDescription = this.description.replace("|", "\\|");
builder.append("|+++", cleanedDescription, "+++");
builder.append("¦+++", this.description, "+++");
}
}

@ -48,8 +48,8 @@ class CompoundConfigurationTableEntryTests {
AsciidocBuilder builder = new AsciidocBuilder();
entry.write(builder);
assertThat(builder.toString()).isEqualTo(
"|`+spring.test.first+` +" + NEWLINE + "`+spring.test.second+` +" + NEWLINE + "`+spring.test.third+` +"
+ NEWLINE + NEWLINE + "|" + NEWLINE + "|+++This is a description.+++" + NEWLINE);
"¦`+spring.test.first+` +" + NEWLINE + "`+spring.test.second+` +" + NEWLINE + "`+spring.test.third+` +"
+ NEWLINE + NEWLINE + "¦" + NEWLINE + +++This is a description.+++" + NEWLINE);
}
}

@ -46,10 +46,10 @@ class ConfigurationTableTests {
second.setType("java.lang.String");
table.addEntry(new SingleConfigurationTableEntry(first));
table.addEntry(new SingleConfigurationTableEntry(second));
assertThat(table.toAsciidocTable()).isEqualTo("[cols=\"1,1,2\", options=\"header\"]" + NEWLINE + "|==="
+ NEWLINE + "|Key|Default Value|Description" + NEWLINE + NEWLINE + "|`+spring.test.other+`" + NEWLINE
+ "|`+other value+`" + NEWLINE + "|+++This is another description.+++" + NEWLINE + NEWLINE
+ "|`+spring.test.prop+`" + NEWLINE + "|`+something+`" + NEWLINE + "|+++This is a description.+++"
assertThat(table.toAsciidocTable()).isEqualTo("[cols=\"1,1,2\", separator=¦, options=\"header\"]" + NEWLINE
+ "|===" + NEWLINE + "¦Key¦Default Value¦Description" + NEWLINE + NEWLINE + "¦`+spring.test.other+`"
+ NEWLINE + "¦`+other value+`" + NEWLINE + +++This is another description.+++" + NEWLINE + NEWLINE
+ "¦`+spring.test.prop+`" + NEWLINE + "¦`+something+`" + NEWLINE + +++This is a description.+++"
+ NEWLINE + NEWLINE + "|===" + NEWLINE);
}

@ -41,8 +41,8 @@ class SingleConfigurationTableEntryTests {
SingleConfigurationTableEntry entry = new SingleConfigurationTableEntry(property);
AsciidocBuilder builder = new AsciidocBuilder();
entry.write(builder);
assertThat(builder.toString()).isEqualTo("|`+spring.test.prop+`" + NEWLINE + "|`+something+`" + NEWLINE
+ "|+++This is a description.+++" + NEWLINE);
assertThat(builder.toString()).isEqualTo("¦`+spring.test.prop+`" + NEWLINE + `+something+`" + NEWLINE
+ "¦+++This is a description.+++" + NEWLINE);
}
@Test
@ -55,7 +55,7 @@ class SingleConfigurationTableEntryTests {
AsciidocBuilder builder = new AsciidocBuilder();
entry.write(builder);
assertThat(builder.toString()).isEqualTo(
"|`+spring.test.prop+`" + NEWLINE + "|" + NEWLINE + "|+++This is a description.+++" + NEWLINE);
"¦`+spring.test.prop+`" + NEWLINE + "¦" + NEWLINE + +++This is a description.+++" + NEWLINE);
}
@Test
@ -68,8 +68,8 @@ class SingleConfigurationTableEntryTests {
SingleConfigurationTableEntry entry = new SingleConfigurationTableEntry(property);
AsciidocBuilder builder = new AsciidocBuilder();
entry.write(builder);
assertThat(builder.toString()).isEqualTo("|`+spring.test.prop+`" + NEWLINE + "|`+first{vbar}" + NEWLINE
+ "second+`" + NEWLINE + "|+++This is a description.+++" + NEWLINE);
assertThat(builder.toString()).isEqualTo("¦`+spring.test.prop+`" + NEWLINE + "¦`+first|second+`" + NEWLINE
+ "¦+++This is a description.+++" + NEWLINE);
}
@Test
@ -82,8 +82,8 @@ class SingleConfigurationTableEntryTests {
SingleConfigurationTableEntry entry = new SingleConfigurationTableEntry(property);
AsciidocBuilder builder = new AsciidocBuilder();
entry.write(builder);
assertThat(builder.toString()).isEqualTo("|`+spring.test.prop+`" + NEWLINE + "|`+first\\\\second+`" + NEWLINE
+ "|+++This is a description.+++" + NEWLINE);
assertThat(builder.toString()).isEqualTo("¦`+spring.test.prop+`" + NEWLINE + `+first\\\\second+`" + NEWLINE
+ "¦+++This is a description.+++" + NEWLINE);
}
@Test
@ -95,8 +95,8 @@ class SingleConfigurationTableEntryTests {
SingleConfigurationTableEntry entry = new SingleConfigurationTableEntry(property);
AsciidocBuilder builder = new AsciidocBuilder();
entry.write(builder);
assertThat(builder.toString()).isEqualTo("|`+spring.test.prop+`" + NEWLINE + "|" + NEWLINE
+ "|+++This is a description with a \\| pipe.+++" + NEWLINE);
assertThat(builder.toString()).isEqualTo("¦`+spring.test.prop+`" + NEWLINE + " + NEWLINE
+ "¦+++This is a description with a | pipe.+++" + NEWLINE);
}
@Test
@ -109,7 +109,7 @@ class SingleConfigurationTableEntryTests {
AsciidocBuilder builder = new AsciidocBuilder();
entry.write(builder);
assertThat(builder.toString()).isEqualTo(
"|`+spring.test.prop.*+`" + NEWLINE + "|" + NEWLINE + "|+++This is a description.+++" + NEWLINE);
"¦`+spring.test.prop.*+`" + NEWLINE + "¦" + NEWLINE + +++This is a description.+++" + NEWLINE);
}
@Test
@ -123,8 +123,8 @@ class SingleConfigurationTableEntryTests {
SingleConfigurationTableEntry entry = new SingleConfigurationTableEntry(property);
AsciidocBuilder builder = new AsciidocBuilder();
entry.write(builder);
assertThat(builder.toString()).isEqualTo("|`+spring.test.prop+`" + NEWLINE + "|`+first," + NEWLINE + "second,"
+ NEWLINE + "third+`" + NEWLINE + "|+++This is a description.+++" + NEWLINE);
assertThat(builder.toString()).isEqualTo("¦`+spring.test.prop+`" + NEWLINE + `+first," + NEWLINE + "second,"
+ NEWLINE + "third+`" + NEWLINE + "¦+++This is a description.+++" + NEWLINE);
}
}

Loading…
Cancel
Save