Merge pull request #12860 from leezh/doc_fix

Moved doc description formatting. Fixes #12798
This commit is contained in:
Rémi Verschelde 2017-11-12 21:14:07 +01:00 committed by GitHub
commit dd55cc7879
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 35 deletions

View file

@ -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<XMLParser> &parser, Vector<DocData::MethodDoc> &methods) {
String section = parser->get_node_name();
@ -666,7 +661,7 @@ static Error _parse_methods(Ref<XMLParser> &parser, Vector<DocData::MethodDoc> &
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<XMLParser> 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<XMLParser> 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<XMLParser> 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<XMLParser> 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<XMLParser> 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<String, Stri
header += ">";
_write_string(f, 0, header);
_write_string(f, 1, "<brief_description>");
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, "</brief_description>");
_write_string(f, 1, "<description>");
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, "</description>");
_write_string(f, 1, "<tutorials>");
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, "</tutorials>");
_write_string(f, 1, "<demos>");
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, "</demos>");
_write_string(f, 1, "<methods>");
@ -1014,8 +1007,7 @@ Error DocData::save_classes(const String &p_default_path, const Map<String, Stri
}
_write_string(f, 3, "<description>");
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, "</description>");
_write_string(f, 2, "</method>");
@ -1036,8 +1028,7 @@ Error DocData::save_classes(const String &p_default_path, const Map<String, Stri
}
PropertyDoc &p = c.properties[i];
_write_string(f, 2, "<member name=\"" + p.name + "\" type=\"" + p.type + "\" setter=\"" + p.setter + "\" getter=\"" + p.getter + "\"" + enum_text + ">");
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, "</member>");
}
_write_string(f, 1, "</members>");
@ -1060,8 +1051,7 @@ Error DocData::save_classes(const String &p_default_path, const Map<String, Stri
}
_write_string(f, 3, "<description>");
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, "</description>");
_write_string(f, 2, "</signal>");
@ -1080,8 +1070,7 @@ Error DocData::save_classes(const String &p_default_path, const Map<String, Stri
} else {
_write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"" + k.value + "\" enum=\"" + k.enumeration + "\">");
}
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, "</constant>");
}

View file

@ -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<String> 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") {