Exaple of pre tag.

Ideas on how to display/present HTML tags on a webpage

I would like that to formatted properly with indentation, and perhaps even have the tags in a different colour scheme. I’m fully aware that I could write the styling for this myself, but surely someone has already written and made available a stylesheet, a LESS mixin, or perhaps a jQuery plugin which recognises and formats for me? UPDATE: Just to make people aware, I realise that I have to HTML-encode the tags (< and >). But that doesn’t help with the formatting/presentation, and it’s the formatting/presentation that I’m looking for help with.

5 Answers 5

  <html><body>This is my html inside html.</body> </html>  

Note that xmp is obsolete and has been removed from HTML5: developer.mozilla.org/en-US/docs/Web/HTML/Element/xmp

While obsolete in the sense that its use is discouraged, none of pre, code, or other similar tags achieve the same affect, and as of this writing xmp still works in Firefox and Chrome, at least. If you want to have a file you can look at yourself (i.e. unescaped < and >tags) rendered as html on the page, xmp does this and none of the other suggested alternatives do.

<div> <p> <span>Hello world</span> </p> </div> 

As for color coding, look into Google Code Prettify. Here are some examples.

You are looking for SyntaxHighlighter. See demo page here

To preserve the formatting (line breaks and spacing), you can use

markup. It is best used so that the first line starts immediately (on the same line) after the 
tag and the last line is immediately (without linebreak) followed by the end tag

. Otherwise some browsers may display extra empty lines.

The markup implies a system-dependent monospace font by default. This can of course be changed in CSS. The markup also implies font size reduction on most browsers, presumably to cope with the properties of monospace fonts; you may therefore wish to set font-size to a value (maybe 100%) to match your design.

Alternatively, you can wrap the code inside any block element (like ) and set white-space: pre for it in CSS. This means that the formatting is preserved but the font face and size are the same as for surrounding text (unless you explicitly set it).

You may additionally use markup to indicate the content as computer code. It, too, sets the font to monospace and reduced-size but is otherwise purely logical. If you wish to indicate the language used, then would be the way suggested in HTML5 drafts. This has no direct impact as such; it just makes it easier to style your HTML code samples consistently and to recognize them in JavaScript processing if needed.

 <span>Hello world</span> </p> </div>

Источник

How to show HTML code on a web page?

In this tutorial you will learn how we can show our HTML, C#, Java, C language etc. code on webpage.

I tried to find the solution of this problem, but I didn’t found any helpful solution on the internet. Here you will get your problem solution in easy way.

If you found any difficulty and mistakes in this tutorial please let me know by posting comment in comment box or send me message in contact us form.

Types of tag to display code on webpage.

The tag that is use to show the coding of html, java c etc on page are given below.

Introduction of
..

tag

The

..

tag is use to display or show the all language coding as same on HTML webpage. We will use HTML

..

tag to display or show the coding on our HTML webpage. With the help of

..

tag we can do it.

In HTML

..

tag we write or paste our HTML, C#, Java, C etc. code. It will show or display same code as you written or pasted in

..

tag.

You can see the output below.

    

Campuslife

Step 1.

Open your Notepad or Adobe Dreamweaver or any other HTML editor. I am using Adobe Dreamweaver. I am suggesting to you use Notepad for better practice.

To open the Notepad press window + r and type notepad, then press enter. Or you can find in start menu.

Start Menu All programs Accessories Notepad.

Step 2.

Let’s start working with

..

tag.

In

..

tag we show the HTML angle brackets ( ) tags with help of & lt ; ( less then angle bracket) and & gt ; (> greater then angle bracket).

Let suppose you want to display a tag in

..

tag then we will use above angle brackets.

Output:

I hope now you have understood the concept of

..

tag. Now our beginning level has been finished.

Now we will work on our different language coding like html, c#, java, etc. which we want to show on webpage.

Step 3.

First create

..

tag and copy the below html code and paste it in between

..

tag.

You will see the HTML angle brackets I replaced with & lt ; and & gt ; angle brackets because we want to display or show it on webpage.

Example:

&lt;html&gt; &lt;head&gt; &lt;title&gt;Welcome to campuslife.&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Campuslife Wesbite&lt;/h1&gt; &lt;h2&gt;My first page.&lt;/h2&gt; &lt;p&gt; Campuslife is a free learning source website for users. &lt;p&gt; &lt;/body&gt; &lt;/html&gt; 

Step 4.

Now we will apply the css to above HTML code. First create the class of your

..

tag like below.

I have created mycode class for my

..

tag.

Now apply the CSS to your

..

tag for better presentation. First create CSS

tag in between .. tag like below.

     

Now copy the below CSS code and paste it in between

tag.

Step 5. Final Step

Now save your file with any name with .html extension. Like mypage.html. After saving the file open the file by double click on it. It will be open in browser. Now you will see your coding on webpage same as in editor it is.

Output:

    

Campuslife Wesbite

My first page.

Campuslife is a free learning source website for users.

Источник

Display html code in html page

The is the code I'm using : I also used the tag and this script: as shown in this article : How to display raw html code in PRE or something like it but without escaping it, but none of them has worked. JSFiddle Solution 4: First, I want to point out that if you will just copy the element that will throw an error because the copied element will have the same id of the first one, so if you will create a copy of your element you don't have to give it the same id. Try this code: The parameter is the container element of the new Link.

Display html code in html page

I've a contentEditable div, and I want to display the html script for the content of this div. I'm using a bootbox alert to display my code, and the Rainbow Plugin to highlight the syntax.

bootbox.alert('
'+ document.getElementById('editor').innerHTML + '

');

I also used the xmp tag and this script:

as shown in this article : How to display raw html code in PRE or something like it but without escaping it, but none of them has worked.

var encodeHtmlEntity = function(str) < var buf = []; for (var i=str.length-1;i>=0;i--) < buf.unshift(['&#', str[i].charCodeAt(), ';'].join('')); >return buf.join(''); >; bootbox.alert('
'+ encodeHtmlEntity(document.getElementById('editor').innerHTML)) + '

');

Javascript - Display HTML code to plain text, So I want to place the HTML code like the w3schools posted this HTML Example on their page with the all tags and tags are colored. javascript php jquery html. Share . Follow edited Oct 31, 2017 at 21:21. Milos Petrovic. asked Oct 31, 2017 at 15:28. Milos Petrovic Milos Petrovic. 143 1 1 gold badge 2 2 silver …

In some part of an html page, I have a link with the following code :

I would like to automatically display the same link in another part of the same page by using a javascript .

What would be the script to insert in my page ?

Thank you in advance for any help in this matter.

myVar = document.getElementById("idname"); varLink = (myVar.attributes.href); 

As son as you know the target id:

And If you are using jQuery you can do like this:

var link = $("#idname").clone(); link.attr("id",link.attr("id") + (Math.random() * 10)); $("#targetID").append(link); 
var link = document.getElementById("idname"); var newLink = document.createElement("a"); newLink.href = link.href; newLink.className = link.className; newLink.innerHTML = link.innerHTML; newLink.id = link.id + (Math.random() * 10); document.getElementById("targetID2").appendChild(newLink); 

Use code above, if you want just to copy your link to another place. JSFiddle

First, I want to point out that if you will just copy the element that will throw an error because the copied element will have the same id of the first one, so if you will create a copy of your element you don't have to give it the same id.

Try this code:

function copyLink(newDestination)

The newDestination parameter is the container element of the new Link.

For example if the new Container element has the id "div1":

Here's a DEMO .

HTML JavaScript, Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, …

How to display java code in html

how to display java code in html

Javascript - How to display html page from string, var tab = getBrowser ().addTab (); //make new tab getBrowser ().selectedTab = tab; //bring it to front var browser = getBrowser ().getBrowserForTab (tab); //get the window of the tab var newDoc = browser.contentDocument; Now I can do: newDoc.location.href = url; And this …

Источник

Читайте также:  Write string list python
Оцените статью