You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-13 13:31:48 +00:00
Replace XML codeblock spaces with tabs
This commit is contained in:
@@ -229,7 +229,6 @@
|
|||||||
func _process(delta):
|
func _process(delta):
|
||||||
basis = basis.rotated(Vector3.UP, TAU * delta)
|
basis = basis.rotated(Vector3.UP, TAU * delta)
|
||||||
basis = basis.rotated(Vector3.RIGHT, TAU * delta)
|
basis = basis.rotated(Vector3.RIGHT, TAU * delta)
|
||||||
|
|
||||||
basis = basis.orthonormalized()
|
basis = basis.orthonormalized()
|
||||||
[/gdscript]
|
[/gdscript]
|
||||||
[csharp]
|
[csharp]
|
||||||
|
|||||||
@@ -2101,7 +2101,7 @@
|
|||||||
rd = RenderingServer.get_rendering_device()
|
rd = RenderingServer.get_rendering_device()
|
||||||
|
|
||||||
if rd.has_feature(RenderingDevice.SUPPORTS_BUFFER_DEVICE_ADDRESS):
|
if rd.has_feature(RenderingDevice.SUPPORTS_BUFFER_DEVICE_ADDRESS):
|
||||||
storage_buffer = rd.storage_buffer_create(bytes.size(), bytes, RenderingDevice.STORAGE_BUFFER_USAGE_SHADER_DEVICE_ADDRESS):
|
storage_buffer = rd.storage_buffer_create(bytes.size(), bytes, RenderingDevice.STORAGE_BUFFER_USAGE_SHADER_DEVICE_ADDRESS)
|
||||||
storage_buffer_address = rd.buffer_get_device_address(storage_buffer)
|
storage_buffer_address = rd.buffer_get_device_address(storage_buffer)
|
||||||
[/gdscript]
|
[/gdscript]
|
||||||
[/codeblocks]
|
[/codeblocks]
|
||||||
|
|||||||
@@ -1840,41 +1840,10 @@ def format_text_block(
|
|||||||
context: DefinitionBase,
|
context: DefinitionBase,
|
||||||
state: State,
|
state: State,
|
||||||
) -> str:
|
) -> str:
|
||||||
# Linebreak + tabs in the XML should become two line breaks unless in a "codeblock"
|
result = preformat_text_block(text, state)
|
||||||
pos = 0
|
|
||||||
while True:
|
|
||||||
pos = text.find("\n", pos)
|
|
||||||
if pos == -1:
|
|
||||||
break
|
|
||||||
|
|
||||||
pre_text = text[:pos]
|
|
||||||
indent_level = 0
|
|
||||||
while pos + 1 < len(text) and text[pos + 1] == "\t":
|
|
||||||
pos += 1
|
|
||||||
indent_level += 1
|
|
||||||
post_text = text[pos + 1 :]
|
|
||||||
|
|
||||||
# Handle codeblocks
|
|
||||||
if (
|
|
||||||
post_text.startswith("[codeblock]")
|
|
||||||
or post_text.startswith("[codeblock ")
|
|
||||||
or post_text.startswith("[gdscript]")
|
|
||||||
or post_text.startswith("[gdscript ")
|
|
||||||
or post_text.startswith("[csharp]")
|
|
||||||
or post_text.startswith("[csharp ")
|
|
||||||
):
|
|
||||||
tag_text = post_text[1:].split("]", 1)[0]
|
|
||||||
tag_state = get_tag_and_args(tag_text)
|
|
||||||
result = format_codeblock(tag_state, post_text, indent_level, state)
|
|
||||||
if result is None:
|
if result is None:
|
||||||
return ""
|
return ""
|
||||||
text = f"{pre_text}{result[0]}"
|
text = result
|
||||||
pos += result[1] - indent_level
|
|
||||||
|
|
||||||
# Handle normal text
|
|
||||||
else:
|
|
||||||
text = f"{pre_text}\n\n{post_text}"
|
|
||||||
pos += 2 - indent_level
|
|
||||||
|
|
||||||
next_brac_pos = text.find("[")
|
next_brac_pos = text.find("[")
|
||||||
text = escape_rst(text, next_brac_pos)
|
text = escape_rst(text, next_brac_pos)
|
||||||
@@ -2426,6 +2395,56 @@ def format_text_block(
|
|||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
|
def preformat_text_block(text: str, state: State) -> Optional[str]:
|
||||||
|
result = ""
|
||||||
|
codeblock_tag = ""
|
||||||
|
indent_level = 0
|
||||||
|
|
||||||
|
for line in text.splitlines():
|
||||||
|
stripped_line = line.lstrip("\t")
|
||||||
|
tab_count = len(line) - len(stripped_line)
|
||||||
|
|
||||||
|
if codeblock_tag:
|
||||||
|
if line == "":
|
||||||
|
result += "\n"
|
||||||
|
continue
|
||||||
|
|
||||||
|
if tab_count < indent_level:
|
||||||
|
print_error(f"{state.current_class}.xml: Invalid indentation.", state)
|
||||||
|
return None
|
||||||
|
|
||||||
|
if stripped_line.startswith("[/" + codeblock_tag):
|
||||||
|
result += stripped_line
|
||||||
|
codeblock_tag = ""
|
||||||
|
else:
|
||||||
|
# Remove extraneous tabs and replace remaining tabs with spaces.
|
||||||
|
result += "\n" + " " * (tab_count - indent_level + 1) + stripped_line
|
||||||
|
else:
|
||||||
|
if (
|
||||||
|
stripped_line.startswith("[codeblock]")
|
||||||
|
or stripped_line.startswith("[codeblock ")
|
||||||
|
or stripped_line.startswith("[gdscript]")
|
||||||
|
or stripped_line.startswith("[gdscript ")
|
||||||
|
or stripped_line.startswith("[csharp]")
|
||||||
|
or stripped_line.startswith("[csharp ")
|
||||||
|
):
|
||||||
|
if result:
|
||||||
|
result += "\n"
|
||||||
|
result += stripped_line
|
||||||
|
|
||||||
|
tag_text = stripped_line[1:].split("]", 1)[0]
|
||||||
|
tag_state = get_tag_and_args(tag_text)
|
||||||
|
codeblock_tag = tag_state.name
|
||||||
|
indent_level = tab_count
|
||||||
|
else:
|
||||||
|
# A line break in XML should become two line breaks (unless in a code block).
|
||||||
|
if result:
|
||||||
|
result += "\n\n"
|
||||||
|
result += stripped_line
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def format_context_name(context: Union[DefinitionBase, None]) -> str:
|
def format_context_name(context: Union[DefinitionBase, None]) -> str:
|
||||||
context_name: str = "unknown context"
|
context_name: str = "unknown context"
|
||||||
if context is not None:
|
if context is not None:
|
||||||
@@ -2468,50 +2487,6 @@ def escape_rst(text: str, until_pos: int = -1) -> str:
|
|||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
def format_codeblock(
|
|
||||||
tag_state: TagState, post_text: str, indent_level: int, state: State
|
|
||||||
) -> Union[Tuple[str, int], None]:
|
|
||||||
end_pos = post_text.find("[/" + tag_state.name + "]")
|
|
||||||
if end_pos == -1:
|
|
||||||
print_error(
|
|
||||||
f"{state.current_class}.xml: Tag depth mismatch for [{tag_state.name}]: no closing [/{tag_state.name}].",
|
|
||||||
state,
|
|
||||||
)
|
|
||||||
return None
|
|
||||||
|
|
||||||
opening_formatted = tag_state.name
|
|
||||||
if len(tag_state.arguments) > 0:
|
|
||||||
opening_formatted += " " + tag_state.arguments
|
|
||||||
|
|
||||||
code_text = post_text[len(f"[{opening_formatted}]") : end_pos]
|
|
||||||
post_text = post_text[end_pos:]
|
|
||||||
|
|
||||||
# Remove extraneous tabs
|
|
||||||
code_pos = 0
|
|
||||||
while True:
|
|
||||||
code_pos = code_text.find("\n", code_pos)
|
|
||||||
if code_pos == -1:
|
|
||||||
break
|
|
||||||
|
|
||||||
to_skip = 0
|
|
||||||
while code_pos + to_skip + 1 < len(code_text) and code_text[code_pos + to_skip + 1] == "\t":
|
|
||||||
to_skip += 1
|
|
||||||
|
|
||||||
if to_skip > indent_level:
|
|
||||||
print_error(
|
|
||||||
f"{state.current_class}.xml: Four spaces should be used for indentation within [{tag_state.name}].",
|
|
||||||
state,
|
|
||||||
)
|
|
||||||
|
|
||||||
if len(code_text[code_pos + to_skip + 1 :]) == 0:
|
|
||||||
code_text = f"{code_text[:code_pos]}\n"
|
|
||||||
code_pos += 1
|
|
||||||
else:
|
|
||||||
code_text = f"{code_text[:code_pos]}\n {code_text[code_pos + to_skip + 1 :]}"
|
|
||||||
code_pos += 5 - to_skip
|
|
||||||
return (f"\n[{opening_formatted}]{code_text}{post_text}", len(f"\n[{opening_formatted}]{code_text}"))
|
|
||||||
|
|
||||||
|
|
||||||
def format_table(f: TextIO, data: List[Tuple[Optional[str], ...]], remove_empty_columns: bool = False) -> None:
|
def format_table(f: TextIO, data: List[Tuple[Optional[str], ...]], remove_empty_columns: bool = False) -> None:
|
||||||
if len(data) == 0:
|
if len(data) == 0:
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -2395,7 +2395,8 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, const C
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool using_tab_indent = int(EDITOR_GET("text_editor/behavior/indent/type")) == 0;
|
const bool using_space_indent = int(EDITOR_GET("text_editor/behavior/indent/type")) == 1;
|
||||||
|
const int indent_size = MAX(1, int(EDITOR_GET("text_editor/behavior/indent/size")));
|
||||||
|
|
||||||
const Ref<Font> doc_font = p_owner_node->get_theme_font(SNAME("doc"), EditorStringName(EditorFonts));
|
const Ref<Font> doc_font = p_owner_node->get_theme_font(SNAME("doc"), EditorStringName(EditorFonts));
|
||||||
const Ref<Font> doc_bold_font = p_owner_node->get_theme_font(SNAME("doc_bold"), EditorStringName(EditorFonts));
|
const Ref<Font> doc_bold_font = p_owner_node->get_theme_font(SNAME("doc_bold"), EditorStringName(EditorFonts));
|
||||||
@@ -2421,7 +2422,7 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, const C
|
|||||||
const Color kbd_bg_color = p_owner_node->get_theme_color(SNAME("kbd_bg_color"), SNAME("EditorHelp"));
|
const Color kbd_bg_color = p_owner_node->get_theme_color(SNAME("kbd_bg_color"), SNAME("EditorHelp"));
|
||||||
const Color param_bg_color = p_owner_node->get_theme_color(SNAME("param_bg_color"), SNAME("EditorHelp"));
|
const Color param_bg_color = p_owner_node->get_theme_color(SNAME("param_bg_color"), SNAME("EditorHelp"));
|
||||||
|
|
||||||
String bbcode = p_bbcode.dedent().remove_chars("\t\r").strip_edges();
|
String bbcode = p_bbcode.dedent().remove_chars("\r").strip_edges();
|
||||||
|
|
||||||
// Select the correct code examples.
|
// Select the correct code examples.
|
||||||
switch ((int)EDITOR_GET("text_editor/help/class_reference_examples")) {
|
switch ((int)EDITOR_GET("text_editor/help/class_reference_examples")) {
|
||||||
@@ -2661,19 +2662,19 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, const C
|
|||||||
const String codeblock_text = bbcode.substr(brk_end + 1, end_pos - (brk_end + 1)).strip_edges();
|
const String codeblock_text = bbcode.substr(brk_end + 1, end_pos - (brk_end + 1)).strip_edges();
|
||||||
|
|
||||||
String codeblock_copy_text = codeblock_text;
|
String codeblock_copy_text = codeblock_text;
|
||||||
if (using_tab_indent) {
|
if (using_space_indent) {
|
||||||
// Replace the code block's space indentation with tabs.
|
// Replace the code block's tab indentation with spaces.
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
PackedStringArray text_lines = codeblock_copy_text.split("\n");
|
PackedStringArray text_lines = codeblock_copy_text.split("\n");
|
||||||
for (const String &line : text_lines) {
|
for (const String &line : text_lines) {
|
||||||
const String stripped_line = line.dedent();
|
const String stripped_line = line.dedent();
|
||||||
const int space_count = line.length() - stripped_line.length();
|
const int tab_count = line.length() - stripped_line.length();
|
||||||
|
|
||||||
if (builder.num_strings_appended() > 0) {
|
if (builder.num_strings_appended() > 0) {
|
||||||
builder.append("\n");
|
builder.append("\n");
|
||||||
}
|
}
|
||||||
if (space_count > 0) {
|
if (tab_count > 0) {
|
||||||
builder.append(String("\t").repeat(MAX(space_count / 4, 1)) + stripped_line);
|
builder.append(String(" ").repeat(tab_count * indent_size) + stripped_line);
|
||||||
} else {
|
} else {
|
||||||
builder.append(line);
|
builder.append(line);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ static String fix_doc_description(const String &p_bbcode) {
|
|||||||
// This seems to be the correct way to do this. It's the same EditorHelp does.
|
// This seems to be the correct way to do this. It's the same EditorHelp does.
|
||||||
|
|
||||||
return p_bbcode.dedent()
|
return p_bbcode.dedent()
|
||||||
.remove_chars("\t\r")
|
.remove_chars("\r")
|
||||||
.strip_edges();
|
.strip_edges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user