Skip to content

Commit 2984b09

Browse files
authored
impl(docfx): support sect{2,3,4} in description (#10971)
1 parent 591ab01 commit 2984b09

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

docfx/doxygen2markdown.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ bool AppendIfDetailedDescription(std::ostream& os, MarkdownContext const& ctx,
181181
// Unexpected: title, internal -> we do not use this...
182182
if (AppendIfParagraph(os, ctx, child)) continue;
183183
if (AppendIfSect1(os, ctx, child)) continue;
184+
// While the XML schema does not allow for `sect2`, `sect3`, or `sect4`
185+
// elements, in practice Doxygen does generate them. And we use them in at
186+
// least one page.
187+
if (AppendIfSect2(os, ctx, child)) continue;
188+
if (AppendIfSect3(os, ctx, child)) continue;
189+
if (AppendIfSect4(os, ctx, child)) continue;
184190
UnknownChildType(__func__, child);
185191
}
186192
return true;

docfx/doxygen2markdown_test.cc

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,100 @@ Sect2 paragraph.)md";
140140
EXPECT_EQ(kExpected, os.str());
141141
}
142142

143+
TEST(Doxygen2Markdown, DetailedDescription) {
144+
auto constexpr kXml = R"xml(<?xml version="1.0" standalone="yes"?>
145+
<doxygen version="1.9.1" xml:lang="en-US">
146+
<detaileddescription id='tested-node'>
147+
<sect1>
148+
<title>This is the title (1)</title>
149+
<para>First paragraph (1).</para>
150+
<para>Second paragraph (1).</para>
151+
<sect2><title>This is a section2</title><para>Sect2 paragraph.</para></sect2>
152+
</sect1>
153+
<sect1>
154+
<title>This is the title (2)</title>
155+
<para>First paragraph (2).</para>
156+
<para>Second paragraph (2).</para>
157+
</sect1>
158+
</detaileddescription>
159+
</doxygen>)xml";
160+
161+
auto constexpr kExpected = R"md(
162+
163+
## This is the title (1)
164+
165+
First paragraph (1).
166+
167+
Second paragraph (1).
168+
169+
### This is a section2
170+
171+
Sect2 paragraph.
172+
173+
## This is the title (2)
174+
175+
First paragraph (2).
176+
177+
Second paragraph (2).)md";
178+
pugi::xml_document doc;
179+
doc.load_string(kXml);
180+
auto selected = doc.select_node("//*[@id='tested-node']");
181+
ASSERT_TRUE(selected);
182+
std::ostringstream os;
183+
ASSERT_TRUE(AppendIfDetailedDescription(os, {}, selected.node()));
184+
EXPECT_EQ(kExpected, os.str());
185+
}
186+
187+
TEST(Doxygen2Markdown, DetailedDescriptionSkipSect1) {
188+
auto constexpr kXml = R"xml(<?xml version="1.0" standalone="yes"?>
189+
<doxygen version="1.9.1" xml:lang="en-US">
190+
<detaileddescription id='tested-node'>
191+
<sect2>
192+
<title>This is the title (2)</title>
193+
<para>First paragraph (2).</para>
194+
<para>Second paragraph (2).</para>
195+
</sect2>
196+
<sect3>
197+
<title>This is the title (3)</title>
198+
<para>First paragraph (3).</para>
199+
<para>Second paragraph (3).</para>
200+
</sect3>
201+
<sect4>
202+
<title>This is the title (4)</title>
203+
<para>First paragraph (4).</para>
204+
<para>Second paragraph (4).</para>
205+
</sect4>
206+
</detaileddescription>
207+
</doxygen>)xml";
208+
209+
auto constexpr kExpected = R"md(
210+
211+
### This is the title (2)
212+
213+
First paragraph (2).
214+
215+
Second paragraph (2).
216+
217+
#### This is the title (3)
218+
219+
First paragraph (3).
220+
221+
Second paragraph (3).
222+
223+
##### This is the title (4)
224+
225+
First paragraph (4).
226+
227+
Second paragraph (4).)md";
228+
pugi::xml_document doc;
229+
doc.load_string(kXml);
230+
auto selected = doc.select_node("//*[@id='tested-node']");
231+
ASSERT_TRUE(selected);
232+
std::ostringstream os;
233+
ASSERT_TRUE(AppendIfDetailedDescription(os, {}, selected.node()));
234+
EXPECT_EQ(kExpected, os.str());
235+
}
236+
143237
TEST(Doxygen2Markdown, PlainText) {
144238
pugi::xml_document doc;
145239
doc.load_string(R"xml(<?xml version="1.0" standalone="yes"?>

0 commit comments

Comments
 (0)