How To Display Valid Markup Code In Websites

Martin Brinkmann
May 7, 2009
Updated • Aug 9, 2018
Development
|
0

There are two issues or problems that Internet users encounter when they want to paste code into forms to display these on the Internet. The first problem that can be encountered is that the website will interpret part or all of the code instead of displaying it.

A basic example would be to display the html code needed to make text linkable on a website. These codes are interpreted by most forms automatically if the user just pastes the code into the form.

The second problem that can arise is that the website will not validate because of the way it has been pasted into the form. Displaying the & char will for example return an error when validating the code. This can lead to all kinds of troubles including broken RSS feeds (read: The XML Feed Cannot Be Displayed).

How to display code on websites

Displaying valid markup code on websites, forums, blogs and any other page is not difficult. The only thing that needs to be done to achieve this is to convert all entities before pasting the code. This can be done manually or by using a script like the one offered on Spacefem.

You may eventually know the replacement strings for brackets and other elements that make up valid code bits on websites. Using a converter is usually the better choice as it can convert an entire construct in one go whereas you'd have to replace each entity individually if you do it manually.

All that needs to be done is to paste the code into the form and click on the Make Code button at the bottom. To display the following code on a website

<a href="https://www.ghacks.net/">Ghacks</a>

one would have to paste the following code into the form on the website where the code should be displayed

&lt;a href=&quot;https://www.ghacks.net/&quot;&gt;Ghacks&lt;/a&gt;

This is actually the easiest way to ensure that the website will not interpret the code and that the code will be valid markup code that users can copy and paste elsewhere.

Obviously, if you want to display the code output, you'd have to paste the actual code and not convert HTML entities in that case.

Summary
How To Display Valid Markup Code In Websites
Article Name
How To Display Valid Markup Code In Websites
Description
Find out how to display valid markup code, e.g. HTML code, on websites so that it is not interpreted by the site but displayed as the code it is.
Author
Publisher
Ghacks Technology News
Logo
Advertisement

Previous Post: «
Next Post: «

Comments

There are no comments on this post yet, be the first one to share your thoughts!

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

We love comments and welcome thoughtful and civilized discussion. Rudeness and personal attacks will not be tolerated. Please stay on-topic.
Please note that your comment may not appear immediately after you post it.