@@ -162,12 +162,21 @@ impl GodotXmlDocs {
162
162
} ;
163
163
164
164
// TODO reuse regex across classes
165
+ // Note: there are still a few special cases, such as:
166
+ // * OK and ERR_CANT_CREATE (corresponding Result.Ok() and GodotError.ERR_CANT_CREATE)
165
167
166
168
// Covers:
167
169
// * [url=U]text[/url]
168
170
// * [url=U][/url]
169
171
let url_regex = Regex :: new ( "\\ [url=(.+?)](.*?)\\ [/url]" ) . unwrap ( ) ;
170
172
173
+ // Covers:
174
+ // * [code]C[/code]
175
+ // * [signal C]
176
+ // 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 ( ) ;
179
+
171
180
// Covers:
172
181
// * [C]
173
182
// * [enum C]
@@ -187,11 +196,15 @@ impl GodotXmlDocs {
187
196
let class_member_regex =
188
197
Regex :: new ( "\\ [(member|method|constant) ([A-Za-z0-9_]+?)\\ .([A-Za-z0-9_]+?)]" ) . unwrap ( ) ;
189
198
190
- // Covers:
191
- // * [code]C[/code]
192
- // * [signal C]
193
- let no_link_regex =
194
- Regex :: new ( "\\ [code]([^.]+?)\\ [/code]|\\ [signal ([A-Za-z0-9_]+?)]" ) . unwrap ( ) ;
199
+ // Before any regex replacement, do verbatim replacements
200
+ // Note: maybe some can be expressed as regex, but if text-replace does the job reliably enough, it's even faster
201
+ let godot_doc = godot_doc
202
+ . replace ( "[codeblock]" , "```gdscript" )
203
+ . replace ( "[/codeblock]" , "```" )
204
+ . replace ( "[b]" , "**" )
205
+ . replace ( "[/b]" , "**" )
206
+ . replace ( "[i]" , "_" )
207
+ . replace ( "[/i]" , "_" ) ;
195
208
196
209
// URLs
197
210
let godot_doc = url_regex. replace_all ( & godot_doc, |c : & Captures | {
@@ -212,7 +225,11 @@ impl GodotXmlDocs {
212
225
// https://docs.godotengine.org/en/stable/classes/class_area2d.html#properties 'gravity_point'
213
226
// This needs to be implemented first: https://github.com/godot-rust/godot-rust/issues/689
214
227
215
- // TODO: [signal M]
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
+ } ) ;
216
233
217
234
// [Type] style
218
235
let godot_doc = type_regex. replace_all ( & godot_doc, |c : & Captures | {
@@ -244,20 +261,6 @@ impl GodotXmlDocs {
244
261
format ! ( "[`{member}`][Self::{member}]" , member = & c[ 2 ] )
245
262
} ) ;
246
263
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
- // Note: maybe some of the following can be expressed as regex, but if text-replace does the job reliably enough, it's even faster
253
- let translated = godot_doc
254
- . replace ( "[codeblock]" , "```gdscript" )
255
- . replace ( "[/codeblock]" , "```" )
256
- . replace ( "[b]" , "**" )
257
- . replace ( "[/b]" , "**" )
258
- . replace ( "[i]" , "_" )
259
- . replace ( "[/i]" , "_" ) ;
260
-
261
- format ! ( "{}{}" , gdscript_note, translated)
264
+ format ! ( "{}{}" , gdscript_note, godot_doc)
262
265
}
263
266
}
0 commit comments