Skip to content

Commit

Permalink
render orphan @Par headings
Browse files Browse the repository at this point in the history
Render @Par headings when the @Par has no children paragraphs

#feat

fix #787
  • Loading branch information
alandefreitas committed Jan 13, 2025
1 parent 521c37d commit b9d403f
Show file tree
Hide file tree
Showing 8 changed files with 452 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/lib/AST/ParseJavadoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1233,24 +1233,26 @@ visitBlockCommandComment(
doc::Paragraph paragraph;
auto scope = enterScope(paragraph);
visitChildren(C->getParagraph());
if(! paragraph.children.empty())
if (C->getNumArgs() > 0)
{
if (C->getNumArgs() > 0)
{
jd_.emplace_back(doc::Heading(C->getArgText(0).str()));
}
else
jd_.emplace_back(doc::Heading(C->getArgText(0).str()));
}
if (!paragraph.children.empty())
{
// the first TextComment is the heading text
if (C->getNumArgs() == 0)
{
// the first TextComment is the heading text
doc::String text(std::move(
paragraph.children.front()->string));

// VFALCO Unfortunately clang puts at least
// one space in front of the text, which seems
// incorrect.
auto const s = trim(text);
if(s.size() != text.size())
if (auto const s = trim(text);
s.size() != text.size())
{
text = s;
}

doc::Heading heading(std::move(text));
jd_.emplace_back(std::move(heading));
Expand All @@ -1259,8 +1261,10 @@ visitBlockCommandComment(
paragraph.children.erase(paragraph.children.begin());
}

if(! paragraph.children.empty())
if (!paragraph.children.empty())
{
jd_.emplace_back(std::move(paragraph));
}
}
return;
}
Expand Down
166 changes: 166 additions & 0 deletions test-files/golden-tests/javadoc/par-1.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
= Reference
:mrdocs:

[#index]
== Global namespace


=== Functions

[cols=2]
|===
| Name | Description

| <<f1,`f1`>>
| Brief



| <<f2,`f2`>>
| Brief



| <<f3,`f3`>>
| Brief



| <<f4,`f4`>>
| Brief



|===

[#f1]
== f1


Brief



=== Synopsis


Declared in `&lt;par&hyphen;1&period;cpp&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
void
f1();
----

=== Description



=== Custom par

Paragraph 1

[,cpp]
----
void f1();
----


[#f2]
== f2


Brief



=== Synopsis


Declared in `&lt;par&hyphen;1&period;cpp&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
void
f2();
----

=== Description



=== Custom par

Paragraph 2

[,cpp]
----
void f2();
----


[#f3]
== f3


Brief



=== Synopsis


Declared in `&lt;par&hyphen;1&period;cpp&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
void
f3();
----

=== Description



=== Custom par

[,cpp]
----
void f3();
----


[#f4]
== f4


Brief



=== Synopsis


Declared in `&lt;par&hyphen;1&period;cpp&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
void
f4();
----

=== Description



=== Custom par

[,cpp]
----
void f4();
----




[.small]#Created with https://www.mrdocs.com[MrDocs]#
43 changes: 43 additions & 0 deletions test-files/golden-tests/javadoc/par-1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/** Brief
@par Custom par
Paragraph 1
@code
void f1();
@endcode
*/
void f1();

/** Brief
@par Custom par
Paragraph 2
@code
void f2();
@endcode
*/
void f2();

/** Brief
@par Custom par
@code
void f3();
@endcode
*/
void f3();

/** Brief
@par Custom par
@code
void f4();
@endcode
*/
void f4();
Loading

0 comments on commit b9d403f

Please sign in to comment.