efl-mono: Allow doc XML tags to be nested

Summary:
This allows inserting nested tags like:
<example><code>bla bla bla</code></example>

The generate_tag_example() is currently unused but serves as an example.

Depends on D8585

Test Plan:
Not much, unless you want to manually call generate_tag_example()
(Which I have done, and it works, I promise).

Reviewers: lauromoura, vitor.sousa

Reviewed By: vitor.sousa

Subscribers: vitor.sousa, cedric, #reviewers, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D8587
This commit is contained in:
Xavi Artigas 2019-04-11 10:37:33 +02:00 committed by Mike Blumenkrantz
parent dcab92b703
commit e8edd7710e
1 changed files with 37 additions and 3 deletions

View File

@ -244,7 +244,19 @@ struct documentation_generator
/// Tag generator helpers
template<typename OutputIterator, typename Context>
bool generate_tag(OutputIterator sink, std::string const& tag, std::string const &text, Context const& context, std::string tag_params = "") const
bool generate_opening_tag(OutputIterator sink, std::string const& tag, Context const& context, std::string tag_params = "") const
{
return as_generator("<" << tag << tag_params << ">").generate(sink, attributes::unused, context);
}
template<typename OutputIterator, typename Context>
bool generate_closing_tag(OutputIterator sink, std::string const& tag, Context const& context) const
{
return as_generator("</" << tag << ">").generate(sink, attributes::unused, context);
}
template<typename OutputIterator, typename Context>
bool generate_escaped_content(OutputIterator sink, std::string const &text, Context const& context) const
{
std::string new_text;
if (!as_generator(html_escaped_string).generate(std::back_inserter(new_text), text, context))
@ -256,14 +268,24 @@ struct documentation_generator
std::istringstream ss(new_text);
std::string para;
std::string final_text = "<" + tag + tag_params + ">";
std::string final_text;
bool first = true;
while (std::getline(ss, para)) {
if (first) final_text += para;
else final_text += "\n" + tabs + para;
first = false;
}
return as_generator(scope_tab(scope_size) << "/// " << final_text << "</" << tag << ">\n").generate(sink, attributes::unused, context);
return as_generator(final_text).generate(sink, attributes::unused, context);
}
template<typename OutputIterator, typename Context>
bool generate_tag(OutputIterator sink, std::string const& tag, std::string const &text, Context const& context, std::string tag_params = "") const
{
if (!as_generator(scope_tab(scope_size) << "/// ").generate(sink, attributes::unused, context)) return false;
if (!generate_opening_tag(sink, tag, context, tag_params)) return false;
if (!generate_escaped_content(sink, text, context)) return false;
if (!generate_closing_tag(sink, tag, context)) return false;
return as_generator("\n").generate(sink, attributes::unused, context);
}
template<typename OutputIterator, typename Context>
@ -290,6 +312,18 @@ struct documentation_generator
return generate_tag(sink, "value", text, context);
}
template<typename OutputIterator, typename Context>
bool generate_tag_example(OutputIterator sink, std::string const& example, Context const& context) const
{
if (!as_generator(scope_tab(scope_size) << "/// ").generate(sink, attributes::unused, context)) return false;
if (!generate_opening_tag(sink, "example", context)) return false;
if (!generate_opening_tag(sink, "code", context)) return false;
if (!generate_escaped_content(sink, example, context)) return false;
if (!generate_closing_tag(sink, "code", context)) return false;
if (!generate_closing_tag(sink, "example", context)) return false;
return as_generator("\n").generate(sink, attributes::unused, context);
}
// Actual exported generators
template<typename OutputIterator, typename Attribute, typename Context>
bool generate(OutputIterator sink, Attribute const& attr, Context const& context) const