[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
This commit is contained in:
Kadir Cetinkaya 2020-01-09 17:56:30 +01:00
parent ffd0f11675
commit abfa27e4f0
No known key found for this signature in database
GPG Key ID: E39E36B8D2057ED6
2 changed files with 12 additions and 11 deletions

View File

@ -196,7 +196,8 @@ void Paragraph::renderMarkdown(llvm::raw_ostream &OS) const {
}
// Paragraphs are translated into markdown lines, not markdown paragraphs.
// Therefore it only has a single linebreak afterwards.
OS << '\n';
// VSCode requires two spaces at the end of line to start a new one.
OS << " \n";
}
void Paragraph::renderPlainText(llvm::raw_ostream &OS) const {

View File

@ -121,7 +121,7 @@ TEST(Document, Separators) {
D.addCodeBlock("test");
D.addParagraph().appendText("bar");
const char ExpectedMarkdown[] = R"md(foo
const char ExpectedMarkdown[] = R"md(foo
```cpp
test
```
@ -141,7 +141,7 @@ TEST(Document, Spacer) {
D.addParagraph().appendText("foo");
D.addSpacer();
D.addParagraph().appendText("bar");
EXPECT_EQ(D.asMarkdown(), "foo\n\nbar");
EXPECT_EQ(D.asMarkdown(), "foo \n\nbar");
EXPECT_EQ(D.asPlainText(), "foo\n\nbar");
}
@ -217,10 +217,10 @@ TEST(BulletList, Render) {
DeepDoc.addParagraph().appendText("baz");
EXPECT_EQ(L.asMarkdown(), R"md(- foo
- bar
- foo
baz
- foo
- baz
- foo
baz
- foo
- baz
baz)md");
EXPECT_EQ(L.asPlainText(), R"pt(- foo
- bar
@ -234,10 +234,10 @@ TEST(BulletList, Render) {
Inner.addParagraph().appendText("after");
EXPECT_EQ(L.asMarkdown(), R"md(- foo
- bar
- foo
baz
- foo
- baz
- foo
baz
- foo
- baz
baz
after)md");