HTML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignHTML Programming
Receive the tools necessary to be the rock star of your field. Our 12-month program teaches you the evolving world of multi-channel marketing as well as the complex issues and opportunities found in the industry.

ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month!
Download and Activate to enter!

Web development can be a daunting task, even for specialists. There is a lot of information to absorb and a lot of technologies to learn in order to manage a superior website. When trying to learn the ropes, developers need a reliable source to introduce new ideas that can be easily implemented. When working on large projects, even web veterans may run into a technology or an aspect of a technology that they are unfamiliar with.

Learn More!


Download to Enter
| Contest Rules

Tutorials | Forums

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 6th, 2012, 07:26 PM
Mike001 Mike001 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2012
Posts: 3 Mike001 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 54 sec
Reputation Power: 0
New Member - Entering a Code Snippet in HTML

I am setting up a web page that will show code examples when a button is selected.

I am not certain the best way to enter these examples in HTML. I have tried using the code element but when I view the page in the browser it treats the code examples as if they were HTML elements and they do not show.

What is the best way to enter code examples in an HTML document.

Thank you for any help.

Mike

Reply With Quote
  #2  
Old February 6th, 2012, 10:25 PM
Catacaustic's Avatar
Catacaustic Catacaustic is online now
Code Monkey V. 0.9
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Mar 2005
Location: A Land Down Under
Posts: 1,660 Catacaustic User rank is General 10th Grade (Above 100000 Reputation Level)Catacaustic User rank is General 10th Grade (Above 100000 Reputation Level)Catacaustic User rank is General 10th Grade (Above 100000 Reputation Level)Catacaustic User rank is General 10th Grade (Above 100000 Reputation Level)Catacaustic User rank is General 10th Grade (Above 100000 Reputation Level)Catacaustic User rank is General 10th Grade (Above 100000 Reputation Level)Catacaustic User rank is General 10th Grade (Above 100000 Reputation Level)Catacaustic User rank is General 10th Grade (Above 100000 Reputation Level)Catacaustic User rank is General 10th Grade (Above 100000 Reputation Level)Catacaustic User rank is General 10th Grade (Above 100000 Reputation Level)Catacaustic User rank is General 10th Grade (Above 100000 Reputation Level)Catacaustic User rank is General 10th Grade (Above 100000 Reputation Level)Catacaustic User rank is General 10th Grade (Above 100000 Reputation Level)Catacaustic User rank is General 10th Grade (Above 100000 Reputation Level)Catacaustic User rank is General 10th Grade (Above 100000 Reputation Level)Catacaustic User rank is General 10th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 2 m 8 sec
Reputation Power: 1642
That should be easy enough to do. All that it takes is making sure that you don't use any special HTML characters like < or > in your code samples. When you do need to use them, make sure that you change them all to their proper HTML equivalent.
Code:
"<" becomes "&lt;"
">" becomes "&gt;"
etc...

Last edited by Catacaustic : February 6th, 2012 at 10:28 PM.

Reply With Quote
  #3  
Old February 7th, 2012, 12:48 PM
Mike001 Mike001 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2012
Posts: 3 Mike001 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 54 sec
Reputation Power: 0
Catacaustic

Thanks for the reply. I had already implemented character entities for the couple of pages that I tested on.

I was looking to see if there is a better and quicker way to enter the codes as I have hundreds of pages to setup with the code strings in them.

I may use popups with the code sheets entered as a png graphics file. This way I can keep the color coding, use the special characters and not have to enter all the input by hand. I am still debating how the best way is to enter these.

Thanks again for the reply.

Mike

Reply With Quote
  #4  
Old February 7th, 2012, 02:32 PM
Kravvitz's Avatar
Kravvitz Kravvitz is offline
CSS & JS/DOM Adept
Dev Shed God 29th Plane (19000 - 19499 posts)
 
Join Date: Jul 2004
Location: USA
Posts: 19,134 Kravvitz User rank is General 41st Grade (Above 100000 Reputation Level)Kravvitz User rank is General 41st Grade (Above 100000 Reputation Level)Kravvitz User rank is General 41st Grade (Above 100000 Reputation Level)Kravvitz User rank is General 41st Grade (Above 100000 Reputation Level)Kravvitz User rank is General 41st Grade (Above 100000 Reputation Level)Kravvitz User rank is General 41st Grade (Above 100000 Reputation Level)Kravvitz User rank is General 41st Grade (Above 100000 Reputation Level)Kravvitz User rank is General 41st Grade (Above 100000 Reputation Level)Kravvitz User rank is General 41st Grade (Above 100000 Reputation Level)Kravvitz User rank is General 41st Grade (Above 100000 Reputation Level)Kravvitz User rank is General 41st Grade (Above 100000 Reputation Level)Kravvitz User rank is General 41st Grade (Above 100000 Reputation Level)Kravvitz User rank is General 41st Grade (Above 100000 Reputation Level)Kravvitz User rank is General 41st Grade (Above 100000 Reputation Level)Kravvitz User rank is General 41st Grade (Above 100000 Reputation Level)Kravvitz User rank is General 41st Grade (Above 100000 Reputation Level) 
Time spent in forums: 5 Months 1 Week 6 Days 2 h 38 m 32 sec
Reputation Power: 3755
Welcome to DevShed Forums, Mike001.

Quote:
Originally Posted by Mike001
I may use popups with the code sheets entered as a png graphics file. This way I can keep the color coding, use the special characters and not have to enter all the input by hand. I am still debating how the best way is to enter these.

So nobody can copy and paste the code? I'd recommend using a JavaScript script to add the color coding (aka syntax highlighting).

Quote:
Originally Posted by Mike001
I was looking to see if there is a better and quicker way to enter the codes as I have hundreds of pages to setup with the code strings in them.

I'd recommend that you use a script to automate the replacement of the special characters with character entities. Here's a script that I wrote for that purpose several years ago:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title></title>
<style type="text/css">
form>div {
  float: left;
  text-align: center;
}
textarea {
  display: block;
}
</style>
<script type="text/javascript"><!--
function addRemoveMsg(msgId,parent,textToAdd) {
  if(!document.getElementById || !document.createElement) return;
  var el;
  if(!textToAdd && msgId && document.getElementById(msgId)) {
    el = document.getElementById(msgId);
    el.parentNode.removeChild(el);
  } else if(textToAdd && msgId && parent) {
    el = document.createElement('div');
    el.id = msgId;
    el.appendChild(document.createTextNode(textToAdd));
    parent.appendChild(el);
  }
}
window.onload = function() {
  document.form1.onsubmit = function() {
    var el=document.form1.ta1;
    var addCodeTags = document.form1.addCodeTags.checked;
    var doubleQuote = document.form1.doubleQuote.checked;
    
    if(el.parentNode) {
      window.tempEl = el.parentNode;
      setTimeout("addRemoveMsg('msgSpan1',tempEl,'running...')",1);
    }
    var str=el.value;
    str=str.replace(/>/g,'>');
    str=str.replace(/</g,'<');
    str=str.replace(/&/g,'&');
    if(doubleQuote) str=str.replace(/"/g,'"');
    str=str.replace(/&(([a-z]{2,16})|(\#x[a-z0-9]{2,5})|(\#[0-9]{2,5}));/ig,
      '&$1;');
    if(addCodeTags) {
      str=str.replace(/>/g,'></code>');
      str=str.replace(/</g,'<code><');
    }
    el.value=str;
    if(el.parentNode) {
      setTimeout("addRemoveMsg('msgSpan1')",500);
    }

    return false;
  }
}
// -->
</script>
</head>
<body>

<form name="form1" action="#"><div>
<textarea name="ta1" id="ta1" rows="20" cols="60"></textarea>
<label>Add <code><code></code> elements? <input type="checkbox" 
name="addCodeTags" value="yes"></label><br>
<label>Convert double-quote characters to <code>&quot;</code>? <input type="checkbox" 
name="doubleQuote" value="yes" checked="checked"></label><br>
<input type="submit" value="Submit">
<input type="reset" value="Clear the text">

</div></form>

</body>
</html>
__________________
Spreading knowledge, one newbie at a time. I'm available for hire at Dynamic Site Solutions.

Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

Remember people spend most of their time on other people's sites (so don't violate web design conventions).

Reply With Quote
  #5  
Old February 7th, 2012, 08:05 PM
Mike001 Mike001 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2012
Posts: 3 Mike001 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 54 sec
Reputation Power: 0
Kravvitz

Now that is very cool. I had not thought about using JavaScript to parse through the entry.

I will try it in the morning and let you know how it worked.

Thanks for the great idea.

Mike

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignHTML Programming > New Member - Entering a Code Snippet in HTML


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate 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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.

© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 8 - Follow our Sitemap