pretext icon indicating copy to clipboard operation
pretext copied to clipboard

Wrap text datafile/pre/@source in CDATA

Open gigamonkey opened this issue 5 months ago • 4 comments

This seems like the Right Thing™ insofar as a data file should not need to be mangled to be legal XML text. However this change could possibly break existing books that have run into the problem this patch is fixing by adding escaping or CDATA into their datafiles.

gigamonkey avatar Jul 19 '25 18:07 gigamonkey

Initially posed on wrong PR. @rbeezer's post on -dev and this crossed in flight.

Our conclusion is that @source on datafile should probably be deprecated. (Correct me if that wasn't our conclusion Rob).

Usually @source usually means that the referenced asset is being loaded at run time. This @source is confusing because the asset is being loaded at build time (as text) into the XML before it is built. (Which is probably why you wanted to put the program into external, which is really for things that are going to be loaded at run time.)

It also is potentially confusing because you can use <pre> outside of a datafile, but @source is not going to work in those locations.

Anywhere else you wanted to include code from a file (like in the body of a <program>) you would have to use <xi:include parse="text" href="filepath"/> to inject the contents. That handles escaping the text to make it valid XML.

So pre@source is just a special case alternative to writing that.

The recommended authoring pattern for putting the contents into a separate file would be:

<datafile>
  <pre>
    <xi:include parse="text" href="filepath"/>
  </pre>
 </datafile>

ascholerChemeketa avatar Jul 21 '25 20:07 ascholerChemeketa

Makes sense to me. At that point it's kind of weird to me to have the

 element at all, but I guess that's to contrast to the possibility of an  child.

gigamonkey avatar Jul 21 '25 20:07 gigamonkey

kind of weird

If you mean the pre element ("the element" is not clear to me), it is necessary to distinguish the case where the element is an image. Though maybe we coulda, shoulda, done that with an attribute.

rbeezer avatar Jul 22 '25 01:07 rbeezer

Lol. I forgot Markdown also lets you use arbitrary HTML. What I said, some of which got eaten by Markdown:

Makes sense to me. At that point it's kind of weird to me to have the <pre> element at all, but I guess that's to contrast to the possibility of an <image> child.

gigamonkey avatar Jul 22 '25 01:07 gigamonkey