From 34f4ae18b8d2b1cf9b56a8c3ac1a93d5190a3aae Mon Sep 17 00:00:00 2001 From: Zher Huei Lee Date: Sat, 11 Nov 2017 09:11:24 +0800 Subject: Moved doc description formatting. Fixes #12798 Paragraph spacing is now applied only during rendering (so doctool preserves formatting). Paragraph spacing now no longer applies within [code] tags. Extra bbcode is now ignored within [code] tags. --- editor/doc/doc_data.cpp | 47 ++++++++++++++++++----------------------------- editor/editor_help.cpp | 24 ++++++++++++++++++------ 2 files changed, 36 insertions(+), 35 deletions(-) (limited to 'editor') diff --git a/editor/doc/doc_data.cpp b/editor/doc/doc_data.cpp index 057b2d827d..533ed48d15 100644 --- a/editor/doc/doc_data.cpp +++ b/editor/doc/doc_data.cpp @@ -615,11 +615,6 @@ 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(); @@ -666,7 +661,7 @@ static Error _parse_methods(Ref &parser, Vector & parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) - method.description = _format_description(parser->get_node_data()); + method.description = parser->get_node_data(); } } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == element) @@ -781,20 +776,20 @@ Error DocData::_load(Ref parser) { parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) - c.brief_description = _format_description(parser->get_node_data()); + c.brief_description = parser->get_node_data(); } else if (name == "description") { parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) - c.description = _format_description(parser->get_node_data()); + c.description = parser->get_node_data(); } else if (name == "tutorials") { parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) - c.tutorials = parser->get_node_data().strip_edges(); + c.tutorials = parser->get_node_data(); } else if (name == "demos") { parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) - c.demos = parser->get_node_data().strip_edges(); + c.demos = parser->get_node_data(); } else if (name == "methods") { Error err = _parse_methods(parser, c.methods); @@ -828,7 +823,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 = _format_description(parser->get_node_data()); + prop.description = parser->get_node_data(); c.properties.push_back(prop); } else { ERR_EXPLAIN("Invalid tag in doc file: " + name); @@ -857,7 +852,7 @@ Error DocData::_load(Ref parser) { prop.type = parser->get_attribute_value("type"); parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) - prop.description = parser->get_node_data().strip_edges(); + prop.description = parser->get_node_data(); c.theme_properties.push_back(prop); } else { ERR_EXPLAIN("Invalid tag in doc file: " + name); @@ -888,7 +883,7 @@ Error DocData::_load(Ref parser) { } parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) - constant.description = parser->get_node_data().strip_edges(); + constant.description = parser->get_node_data(); c.constants.push_back(constant); } else { ERR_EXPLAIN("Invalid tag in doc file: " + name); @@ -915,6 +910,8 @@ Error DocData::_load(Ref parser) { static void _write_string(FileAccess *f, int p_tablevel, const String &p_string) { + if (p_string == "") + return; String tab; for (int i = 0; i < p_tablevel; i++) tab += "\t"; @@ -957,20 +954,16 @@ Error DocData::save_classes(const String &p_default_path, const Map"); - if (c.brief_description != "") - _write_string(f, 2, c.brief_description.xml_escape()); + _write_string(f, 2, c.brief_description.strip_edges().xml_escape()); _write_string(f, 1, ""); _write_string(f, 1, ""); - if (c.description != "") - _write_string(f, 2, c.description.xml_escape()); + _write_string(f, 2, c.description.strip_edges().xml_escape()); _write_string(f, 1, ""); _write_string(f, 1, ""); - if (c.tutorials != "") - _write_string(f, 2, c.tutorials.xml_escape()); + _write_string(f, 2, c.tutorials.strip_edges().xml_escape()); _write_string(f, 1, ""); _write_string(f, 1, ""); - if (c.demos != "") - _write_string(f, 2, c.demos.xml_escape()); + _write_string(f, 2, c.demos.strip_edges().xml_escape()); _write_string(f, 1, ""); _write_string(f, 1, ""); @@ -1014,8 +1007,7 @@ Error DocData::save_classes(const String &p_default_path, const Map"); - if (m.description != "") - _write_string(f, 4, m.description.xml_escape()); + _write_string(f, 4, m.description.strip_edges().xml_escape()); _write_string(f, 3, ""); _write_string(f, 2, ""); @@ -1036,8 +1028,7 @@ Error DocData::save_classes(const String &p_default_path, const Map"); - if (p.description != "") - _write_string(f, 3, p.description.xml_escape()); + _write_string(f, 3, p.description.strip_edges().xml_escape()); _write_string(f, 2, ""); } _write_string(f, 1, ""); @@ -1060,8 +1051,7 @@ Error DocData::save_classes(const String &p_default_path, const Map"); - if (m.description != "") - _write_string(f, 4, m.description.xml_escape()); + _write_string(f, 4, m.description.strip_edges().xml_escape()); _write_string(f, 3, ""); _write_string(f, 2, ""); @@ -1080,8 +1070,7 @@ Error DocData::save_classes(const String &p_default_path, const Map"); } - if (k.description != "") - _write_string(f, 3, k.description.xml_escape()); + _write_string(f, 3, k.description.strip_edges().xml_escape()); _write_string(f, 2, ""); } diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index 03cd2c9b6b..bdb621a258 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -1478,9 +1478,10 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) { Color font_color_hl = p_rt->get_color("headline_color", "EditorHelp"); Color link_color = p_rt->get_color("accent_color", "Editor").linear_interpolate(font_color_hl, 0.8); - String bbcode = p_bbcode.replace("\t", " ").replace("\r", " ").strip_edges(); + String bbcode = p_bbcode.dedent().replace("\t", "").replace("\r", "").strip_edges(); List tag_stack; + bool code_tag = false; int pos = 0; while (pos < bbcode.length()) { @@ -1491,7 +1492,10 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) { brk_pos = bbcode.length(); if (brk_pos > pos) { - p_rt->add_text(bbcode.substr(pos, brk_pos - pos)); + String text = bbcode.substr(pos, brk_pos - pos); + if (!code_tag) + text = text.replace("\n", "\n\n"); + p_rt->add_text(text); } if (brk_pos == bbcode.length()) @@ -1500,7 +1504,11 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) { int brk_end = bbcode.find("]", brk_pos + 1); if (brk_end == -1) { - p_rt->add_text(bbcode.substr(brk_pos, bbcode.length() - brk_pos)); + + String text = bbcode.substr(brk_pos, bbcode.length() - brk_pos); + if (!code_tag) + text = text.replace("\n", "\n\n"); + p_rt->add_text(text); break; } @@ -1509,20 +1517,23 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) { if (tag.begins_with("/")) { bool tag_ok = tag_stack.size() && tag_stack.front()->get() == tag.substr(1, tag.length()); - if (tag_stack.size()) { - } if (!tag_ok) { p_rt->add_text("["); - pos++; + pos = brk_pos + 1; continue; } tag_stack.pop_front(); pos = brk_end + 1; + code_tag = false; if (tag != "/img") p_rt->pop(); + } else if (code_tag) { + + p_rt->add_text("["); + pos = brk_pos + 1; } else if (tag.begins_with("method ")) { @@ -1559,6 +1570,7 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) { //use monospace font p_rt->push_font(doc_code_font); + code_tag = true; pos = brk_end + 1; tag_stack.push_front(tag); } else if (tag == "center") { -- cgit v1.2.3