/    Sign up×
Community /Pin to ProfileBookmark

Format HTML code

Hi. I have the following script on my page

[code=html]<script type=”text/javascript”>
<!–

escapeHTML(‘<ul id=”nav”><li><a href=”http://www.google.com”>text</a><ul><li><a href=”http://www.google.com”>text</a> <ul><li><a href=”http://www.google.com”>text</a></li></ul></li></ul></li></ul>’);

function escapeHTML(text) {
text = text.replace(new RegExp(/</g),”&lt”)
text = text.replace(new RegExp(/>/g),”&gt”)
document.writeln( text.toLowerCase() );
}
//–>
</script>[/code]

The idea is to write the HTML code for a bulleted list to a page without actually rendering it.

This code works great except the written results are all on one line. What i need is for the results to be indented as if i were writing it in an editor. i.e.

[code=html]<ul id=”nav”>
<li><a href=”http://www.google.com”>text</a>
<ul>
<li><a href=”http://www.google.com”>text</a>
<ul>
<li><a href=”http://www.google.com”>text</a></li>
</ul>
</li>
</ul>
</li>
</ul>[/code]

The only caveat is – i cannot change the string that is passed to the escapeHTML function in any way. Can this be done?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Typhoon101authorSep 11.2006 — Bump!!! :o
×

Success!

Help @Typhoon101 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...