Skip to content

Commit 1c0a955

Browse files
authored
Fix characters interpreted as Smithy format specifiers in doc gen (#582)
1 parent 42d669f commit 1c0a955

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

codegen/aws/core/src/test/java/software/amazon/smithy/python/aws/codegen/MarkdownToRstDocConverterTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,13 @@ public void testConvertCommonmarkToRstWithNestedList() {
106106
String result = markdownToRstDocConverter.convertCommonmarkToRst(html);
107107
assertEquals(expected, result.trim());
108108
}
109+
110+
@Test
111+
public void testConvertCommonmarkToRstWithFormatSpecifierCharacters() {
112+
// Test that Smithy format specifier characters ($) are properly escaped and treated as literal text
113+
String html = "<html><body><p>Testing $placeholder_one and $placeholder_two</p></body></html>";
114+
String expected = "Testing $placeholder_one and $placeholder_two";
115+
String result = markdownToRstDocConverter.convertCommonmarkToRst(html);
116+
assertEquals(expected, result.trim());
117+
}
109118
}

codegen/core/src/main/java/software/amazon/smithy/python/codegen/writer/MarkdownToRstDocConverter.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void head(Node node, int depth) {
7878
if (!text.trim().isEmpty()) {
7979
if (text.startsWith(":param ")) {
8080
int secondColonIndex = text.indexOf(':', 1);
81-
writer.write(text.substring(0, secondColonIndex + 1));
81+
writer.write("$L", text.substring(0, secondColonIndex + 1));
8282
//TODO right now the code generator gives us a mixture of
8383
// RST and HTML (for instance :param xyz: <p> docs
8484
// </p>). Since we standardize to html above, that <p> tag
@@ -91,16 +91,16 @@ public void head(Node node, int depth) {
9191
} else {
9292
writer.ensureNewline();
9393
writer.indent();
94-
writer.write(text.substring(secondColonIndex + 1));
94+
writer.write("$L", text.substring(secondColonIndex + 1));
9595
writer.dedent();
9696
}
9797
} else {
98-
writer.writeInline(text);
98+
writer.writeInline("$L", text);
9999
}
100100
// Account for services making a paragraph tag that's empty except
101101
// for a newline
102102
} else if (node.parent() != null && ((Element) node.parent()).tagName().equals("p")) {
103-
writer.writeInline(text.replaceAll("[ \\t]+", ""));
103+
writer.writeInline("$L", text.replaceAll("[ \\t]+", ""));
104104
}
105105
} else if (node instanceof Element) {
106106
Element element = (Element) node;
@@ -158,7 +158,7 @@ public void tail(Node node, int depth) {
158158
case "a":
159159
String href = element.attr("href");
160160
if (!href.isEmpty()) {
161-
writer.writeInline(" <").writeInline(href).writeInline(">`_");
161+
writer.writeInline(" <").writeInline("$L", href).writeInline(">`_");
162162
} else {
163163
writer.writeInline("`");
164164
}
@@ -196,7 +196,7 @@ public void tail(Node node, int depth) {
196196
break;
197197
case "h1":
198198
String title = element.text();
199-
writer.ensureNewline().writeInline("=".repeat(title.length())).ensureNewline();
199+
writer.ensureNewline().writeInline("$L", "=".repeat(title.length())).ensureNewline();
200200
break;
201201
default:
202202
break;

0 commit comments

Comments
 (0)