From 0804dd53364107001f31948a9ec9fe331bc92a4a Mon Sep 17 00:00:00 2001 From: Zher Huei Lee Date: Wed, 11 Oct 2017 16:27:54 +0800 Subject: Added String::dedent() to remove text indentation This functions similarly to Python's textwrap.dedent() It's also been applied to doc_data.cpp to remove extra whitespace while parsing the XML. --- editor/doc/doc_data.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'editor') diff --git a/editor/doc/doc_data.cpp b/editor/doc/doc_data.cpp index d35dc53ae1..057b2d827d 100644 --- a/editor/doc/doc_data.cpp +++ b/editor/doc/doc_data.cpp @@ -615,6 +615,11 @@ void DocData::generate(bool p_basic_types) { } } +static String _format_description(const String &string) { + + return string.dedent().strip_edges().replace("\n", "\n\n"); +} + static Error _parse_methods(Ref &parser, Vector &methods) { String section = parser->get_node_name(); @@ -661,7 +666,7 @@ static Error _parse_methods(Ref &parser, Vector & parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) - method.description = parser->get_node_data().strip_edges(); + method.description = _format_description(parser->get_node_data()); } } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == element) @@ -776,12 +781,12 @@ Error DocData::_load(Ref parser) { parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) - c.brief_description = parser->get_node_data().strip_edges(); + c.brief_description = _format_description(parser->get_node_data()); } else if (name == "description") { parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) - c.description = parser->get_node_data().strip_edges(); + c.description = _format_description(parser->get_node_data()); } else if (name == "tutorials") { parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) @@ -823,7 +828,7 @@ Error DocData::_load(Ref parser) { prop.enumeration = parser->get_attribute_value("enum"); parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) - prop.description = parser->get_node_data().strip_edges(); + prop.description = _format_description(parser->get_node_data()); c.properties.push_back(prop); } else { ERR_EXPLAIN("Invalid tag in doc file: " + name); -- cgit v1.2.3