Skip to content

Commit 911f9cb

Browse files
committed
RustDoc links: replace [code][/code] again verbatim, more reliable
1 parent 88dd2f5 commit 911f9cb

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

bindings_generator/src/class_docs.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,7 @@ impl GodotXmlDocs {
174174
// * [code]C[/code]
175175
// * [signal C]
176176
// Must run before others, as [code] will itself match the link syntax
177-
let no_link_regex =
178-
Regex::new("\\[code]([^.]+?)\\[/code]|\\[signal ([A-Za-z0-9_]+?)]").unwrap();
177+
let no_link_regex = Regex::new("\\[signal ([A-Za-z0-9_]+?)]").unwrap();
179178

180179
// Covers:
181180
// * [C]
@@ -201,11 +200,20 @@ impl GodotXmlDocs {
201200
let godot_doc = godot_doc
202201
.replace("[codeblock]", "```gdscript")
203202
.replace("[/codeblock]", "```")
203+
.replace("[code]", "`")
204+
.replace("[/code]", "`")
204205
.replace("[b]", "**")
205206
.replace("[/b]", "**")
206207
.replace("[i]", "_")
207208
.replace("[/i]", "_");
208209

210+
// Note: we currently don't use c[1], which would be the "kind" (method/member/constant/...)
211+
// This one could be used to disambiguate the doc-link, e.g. [`{method}`][fn@Self::{method}]
212+
213+
// What currently doesn't work are "indexed properties" which are not also exposed as getters, e.g.
214+
// https://docs.godotengine.org/en/stable/classes/class_area2d.html#properties 'gravity_point'
215+
// This needs to be implemented first: https://github.com/godot-rust/godot-rust/issues/689
216+
209217
// URLs
210218
let godot_doc = url_regex.replace_all(&godot_doc, |c: &Captures| {
211219
let url = &c[1];
@@ -218,31 +226,6 @@ impl GodotXmlDocs {
218226
}
219227
});
220228

221-
// Note: we currently don't use c[1], which would be the "kind" (method/member/constant/...)
222-
// This one could be used to disambiguate the doc-link, e.g. [`{method}`][fn@Self::{method}]
223-
224-
// What currently doesn't work are "indexed properties" which are not also exposed as getters, e.g.
225-
// https://docs.godotengine.org/en/stable/classes/class_area2d.html#properties 'gravity_point'
226-
// This needs to be implemented first: https://github.com/godot-rust/godot-rust/issues/689
227-
228-
// `member` style (no link)
229-
let godot_doc = no_link_regex.replace_all(&godot_doc, |c: &Captures| {
230-
let member = c.get(1).or(c.get(2)).unwrap().as_str();
231-
format!("`{member}`", member = member)
232-
});
233-
234-
// [Type] style
235-
let godot_doc = type_regex.replace_all(&godot_doc, |c: &Captures| {
236-
let godot_ty = &c[2];
237-
let rust_ty = Self::translate_type(godot_ty);
238-
239-
format!(
240-
"[`{godot_ty}`][{rust_ty}]",
241-
godot_ty = godot_ty,
242-
rust_ty = rust_ty
243-
)
244-
});
245-
246229
// [Type::member] style
247230
let godot_doc = class_member_regex.replace_all(&godot_doc, |c: &Captures| {
248231
let godot_ty = &c[2];
@@ -261,6 +244,23 @@ impl GodotXmlDocs {
261244
format!("[`{member}`][Self::{member}]", member = &c[2])
262245
});
263246

247+
// `member` style (no link)
248+
let godot_doc = no_link_regex.replace_all(&godot_doc, |c: &Captures| {
249+
format!("`{member}`", member = &c[1])
250+
});
251+
252+
// [Type] style
253+
let godot_doc = type_regex.replace_all(&godot_doc, |c: &Captures| {
254+
let godot_ty = &c[2];
255+
let rust_ty = Self::translate_type(godot_ty);
256+
257+
format!(
258+
"[`{godot_ty}`][{rust_ty}]",
259+
godot_ty = godot_ty,
260+
rust_ty = rust_ty
261+
)
262+
});
263+
264264
format!("{}{}", gdscript_note, godot_doc)
265265
}
266266
}

0 commit comments

Comments
 (0)