Disable formatting of monospaced text in Asciidoctor templates

Previously, if text enclosed in ` characters contained multiple *
characters, the *s would be removed and the characters they enclosed
would become bold.

This commit escapes the text by enclosing it in + characters in
addition to the existing, enclosing ` characters. The `+text+`
arrangement retains the monospace formatting be disables any further
formatting of the text.

Closes gh-474
This commit is contained in:
Andy Wilkinson
2018-03-27 15:34:14 +01:00
parent 0b0c9e1cc4
commit 7924d5fb01
10 changed files with 21 additions and 14 deletions

View File

@@ -2,7 +2,7 @@
|Relation|Description
{{#links}}
|{{#tableCellContent}}`{{rel}}`{{/tableCellContent}}
|{{#tableCellContent}}`+{{rel}}+`{{/tableCellContent}}
|{{#tableCellContent}}{{description}}{{/tableCellContent}}
{{/links}}

View File

@@ -3,7 +3,7 @@
|Parameter|Description
{{#parameters}}
|{{#tableCellContent}}`{{name}}`{{/tableCellContent}}
|{{#tableCellContent}}`+{{name}}+`{{/tableCellContent}}
|{{#tableCellContent}}{{description}}{{/tableCellContent}}
{{/parameters}}

View File

@@ -2,8 +2,8 @@
|Path|Type|Description
{{#fields}}
|{{#tableCellContent}}`{{path}}`{{/tableCellContent}}
|{{#tableCellContent}}`{{type}}`{{/tableCellContent}}
|{{#tableCellContent}}`+{{path}}+`{{/tableCellContent}}
|{{#tableCellContent}}`+{{type}}+`{{/tableCellContent}}
|{{#tableCellContent}}{{description}}{{/tableCellContent}}
{{/fields}}

View File

@@ -2,7 +2,7 @@
|Name|Description
{{#headers}}
|{{#tableCellContent}}`{{name}}`{{/tableCellContent}}
|{{#tableCellContent}}`+{{name}}+`{{/tableCellContent}}
|{{#tableCellContent}}{{description}}{{/tableCellContent}}
{{/headers}}

View File

@@ -2,7 +2,7 @@
|Parameter|Description
{{#parameters}}
|{{#tableCellContent}}`{{name}}`{{/tableCellContent}}
|{{#tableCellContent}}`+{{name}}+`{{/tableCellContent}}
|{{#tableCellContent}}{{description}}{{/tableCellContent}}
{{/parameters}}

View File

@@ -2,8 +2,8 @@
|Path|Type|Description
{{#fields}}
|{{#tableCellContent}}`{{path}}`{{/tableCellContent}}
|{{#tableCellContent}}`{{type}}`{{/tableCellContent}}
|{{#tableCellContent}}`+{{path}}+`{{/tableCellContent}}
|{{#tableCellContent}}`+{{type}}+`{{/tableCellContent}}
|{{#tableCellContent}}{{description}}{{/tableCellContent}}
{{/fields}}

View File

@@ -2,7 +2,7 @@
|Part|Description
{{#requestParts}}
|{{#tableCellContent}}`{{name}}`{{/tableCellContent}}
|{{#tableCellContent}}`+{{name}}+`{{/tableCellContent}}
|{{#tableCellContent}}{{description}}{{/tableCellContent}}
{{/requestParts}}

View File

@@ -2,8 +2,8 @@
|Path|Type|Description
{{#fields}}
|{{#tableCellContent}}`{{path}}`{{/tableCellContent}}
|{{#tableCellContent}}`{{type}}`{{/tableCellContent}}
|{{#tableCellContent}}`+{{path}}+`{{/tableCellContent}}
|{{#tableCellContent}}`+{{type}}+`{{/tableCellContent}}
|{{#tableCellContent}}{{description}}{{/tableCellContent}}
{{/fields}}

View File

@@ -2,7 +2,7 @@
|Name|Description
{{#headers}}
|{{#tableCellContent}}`{{name}}`{{/tableCellContent}}
|{{#tableCellContent}}`+{{name}}+`{{/tableCellContent}}
|{{#tableCellContent}}{{description}}{{/tableCellContent}}
{{/headers}}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -335,12 +335,19 @@ public final class SnippetMatchers {
@Override
public AsciidoctorTableMatcher row(String... entries) {
for (String entry : entries) {
this.addLine(-1, "|" + entry);
this.addLine(-1, "|" + escapeEntry(entry));
}
this.addLine(-1, "");
return this;
}
private String escapeEntry(String entry) {
if (entry.startsWith("`") && entry.endsWith("`")) {
return "`+" + entry.substring(1, entry.length() - 1) + "+`";
}
return entry;
}
@Override
public AsciidoctorTableMatcher configuration(String configuration) {
this.addLine(0, configuration);