Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pacmak/python): escape character escapes in python docs #2138

Merged
merged 8 commits into from Oct 22, 2020
2 changes: 1 addition & 1 deletion packages/jsii-pacmak/lib/markdown.ts
Expand Up @@ -20,7 +20,7 @@ export function md2rst(text: string) {
}

function textOf(node: commonmark.Node) {
return node.literal ?? '';
return node.literal?.replace(/\\/g, '\\\\') ?? '';
}

pump(ast, {
Expand Down
17 changes: 17 additions & 0 deletions packages/jsii-pacmak/test/python.test.ts
Expand Up @@ -113,6 +113,23 @@ test('list with multiline text', () => {
);
});

test('escape character escaping', () => {
converts(
[
String.raw`For example, if you specify "\N", BigQuery interprets "\N" as a null value`,
String.raw`Single slash \\`, // markdown parses the escape even if ts doesn't
String.raw`Double slash \\\\`,
String.raw`Triple slash \\\\\\`,
],
[
String.raw`For example, if you specify "\\N", BigQuery interprets "\\N" as a null value`,
String.raw`Single slash \\`,
String.raw`Double slash \\\\`,
String.raw`Triple slash \\\\\\`,
],
);
});

function converts(input: string[], output: string[]) {
const converted = md2rst(input.join('\n'));

Expand Down