Skip to content

Commit d7d2de6

Browse files
authored
Merge pull request #1015 from adalinesimonian/litrs
fix: parse doc strings with litrs
2 parents 506f8f5 + d929319 commit d7d2de6

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

godot-macros/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ homepage = "https://godot-rust.github.io"
1212

1313
[features]
1414
api-custom = ["godot-bindings/api-custom"]
15-
register-docs = ["dep:markdown"]
15+
register-docs = ["dep:markdown", "dep:litrs"]
1616
codegen-full = ["godot/__codegen-full"]
1717

1818
[lib]
@@ -24,6 +24,7 @@ proc-macro2 = "1.0.80" # Literal::c_string() added in 1.0.80.
2424
quote = "1.0.29"
2525
# Enabled by `docs`.
2626
markdown = { version = "=1.0.0-alpha.21", optional = true }
27+
litrs = { version = "0.4.1", optional = true }
2728
# Requires bugfixes from 0.6.1.
2829
venial = "0.6.1"
2930

godot-macros/src/docs.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,10 @@ fn siphon_docs_from_attributes(doc: &[Attribute]) -> impl Iterator<Item = String
113113
_ => None,
114114
})
115115
.flat_map(|doc| {
116-
doc.iter().map(|x| {
117-
x.to_string()
118-
.trim_start_matches('r')
119-
.trim_start_matches('#')
120-
.trim_start_matches('"')
121-
.trim_end_matches('#')
122-
.trim_end_matches('"')
123-
.to_string()
116+
doc.iter().map(|token_tree| {
117+
let str = token_tree.to_string();
118+
litrs::StringLit::parse(str.clone())
119+
.map_or(str, |parsed| parsed.value().to_string())
124120
})
125121
})
126122
}

itest/rust/src/register_tests/res/registered_docs.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
<class name="FairlyDocumented" inherits="Node" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
33
<brief_description>[i]documented[/i] ~ [b]documented[/b] ~ [AABB] &lt; [url=https://github.com/godot-rust/gdext/pull/748]pr[/url]</brief_description>
44
<description>[i]documented[/i] ~ [b]documented[/b] ~ [AABB] &lt; [url=https://github.com/godot-rust/gdext/pull/748]pr[/url][br][br]This is a paragraph. It has some text in it. It&#39;s a paragraph. It&#39;s quite long, and wraps multiple lines. It is describing the struct [code]Player[/code]. Or maybe perhaps it&#39;s describing the module. It&#39;s hard to say, really. It even has some code in it: [code]let x = 5;[/code]. And some more code: [code]let y = 6;[/code]. And a bunch of [b]bold[/b] and [i]italic[/i] text with [i]different[/i] ways to do it. Don&#39;t forget about [url=https://example.com]links[/url].[br][br]a few tests:[br][br]headings:[br][br][b]Some heading[/b][br][br]lists:[br][br]• lists[br]• like this[br] • with sublists[br] that are multiline[br] • and subsublists[br]• and list items[br][br]• maybe with [code]*[/code] as well[br][br][url=https://example.com]reference-style link[/url][br][br]links with back-references:[br][br]Blah blah¹ Also same reference¹[br][br]footnotes:[br][br]We cannot florbinate the glorb²[br][br]Third note in order of use³ and fourth ⁴[br][br]Fifth note in order of use. ⁶[br][br]Sixth footnote in order of use. ⁵[br][br]task lists:[br][br]We must ensure that we&#39;ve completed[br][br]• [ ] task 1[br]• [x] task 2[br][br]tables:[br][br]Header1 | Header2[br]abc | def[br][br]images:[br][br][url=https://godotengine.org/assets/press/logo_small_color_light.png]https://godotengine.org/assets/press/logo_small_color_light.png[/url][br][br][url=https://godotengine.org/assets/press/logo_small_color_dark.png]https://godotengine.org/assets/press/logo_small_color_dark.png[/url][br][br]blockquotes:[br][br]&gt; Some cool thing[br][br]ordered list:[br][br]1. thing one[br]2. thing two[br] 1. thing two point one[br] 2. thing two point two[br] 3. thing two point three[br][br][b]Something here &lt; this is technically header syntax[/b][br][br]And here[br][br]smart punctuation[br][br]codeblocks:[br][br][codeblock lang=rust]#![no_main]
5-
#[link_section=\&quot;.text\&quot;]
5+
#[link_section=&quot;.text&quot;]
66
#[no_mangle]
77
static main: u64 = 0x31c0678b10;[/codeblock][br][br][codeblock lang=gdscript]extends Node
88

99
func _ready():
10-
print(\&quot;Hello, world!\&quot;)[/codeblock][br][br][codeblock lang=csharp]using Godot;
10+
print(&quot;Hello, world!&quot;)[/codeblock][br][br][codeblock lang=csharp]using Godot;
1111

1212
public class Player : Node2D
1313
{

0 commit comments

Comments
 (0)