Skip to content

Commit f0bd843

Browse files
Copilotalexr00
andcommitted
Add strong and em formatting support to PlainTextRenderer when allowSimpleMarkdown is true
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 85ba9f9 commit f0bd843

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/github/markdownUtils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,15 @@ export class PlainTextRenderer extends marked.Renderer {
287287
return content;
288288
}
289289
override strong(text: string): string {
290+
if (this.allowSimpleMarkdown) {
291+
return `**${text}**`;
292+
}
290293
return text;
291294
}
292295
override em(text: string): string {
296+
if (this.allowSimpleMarkdown) {
297+
return `*${text}*`;
298+
}
293299
return text;
294300
}
295301
override codespan(code: string): string {

src/test/github/markdownUtils.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,40 @@ suite('PlainTextRenderer', () => {
3131
const result = marked.parse('rename the `Foo` class to `Bar`', { renderer, smartypants: true });
3232
assert.strictEqual(result.trim(), 'rename the \\`Foo\\` class to \\`Bar\\`');
3333
});
34+
35+
test('should strip strong formatting by default', () => {
36+
const renderer = new PlainTextRenderer();
37+
const result = marked.parse('This is **bold** text', { renderer, smartypants: true });
38+
assert.strictEqual(result.trim(), 'This is bold text');
39+
});
40+
41+
test('should preserve strong formatting when allowSimpleMarkdown is true', () => {
42+
const renderer = new PlainTextRenderer(true);
43+
const result = marked.parse('This is **bold** text', { renderer, smartypants: true });
44+
assert.strictEqual(result.trim(), 'This is **bold** text');
45+
});
46+
47+
test('should strip em formatting by default', () => {
48+
const renderer = new PlainTextRenderer();
49+
const result = marked.parse('This is *italic* text', { renderer, smartypants: true });
50+
assert.strictEqual(result.trim(), 'This is italic text');
51+
});
52+
53+
test('should preserve em formatting when allowSimpleMarkdown is true', () => {
54+
const renderer = new PlainTextRenderer(true);
55+
const result = marked.parse('This is *italic* text', { renderer, smartypants: true });
56+
assert.strictEqual(result.trim(), 'This is *italic* text');
57+
});
58+
59+
test('should handle combined formatting when allowSimpleMarkdown is true', () => {
60+
const renderer = new PlainTextRenderer(true);
61+
const result = marked.parse('rename the `Foo` class to **`Bar`** and make it *italic*', { renderer, smartypants: true });
62+
assert.strictEqual(result.trim(), 'rename the `Foo` class to **`Bar`** and make it *italic*');
63+
});
64+
65+
test('should strip all formatting by default', () => {
66+
const renderer = new PlainTextRenderer(false);
67+
const result = marked.parse('rename the `Foo` class to **`Bar`** and make it *italic*', { renderer, smartypants: true });
68+
assert.strictEqual(result.trim(), 'rename the \\`Foo\\` class to \\`Bar\\` and make it italic');
69+
});
3470
});

0 commit comments

Comments
 (0)