[PATCH] D65005: [clang-doc] Fix output format of html

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL367050: [clang-doc] Fix output format of html (authored by 
DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65005?vs=211812&id=211814#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65005/new/

https://reviews.llvm.org/D65005

Files:
  clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/trunk/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
   
-private int X
+
+  private 
+  int
+   X
+
   
   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: &, <, >, ", '.
 
   
 
Index: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/trunk/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 re

[PATCH] D65005: [clang-doc] Fix output format of html

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 211812.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65005/new/

https://reviews.llvm.org/D65005

Files:
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

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
   
-private int X
+
+  private 
+  int
+   X
+
   
   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: &, <, >, ", '.
 
   
 
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() << "=\"" << 

[PATCH] D65005: [clang-doc] Fix output format of html

2019-07-19 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added reviewers: juliehockett, jakehehrlich, lebedev.ri.
DiegoAstiazaran added a project: clang-tools-extra.

The children of a TagNode are rendered in the same line as the parent only if 
they are all TextNodes.
When children are not inline; two text nodes that are adjacent won't have a new 
line between them, each tag node is rendered in its own line.


https://reviews.llvm.org/D65005

Files:
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

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
   
-private int X
+
+  private 
+  int
+   X
+
   
   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";
 
@@ -271,20 +265,12 @@
 
 
   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.
-  
+   Brief description.
+   Extended description that continues onto the next line.
 
   
 
Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -43,9 +43,6 @@
   operator bool() = delete;
 
   bool IsSelfClosing() const;
-
-  bool HasInlineChildren() const;
-
   llvm::SmallString<16> ToString() const;
 
 private:
@@ -66,29 +63,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
@@ -129,24 +117,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:
@@ -174,17 +144,23 @@
 }
 
 void TextNode::Render(llvm::raw_ostream &OS, int IndentationLevel) {
-  if (Indented)
-OS.indent(IndentationLevel * 2);
+  OS.indent(IndentationLevel * 2);
   OS << Text;
 }
 
 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;
+  bre