homepage Welcome to WebmasterWorld Guest from 54.237.54.83
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Local / WebmasterWorld Community Center
Forum Library, Charter, Moderators: lawman

WebmasterWorld Community Center Forum

    
WebmasterWorld code formatting bookmarklet
Skier88




msg:4393735
 4:30 am on Dec 3, 2011 (gmt 0)

Hi, I just thought I'd share a bookmarklet I wrote to make code I post to webmasterworld a litter clearer.

Currently, wrapping code in "code" tags results in something like this:

<!doctype html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<title>example page</title>
<style type='text/css'>
* {margin:0; padding:0;}
body {font:13px/1.231 arial,sans-serif;}
p {margin:10px 0;}
</style>
</head>
<body>
<p>Hello world.</p>
</body>
</html>


By adding a few other tags and careful spacing, you can get this:
<!doctype html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<title>example page</title>
<style type='text/css'>
* {margin:0; padding:0;}
body {font:13px/1.231 arial,sans-serif;}
p {margin:10px 0;}
</style>
</head>
<body>
<p>Hello world.</p>
</body>
</html>

This bookmarklet makes that transformation automatically. Just:
  1. Type your post, surrounding code with "code" tags.
  2. Click the bookmarklet.
  3. Submit.
Note that webmasterworld deletes some of the spacing, so if you want to edit your post you'll have to use the text you submitted, not the text that appears when you click "edit".

Here's the bookmarklet; be sure to delete the space in "[/co de]" before using.
javascript:(function(e){(e&&e.tagName=='TEXTAREA')?e.value=e.value.replace(/\[code\]\s*((.|\s)*?)\s*\[\/code\]\r?\n?/g,function(m,c){return'[quote][pre][code]'+c.replace(/( {2,})/g,'$1$1')+'[/co de][/pre][/quote]'}):alert('Error: document structure is not recognized.')})(document.getElementsByName('post_content')[0]);

If you encounter any bugs, or want me to add something, please say so and I'll see what I can do.

 

engine




msg:4394356
 12:24 pm on Dec 5, 2011 (gmt 0)

Thanks Skier88

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Local / WebmasterWorld Community Center
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved