Forum How do I...?

Styling with prince-text-replace

nico
How can I apply styling to a text that is replaced with prince-text-replace?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>prince-text-replace</title>
<style type="text/css">
body {
    prince-text-replace: "black" "<span class='rep'>not red but it should</span>";
}
.rep {
    color: red;
}
</style>
</head>
<body>
<p>This text is black</p>
<p><span class='rep'>This one is red</span></p>
</body>
</html>
mikeday
The prince-text-replace property can only generate text, not markup.

To create new elements you will need to use JavaScript. In some cases you can also use CSS pseudo-elements, like ::before and ::after.
nico
Thank you for your reply. Can you tell me what happens to the span tag in my exemple above? If Prince is called with --input=html, the span tag is shown as text, but with --input=xml it disappears. Is the span tag simply discarded in xml mode ?

Note that in my example the doctype declaration seems to trigger --input=xml.
mikeday
In XML, the <style> element is not parsed in a special manner, so tags like <span> will be interpreted as actual tags! You would need to escape them, with &lt; and &gt; entities, or similar.