Skip to content

Commit abfa27e

Browse files
committed
[clangd] Fix markdown rendering in VSCode
Summary: Eventough it is OK to have a new line without any preceding spaces in some markdown specifications, VSCode requires two spaces before a new line to break a line inside a paragraph. Reviewers: sammccall, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D72462
1 parent ffd0f11 commit abfa27e

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

clang-tools-extra/clangd/FormattedString.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ void Paragraph::renderMarkdown(llvm::raw_ostream &OS) const {
196196
}
197197
// Paragraphs are translated into markdown lines, not markdown paragraphs.
198198
// Therefore it only has a single linebreak afterwards.
199-
OS << '\n';
199+
// VSCode requires two spaces at the end of line to start a new one.
200+
OS << " \n";
200201
}
201202

202203
void Paragraph::renderPlainText(llvm::raw_ostream &OS) const {

clang-tools-extra/clangd/unittests/FormattedStringTests.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ TEST(Document, Separators) {
121121
D.addCodeBlock("test");
122122
D.addParagraph().appendText("bar");
123123

124-
const char ExpectedMarkdown[] = R"md(foo
124+
const char ExpectedMarkdown[] = R"md(foo
125125
```cpp
126126
test
127127
```
@@ -141,7 +141,7 @@ TEST(Document, Spacer) {
141141
D.addParagraph().appendText("foo");
142142
D.addSpacer();
143143
D.addParagraph().appendText("bar");
144-
EXPECT_EQ(D.asMarkdown(), "foo\n\nbar");
144+
EXPECT_EQ(D.asMarkdown(), "foo \n\nbar");
145145
EXPECT_EQ(D.asPlainText(), "foo\n\nbar");
146146
}
147147

@@ -217,10 +217,10 @@ TEST(BulletList, Render) {
217217
DeepDoc.addParagraph().appendText("baz");
218218
EXPECT_EQ(L.asMarkdown(), R"md(- foo
219219
- bar
220-
- foo
221-
baz
222-
- foo
223-
- baz
220+
- foo
221+
baz
222+
- foo
223+
- baz
224224
baz)md");
225225
EXPECT_EQ(L.asPlainText(), R"pt(- foo
226226
- bar
@@ -234,10 +234,10 @@ TEST(BulletList, Render) {
234234
Inner.addParagraph().appendText("after");
235235
EXPECT_EQ(L.asMarkdown(), R"md(- foo
236236
- bar
237-
- foo
238-
baz
239-
- foo
240-
- baz
237+
- foo
238+
baz
239+
- foo
240+
- baz
241241
baz
242242
243243
after)md");

0 commit comments

Comments
 (0)