Skip to content

Commit ef8101b

Browse files
authored
impl(docfx): support <verbatim> elements (#11294)
1 parent 835e6a2 commit ef8101b

3 files changed

Lines changed: 42 additions & 1 deletion

File tree

docfx/doxygen2markdown.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,8 @@ bool AppendIfDocCmdGroup(std::ostream& os, MarkdownContext const& ctx,
448448
if (AppendIfDocTitleCmdGroup(os, ctx, node)) return true;
449449
// Unexpected: hruler, preformatted
450450
if (AppendIfProgramListing(os, ctx, node)) return true;
451-
// Unexpected: verbatim, indexentry
451+
// Unexpected: indexentry
452+
if (AppendIfVerbatim(os, ctx, node)) return true;
452453
if (AppendIfOrderedList(os, ctx, node)) return true;
453454
if (AppendIfItemizedList(os, ctx, node)) return true;
454455
if (AppendIfSimpleSect(os, ctx, node)) return true;
@@ -508,6 +509,16 @@ bool AppendIfProgramListing(std::ostream& os, MarkdownContext const& ctx,
508509
return true;
509510
}
510511

512+
// The type for `verbatim` is a simple string.
513+
bool AppendIfVerbatim(std::ostream& os, MarkdownContext const& ctx,
514+
pugi::xml_node const& node) {
515+
if (std::string_view{node.name()} != "verbatim") return false;
516+
os << ctx.paragraph_start << ctx.paragraph_indent << "```\n"
517+
<< ctx.paragraph_indent << node.child_value() << "\n"
518+
<< ctx.paragraph_indent << "```";
519+
return true;
520+
}
521+
511522
// The type for `codeline` is basically a sequence of highlights (think "syntax
512523
// highlighting", not "important things"). We will discard this information and
513524
// rely in the target markdown to generate the right coloring.

docfx/doxygen2markdown.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ bool AppendIfParagraph(std::ostream& os, MarkdownContext const& ctx,
133133
bool AppendIfProgramListing(std::ostream& os, MarkdownContext const& ctx,
134134
pugi::xml_node const& node);
135135

136+
/// Handle `verbatim` elements.
137+
bool AppendIfVerbatim(std::ostream& os, MarkdownContext const& ctx,
138+
pugi::xml_node const& node);
139+
136140
/// Handle `codeline` elements.
137141
bool AppendIfCodeline(std::ostream& os, MarkdownContext const& ctx,
138142
pugi::xml_node const& node);

docfx/doxygen2markdown_test.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,32 @@ for (StatusOr<int> const& v : sr) {
633633
EXPECT_EQ(kExpected, os.str());
634634
}
635635

636+
TEST(Doxygen2Markdown, ParagraphVerbatim) {
637+
auto constexpr kXml = R"xml(<?xml version="1.0" standalone="yes"?>
638+
<doxygen version="1.9.1" xml:lang="en-US">
639+
<para id='test-node'>
640+
<verbatim>https://cloud.google.com/storage/docs/transcoding
641+
</verbatim>
642+
</para>
643+
</doxygen>)xml";
644+
645+
auto constexpr kExpected = R"md(
646+
647+
648+
649+
```
650+
https://cloud.google.com/storage/docs/transcoding
651+
652+
```)md";
653+
654+
pugi::xml_document doc;
655+
doc.load_string(kXml);
656+
auto selected = doc.select_node("//*[@id='test-node']");
657+
std::ostringstream os;
658+
ASSERT_TRUE(AppendIfParagraph(os, {}, selected.node()));
659+
EXPECT_EQ(kExpected, os.str());
660+
}
661+
636662
TEST(Doxygen2Markdown, ParagraphXrefSect) {
637663
auto constexpr kXml = R"xml(<?xml version="1.0" standalone="yes"?>
638664
<doxygen version="1.9.1" xml:lang="en-US">

0 commit comments

Comments
 (0)