Supporting each other

Community forums

Welcome, Guest
Username: Password: Remember me
Report any technical problems you discover and discuss solutions.
  • Page:
  • 1

TOPIC:

Displaying code in a Xerte page 3 years 6 months ago #7388

  • takeshi
  • takeshi's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 27
  • Thank you received: 1
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. < and >). 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?

Please Inloggen or Create an account to join the conversation.

Displaying code in a Xerte page 3 years 6 months ago #7390

  • ronm
  • ronm's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 852
  • Thank you received: 261
Hi
try any of the following:
<xmp>Wrap your code between </xmp> tags.
Or put your code inside <textarea></textarea> tags.
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/

Please Inloggen or Create an account to join the conversation.

Displaying code in a Xerte page 3 years 6 months ago #7394

  • takeshi
  • takeshi's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 27
  • Thank you received: 1
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
&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.

Please Inloggen or Create an account to join the conversation.

Last edit: by takeshi.

Displaying code in a Xerte page 3 years 5 months ago #7410

  • takeshi
  • takeshi's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 27
  • Thank you received: 1
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
<strong>Text goes here</strong>
I must write
<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.

Please Inloggen or Create an account to join the conversation.

Displaying code in a Xerte page 3 years 5 months ago #7416

  • simonbarne
  • simonbarne's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 36
  • Thank you received: 5
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.

Please Inloggen or Create an account to join the conversation.

Displaying code in a Xerte page 3 years 5 months ago #7417

  • takeshi
  • takeshi's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 27
  • Thank you received: 1
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!

Please Inloggen or Create an account to join the conversation.

  • Page:
  • 1
Moderators: ronmjultenJohnSmith
Time to create page: 0.052 seconds
Copyright © 2024 The Xerte Project.
Xerte logo Apereo logo OSI Logo

Search