svd2rust icon indicating copy to clipboard operation
svd2rust copied to clipboard

Partial escape of HTML link from peripheral description

Open hegza opened this issue 1 year ago • 6 comments

Given an SVD with an HTML link in a description creates either a correct or a partially escaped link definition depending on where it is generated in the PAC.

E.g., relevant part of input SVD:

<peripheral>
	<name>Google</name>
	<version>1.0</version>
	<description>
		Link to Google: &lt;https://google.com&gt;
	</description>
	<registers>...</registers>
</peripheral>

Relevant parts of output:

#[doc = "Link to Google: &lt;https://google.com>"]
pub mod google;
#[doc = "Link to Google: <https://google.com>"]
pub struct Google {
    _marker: PhantomData<*const ()>,
}

We see the generated link symbols are partially escaped when used in the mod documentation and correctly escaped when used in peripheral struct documentation.

Reproduction

  • Attached, minimal SVD to reproduce issue: test.zip (in Zip due to GitHub file-type restriction)
  • Command to generate: svd2rust --target riscv -i test.svd && form -i lib.rs -o src && rm lib.rs && cargo fmt
  • svd2rust --version

    svd2rust 0.33.3 ( )

hegza avatar Jun 10 '24 10:06 hegza

I've never see links in description. Is this allowed by SVD? I'm not sure.

burrbull avatar Jun 12 '24 13:06 burrbull

I would've assumed that svd2rust does not do transformations of the field contents but it does seem to translate special HTML characters. Surely it's wrong that it sometimes does it and sometimes not.

The behavior is relevant for our use case. I'll try to find time to investigate.

hegza avatar Jun 15 '24 14:06 hegza

PRs are appreciated.

burrbull avatar Jun 16 '24 04:06 burrbull

I've found that causer is encode_text_minimal. Looks like removing it fixes your issue. The question is can we remove it entirely? Does it needed yet?

burrbull avatar Oct 20 '24 07:10 burrbull

Sorry, I don't necessarily understand the question. I'm also sorry I didn't get to investigating it myself. It's a low priority issue for us at the end of the day and we re-generate PACs infrequently.

We use peripheral level links to point to the relevant hardware implementation / documentation when working with open-source hardware IP.

Consistency is good enough, i.e. both links generated the same way. We can script the rest if necessary. Does that answer the question?

hegza avatar Oct 20 '24 09:10 hegza

The question is why #711 was introduced. Maybe it is just not actual in newer versions of Rust.

burrbull avatar Oct 20 '24 09:10 burrbull