Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp =================================================================== --- clang-tools-extra/clang-doc/HTMLGenerator.cpp +++ clang-tools-extra/clang-doc/HTMLGenerator.cpp @@ -44,9 +44,6 @@ operator bool() = delete; bool IsSelfClosing() const; - - bool HasInlineChildren() const; - llvm::SmallString<16> ToString() const; private: @@ -67,29 +64,20 @@ }; struct TextNode : public HTMLNode { - TextNode(const Twine &Text, bool Indented = true) - : HTMLNode(NodeType::NODE_TEXT), Text(Text.str()), Indented(Indented) {} + TextNode(const Twine &Text) + : HTMLNode(NodeType::NODE_TEXT), Text(Text.str()) {} std::string Text; // Content of node - bool Indented; // Indicates if an indentation must be rendered before the text void Render(llvm::raw_ostream &OS, int IndentationLevel) override; }; struct TagNode : public HTMLNode { - TagNode(HTMLTag Tag) - : HTMLNode(NodeType::NODE_TAG), Tag(Tag), - InlineChildren(Tag.HasInlineChildren()), - SelfClosing(Tag.IsSelfClosing()) {} + TagNode(HTMLTag Tag) : HTMLNode(NodeType::NODE_TAG), Tag(Tag) {} TagNode(HTMLTag Tag, const Twine &Text) : TagNode(Tag) { - Children.emplace_back( - llvm::make_unique(Text.str(), !InlineChildren)); + Children.emplace_back(llvm::make_unique(Text.str())); } - HTMLTag Tag; // Name of HTML Tag (p, div, h1) - bool InlineChildren; // Indicates if children nodes are rendered in the same - // line as itself or if children must rendered in the - // next line and with additional indentation - bool SelfClosing; // Indicates if tag is self-closing + HTMLTag Tag; // Name of HTML Tag (p, div, h1) std::vector> Children; // List of child nodes llvm::StringMap> Attributes; // List of key-value attributes for tag @@ -130,24 +118,6 @@ llvm_unreachable("Unhandled HTMLTag::TagType"); } -bool HTMLTag::HasInlineChildren() const { - switch (Value) { - case HTMLTag::TAG_META: - case HTMLTag::TAG_TITLE: - case HTMLTag::TAG_H1: - case HTMLTag::TAG_H2: - case HTMLTag::TAG_H3: - case HTMLTag::TAG_LI: - case HTMLTag::TAG_A: - return true; - case HTMLTag::TAG_DIV: - case HTMLTag::TAG_P: - case HTMLTag::TAG_UL: - return false; - } - llvm_unreachable("Unhandled HTMLTag::TagType"); -} - llvm::SmallString<16> HTMLTag::ToString() const { switch (Value) { case HTMLTag::TAG_META: @@ -175,17 +145,23 @@ } void TextNode::Render(llvm::raw_ostream &OS, int IndentationLevel) { - if (Indented) - OS.indent(IndentationLevel * 2); + OS.indent(IndentationLevel * 2); printHTMLEscaped(Text, OS); } void TagNode::Render(llvm::raw_ostream &OS, int IndentationLevel) { + // Children nodes are rendered in the same line if all of them are text nodes + bool InlineChildren = true; + for (const auto &C : Children) + if (C->Type == NodeType::NODE_TAG) { + InlineChildren = false; + break; + } OS.indent(IndentationLevel * 2); OS << "<" << Tag.ToString(); for (const auto &A : Attributes) OS << " " << A.getKey() << "=\"" << A.getValue() << "\""; - if (SelfClosing) { + if (Tag.IsSelfClosing()) { OS << "/>"; return; } @@ -385,7 +361,7 @@ } else if (I.Kind == "TextComment") { if (I.Text == "") return nullptr; - return llvm::make_unique(I.Text, true); + return llvm::make_unique(I.Text); } return nullptr; } Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp =================================================================== --- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp +++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp @@ -56,9 +56,7 @@

Functions

OneFunction

-

- OneFunction() -

+

OneFunction()

Enums

@@ -107,9 +105,7 @@ class r

class r

-

- Defined at line 10 of test.cpp -

+

Defined at line 10 of test.cpp

Inherits from

Members

Records

    @@ -128,9 +128,7 @@

    Functions

    OneFunction

    -

    - OneFunction() -

    +

    OneFunction()

    Enums

    @@ -180,9 +178,7 @@ R"raw(">int P)

    -

    - Defined at line 10 of test.cpp -

    +

    Defined at line 10 of test.cpp

    )raw"; @@ -214,9 +210,7 @@
    • X
    -

    - Defined at line 10 of test.cpp -

    +

    Defined at line 10 of test.cpp

)raw"; @@ -280,23 +274,13 @@

f

-

- void f(int I, int J) -

-

- Defined at line 10 of test.cpp -

+

void f(int I, int J)

+

Defined at line 10 of test.cpp

-

- Brief description. -

-

- Extended description that continues onto the next line. -

-

- Comment with html entities: &, <, >, ", '. -

+

Brief description.

+

Extended description that continues onto the next line.

+

Comment with html entities: &, <, >, ", '.