Welcome to WebmasterWorld Guest from 54.227.52.24

Forum Moderators: lawman

Message Too Old, No Replies

WebmasterWorld code formatting bookmarklet

     

Skier88

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

5+ Year Member



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

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

WebmasterWorld Administrator engine is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Thanks Skier88
 

Featured Threads

Hot Threads This Week

Hot Threads This Month