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 @Override
void write(AsciidocBuilder builder) { void write(AsciidocBuilder builder) {
builder.append("|"); builder.append("¦");
this.configurationKeys.forEach(builder::appendKey); 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() { String toAsciidocTable() {
AsciidocBuilder builder = new AsciidocBuilder(); 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("|===");
builder.appendln("|Key|Default Value|Description"); builder.appendln("¦Key¦Default Value¦Description");
builder.appendln(); builder.appendln();
this.entries.forEach((entry) -> { this.entries.forEach((entry) -> {
entry.write(builder); entry.write(builder);

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

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

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

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

Loading…
Cancel
Save