Report any technical problems you discover and discuss solutions.

Displaying code in a Xerte page

Plus d'informations
il y a 5 ans 2 mois #7388 par takeshi
Displaying code in a Xerte page a été créé par takeshi
I want to include (HTML) code samples in Xerte pages, and tried to do this in the editor Source view using a combination of <pre>, <code>, and replacing escape characters with HTML entities (e.g. &lt; and &gt;). The first time I do this, it all looks fine in WYSIWIG editor, and in published project. But if I close the editor, then open it again, the HTML entities are converted back into escape characters and the snippet is rendered. Is it possible to stop this from happening?

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 5 ans 2 mois #7390 par ronm
Réponse de ronm sur le sujet Displaying code in a Xerte page
Hi
try any of the following:
Code:
<xmp>Wrap your code between </xmp> tags.
Code:
Or put your code inside <textarea></textarea> tags.
Code:
Or Convert all your ‘<‘ and ‘>’ to ‘&lt’ and ‘&gt’ respectively

HTH
Ron

Xerte developer & trainer
e-learning & m-learning consultant
mitchellmedia.co.uk | xerteacademy.com | learningapps.co.uk
Note: Support here is voluntary and meant for users to support each other.
Need direct commercial support with Xerte? mitchellmedia.co.uk/contact/

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 5 ans 2 mois - il y a 5 ans 2 mois #7394 par takeshi
Réponse de takeshi sur le sujet Displaying code in a Xerte page
Thanks for the suggestions Ron. I would prefer to avoid <xmp> because it is deprecated. Using <textarea> is a bit of an awkward workaround as have to add readonly attribute, and also specify rows and cols to make it fit the text.
The problem with using the
Code:
&lt; and &gt;
is that they get converted to tag brackets and rendered as HTML when you go back into the editor later. I was hoping there might be a solution to this, I haven't experienced it outside of Xerte.
Dernière édition: il y a 5 ans 2 mois par takeshi.

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 5 ans 2 mois #7410 par takeshi
Réponse de takeshi sur le sujet Displaying code in a Xerte page
For now I have found the only way to stop the HTML entities from being rendered is to enclose every single one in a span tag. So for example to show
Code:
<strong>Text goes here</strong>
I must write
Code:
<pre style="margin-left:40px"> <code><span>&lt;</span>strong<span>&gt;</span>Text goes here<span>&lt;</span>/strong<span>&gt;</span> </code> </pre>
It's quite a slog, but it seems to work.

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 5 ans 2 mois #7416 par simonbarne
Réponse de simonbarne sur le sujet Displaying code in a Xerte page
Isn't it simpler to use <textarea>? I know you rejected this option, but all it needs is "readonly" and the number of rows. The width (e.g. 100%) can be set in the Styles optional property for the page.

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 5 ans 2 mois #7417 par takeshi
Réponse de takeshi sur le sujet Displaying code in a Xerte page
Thanks Simon for the styling suggestion, it was the text area width that bothered me most - I didn't like using the cols attribute, and styling it is much easier to work with. I'm just adding the width in a style attribute in the textarea tag.
As long as I remember that empty lines will get stripped out, yes, this is much simpler than using a million span tags!

Connexion ou Créer un compte pour participer à la conversation.

Modérateurs: ronmjultenJohnSmith
Temps de génération de la page : 0.277 secondes
Copyright © 2026 The Xerte Project.
Xerte logo Apereo logo OSI Logo