|
|
Post a Project »
Find a Professional HTML Freelancer!
Find a Freelancer to help you with your HTML projects
| |
|
 |
|
|
|
10-08-2006, 02:19 PM
|
Display code
|
Posts: 151
Name: Ben
|
I want to make tutorials and how tos for HTML and CSS but I can't figure out how to display the code. I have tried the following tags:
Code:
<pre>
<textarea>
<code>
None of them work, the code that I am trying to display is still being rendered. What is wrong all of those tags should work.
|
|
|
|
10-08-2006, 03:33 PM
|
Re: Display code
|
Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
|
__________________
Chris. ->> Please login or register to view this content. Registration is FREE <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
|
|
|
|
10-08-2006, 05:43 PM
|
Re: Display code
|
Posts: 151
Name: Ben
|
That, is not what I am talking about. I want to be able to display code, so readers see the code like you can see this
Code:
<a href="text.html">test</a>
<h1>Blah</h1>
I want my readers to see the actually html code. But I can't figure out how.
|
|
|
|
10-08-2006, 05:48 PM
|
Re: Display code
|
Posts: 10,815
Name: Steven Bradley
Location: Boulder, Colorado
|
You can use the <code></code> tag. You may also need to use < and > for the angle brackets. You may also find using <pre></pre> helpful to keep your formatting.
|
|
|
|
10-08-2006, 05:57 PM
|
Re: Display code
|
Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
|
Quote:
|
Originally Posted by lunchbox170
That, is not what I am talking about
|
Actually it is, which is why I said you need to do the opposite
The other thread is asking how to change the < and > back from < & >
so <h1>Blah</h1> is coded as <h1>Blah</h1>
__________________
Chris. ->> Please login or register to view this content. Registration is FREE <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
|
|
|
|
10-08-2006, 06:30 PM
|
Re: Display code
|
Posts: 151
Name: Ben
|
Oh, you are right, that does work. sorry about that. So there is no easier way, it is a pain to type that.
Thanks
|
|
|
|
10-08-2006, 06:59 PM
|
Re: Display code
|
Posts: 169
|
sure there is... using <code></code> and <pre></pre> as said... 
|
|
|
|
10-08-2006, 08:23 PM
|
Re: Display code
|
Posts: 10,017
Location: Tennessee
|
Why do you want to make yet another html 'how to' site ? There are thousands of them out there already !
__________________
Web Goddess & Web Standards Evangelist :) - Tables Be Gone !!
Please login or register to view this content. Registration is FREE
Please login or register to view this content. Registration is FREE
|
|
|
|
10-08-2006, 08:23 PM
|
Re: Display code
|
Posts: 151
Name: Ben
|
As said, Tried it did not work, it should work, but it doesn't.
|
|
|
|
10-12-2006, 02:55 AM
|
Re: Display code
|
Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
|
Quote:
|
=lunchbox170]So there is no easier way, it is a pain to type that.
|
Yep there is.
You code a server side function to parse the sections of source code when you need to do the replace.
__________________
Chris. ->> Please login or register to view this content. Registration is FREE <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
|
|
|
|
10-12-2006, 07:45 PM
|
Re: Display code
|
Posts: 151
Name: Ben
|
That's not easier
|
|
|
|
10-13-2006, 09:53 AM
|
Re: Display code
|
Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
|
it's definitely simpler, write one function, use it wherever it's required.
This one is in ASP VbScript
Code:
function toCode(strItem)
dim i
'Change code delimiters to HTML entities
strItem = Replace(strItem,"<","<")
strItem = Replace(strItem,">",">")
strItem = Replace(strItem,"%","%")
strItem = replace(strItem,chr(34),""")
toCode = strItem
end function
Use would be
Code:
response.write tocode("<h1>Blah</h1>")
PHP would be
PHP Code:
function toCode($strItem) {
$html = array("<",">",chr(34));
$entities = array("<",">",""");
$strItem = str_replace($html, $entities, $strItem);
return $strItem;
}
Use would be
PHP Code:
echo toCode('<h1>Blah</h1>');
__________________
Chris. ->> Please login or register to view this content. Registration is FREE <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
|
|
|
|
10-13-2006, 10:34 PM
|
Re: Display code
|
Posts: 151
Name: Ben
|
no, that really isn't eaier. You have to remember not everyone knows every thing you do.
What I want to know is why code and pre tag don't work?
|
|
|
|
10-14-2006, 04:19 AM
|
Re: Display code
|
Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
|
Quote:
|
What I want to know is why code and pre tag don't work
|
It's really quite simple.
HTML is a markup language NOT a scripting language.
That is to say it can only change the way the text will look on the page not how the text is sent to the user agent.
Quote:
|
You have to remember not everyone knows every thing you do
|
Yep, which is why I am pointing you to ways you can achieve what you want because HTML alone cannot.
Here is a javascript function to convert the < & > inside a <pre> element to the HTML entities.
Code:
<script type="text/javascript">
function toCode() {
html = new Array(/</g,/>/g);
entities = new Array('<','>');
var codeSect = document.getElementsByTagName('pre');
for (var i=0;i<codeSect.length;i++) {
for (var j=0;j<html.length;j++) {
codeSect[i].innerHTML = codeSect[i].innerHTML.replace(html[j],entities[j]);
}
}
}
</script>
Put the function code inside the <head> or in a linked .js file and use <body onLoad="toCode()"> in the document to run the code.
Bear in mind that some UAs do not execute javascript so will see the formatted element rather than the underlying code.
__________________
Chris. ->> Please login or register to view this content. Registration is FREE <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
|
|
|
|
10-14-2006, 11:21 AM
|
Re: Display code
|
Posts: 151
Name: Ben
|
That didn't work...
It is weird pre and code tag should work, also your thing should have worked, why don't they.
|
|
|
|
10-14-2006, 02:02 PM
|
Re: Display code
|
Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
|
No idea, do we get a URL to look at?
removed server is now down
__________________
Chris. ->> Please login or register to view this content. Registration is FREE <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
Last edited by chrishirst; 08-01-2010 at 05:17 PM..
|
|
|
|
10-14-2006, 05:42 PM
|
Re: Display code
|
Posts: 151
Name: Ben
|
http://www.thelnews.com
I don't have any code to display right now, and I got rid of the Javascript.
|
|
|
|
10-17-2006, 11:29 PM
|
Re: Display code
|
Posts: 118
Name: Brian Collins
|
Here is a html solution that may work for you.
I made a test page and uploaded it to my server and it worked
<form NAME="display code">
<DIV align="center">
<input type=button value="Highlight Your Code" onClick="javascript:this.form.txt.focus();this.for m.txt.select();">
</DIV>
<///-----------------------------------------------------begin code display------------------------------------->
<///---------- every thing between these textarea tags will display as code--------------------------------->
<textarea NAME="txt" ROWS=10 COLS=70 WRAP=VIRTUAL>
<HEAD>
Some html stuff
</HEAD>
<BODY>
<font size="5"> this should do the trick for you</font>
<br><p></p>
any othe html stuff you may need
<p><center>
I think this should work
</center><p><p></p>
</form>
</textarea>
</form>
<///---------------------------------end code display------------------------------------------------->
|
|
|
|
10-18-2006, 02:23 AM
|
Re: Display code
|
Posts: 350
|
You can display the data within a textarea if you assign the value to a variable and echo the variable out in the textarea...
Or just use <xmp>.....
HTML Code:
<xmp><b>Everything will just show out as norma.. code wise.l</b></xmp>
|
|
|
|
|
« Reply to Display code
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|