RayTracing / raytracing.github.io

Main Web Site (Online Books)
https://raytracing.github.io/
Creative Commons Zero v1.0 Universal
8.2k stars 827 forks source link

Fix extra spaces in static_cast in rtw_stb_image.h once fixed in Markdeep #1463

Closed hollasch closed 3 months ago

hollasch commented 3 months ago

Markdeep currently has a bug where the line

*bptr = static_cast<unsigned char>(*fptr * 256.0);

is rendered as

*bptr = static_cast<unsigned char="">(*fptr * 256.0);

As a workaround, we use

*bptr = static_cast< unsigned char >(*fptr * 256.0);

This is in the file rtw_stb_image.h. Once this bug is fixed in Markdeep, remove the extraneous spaces inside the angle brackets.

armansito commented 3 months ago

When you insert spaces those get rendered in the final document. To avoid the visible spaces and to prevent the browser from interpreting the less-than sign as the beginning of a tag, you can alternately insert a "Zero Width No-Break Space" unicode character (U+FEFF). The HTML entity escape code for this is &#xFEFF;:

*bptr = static_cast<&#xFEFF;unsigned char>(*fptr * 256.0);

This gets rendered as expected and without spaces for me (by Chrome, Safari, and Firefox). Note that the second space (before the greater-than sign >) doesn't seem to be necessary as just separating the less-than sign from a subsequent character seems to be enough to convince the browser that this is not an HTML tag.

hollasch commented 3 months ago

Now copy and paste from the listing into your code and try compiling. 😄

hollasch commented 3 months ago

(I also tried no-break space, en-space, etc.)

armansito commented 3 months ago

Yeah, copying and pasting becomes an issue with character codes like this.

armansito commented 3 months ago

Another solution that works (according to the Markdeep Demo, Section 1.15.5 is to wrap the code examples (or the entire document) in <script type="preformatted">...</script>. This seems to make the code render correctly without any special treatment and the copying and pasting seems to work as well.

hollasch commented 3 months ago

Ah. Ugly, but another decent (temporary) workaround. Morgan returns from vacation April 4 — let's see what his response is then.

armansito commented 3 months ago

Another solution that works (according to the Markdeep Demo, Section 1.15.5 is to wrap the code examples (or the entire document) in <script type="preformatted">...</script>. This seems to make the code render correctly without any special treatment and the copying and pasting seems to work as well.

I tried wrapping the whole document and that didn't work for me. Wrapping individual listings works though.

Anyway, let's wait for Morgan's response.

hollasch commented 3 months ago

Here's Morgan's response:

This is caused by the browser parsing that as a HTML tag with an empty attribute before I see the document in Markdeep script. The simplest workaround is to make the input not legal HTML with the space as you found. Another workaround is the one advocated in the demo/manual https://casual-effects.com/markdeep/features.md.html#basicformatting/codeblocks/less-thansignsincode:

use a script tag with "preformatted" to surround either the entire document or the code sample. That prevents the browser from modifying it, and then Markdeep knows to strip the script tag out when processing.