Report any technical problems you discover and discuss solutions.

Displaying code in a Xerte page

  • takeshi
  • Onderwerp Auteur
  • Offline
  • Junior lid
  • Junior lid
Meer
5 jaren 2 maanden geleden #7388 door takeshi
Displaying code in a Xerte page werd gestart door 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?

Graag Inloggen of een account aanmaken deelnemen aan het gesprek.

Meer
5 jaren 2 maanden geleden #7390 door ronm
Beantwoord door ronm in topic 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/

Graag Inloggen of een account aanmaken deelnemen aan het gesprek.

  • takeshi
  • Onderwerp Auteur
  • Offline
  • Junior lid
  • Junior lid
Meer
5 jaren 2 maanden geleden - 5 jaren 2 maanden geleden #7394 door takeshi
Beantwoord door takeshi in topic 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.
Laatst bewerkt 5 jaren 2 maanden geleden door takeshi.

Graag Inloggen of een account aanmaken deelnemen aan het gesprek.

  • takeshi
  • Onderwerp Auteur
  • Offline
  • Junior lid
  • Junior lid
Meer
5 jaren 1 maand geleden #7410 door takeshi
Beantwoord door takeshi in topic 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.

Graag Inloggen of een account aanmaken deelnemen aan het gesprek.

Meer
5 jaren 1 maand geleden #7416 door simonbarne
Beantwoord door simonbarne in topic 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.

Graag Inloggen of een account aanmaken deelnemen aan het gesprek.

  • takeshi
  • Onderwerp Auteur
  • Offline
  • Junior lid
  • Junior lid
Meer
5 jaren 1 maand geleden #7417 door takeshi
Beantwoord door takeshi in topic 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!

Graag Inloggen of een account aanmaken deelnemen aan het gesprek.

Moderators: ronmjultenJohnSmith
Tijd voor maken pagina: 0.209 seconden
Copyright © 2026 The Xerte Project.
Xerte logo Apereo logo OSI Logo