diff --git a/.gitignore b/.gitignore
index b9518c52..54ebf2d0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
*.swp
.DS_Store
-*.js
-lib/**/*.js
+lib/*
+test/*.js
+test/**/*.js
diff --git a/Cakefile b/Cakefile
index 5ffe7cd4..29574d83 100644
--- a/Cakefile
+++ b/Cakefile
@@ -9,10 +9,14 @@ task 'build', 'Build the .js files', (options) ->
# console.log options
# options.watch ||= no
# exec "coffee --compile #{if options.watch then '--watch' else ''} --output lib/ src/", (err, stdout, stderr) ->
- exec "coffee --compile --output lib/ src/", (err, stdout, stderr) ->
+ exec "coffee --compile --bare --output lib/ src/", (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr
+lib = [
+ 'thirdparty/microevent.js/microevent.js'
+]
+
client = [
'types/text'
'client/opstream'
@@ -26,6 +30,7 @@ e = (str, callback) ->
callback() if callback?
task 'webclient', 'Assemble the web client into one file', ->
- clientfiles = ("src/#{c}.coffee" for c in client).join(' ')
+ clientfiles = ("src/#{c}.coffee" for c in client).join ' '
e "coffee -cj #{clientfiles}", ->
- e 'mv concatenation.js webclient.js'
+ e "cat #{lib.join ' '} concatenation.js >share.js", ->
+ e 'rm concatenation.js'
diff --git a/bin/exampleserver b/bin/exampleserver
new file mode 100755
index 00000000..505dc010
--- /dev/null
+++ b/bin/exampleserver
@@ -0,0 +1,37 @@
+#!/usr/bin/env coffee
+
+connect = require 'connect'
+sharejs = require '../lib/server'
+sys = require 'sys'
+fs = require 'fs'
+renderer = require '../examples/_static'
+wiki = require '../examples/_wiki'
+
+server = connect(
+ connect.logger(),
+ connect.static(__dirname + '/../examples'),
+ connect.router (app) ->
+ app.get '/share.js', (req, res) ->
+ clientsrc = fs.readFileSync __dirname + '/../share.js', 'utf8'
+ res.setHeader 'content-type', 'application/javascript'
+ res.end clientsrc
+
+ app.get '/static/:docName', (req, res, next) ->
+ docName = req.params.docName
+ renderer docName, server.model, res, next
+
+ app.get '/wiki/:docName', (req, res, next) ->
+ docName = "wiki:#{req.params.docName}"
+ wiki docName, server.model, res, next
+
+)
+
+# Maybe... don't use the real config here?
+config = fs.readFileSync require.resolve('./sharejs.json'), 'utf8'
+options = JSON.parse config
+
+# Attach the sharejs REST and Socket.io interfaces to the server
+sharejs.attach server, options
+
+server.listen 8000
+sys.puts 'Server running at http://127.0.0.1:8000/'
diff --git a/bin/sharejs b/bin/sharejs
new file mode 100755
index 00000000..c585507a
--- /dev/null
+++ b/bin/sharejs
@@ -0,0 +1,18 @@
+#!/usr/bin/env node
+
+var connect = require('connect'),
+ sharejs = require('../lib/server'),
+ sys = require('sys'),
+ fs = require('fs'),
+ server;
+
+server = connect(connect.logger());
+
+config = fs.readFileSync(require.resolve('./sharejs.json'), 'utf8');
+options = JSON.parse(config);
+
+// Attach the sharejs REST and Socket.io interfaces to the server
+sharejs.attach(server, options);
+
+server.listen(8000);
+sys.puts('Server running at http://127.0.0.1:8000/');
diff --git a/bin/sharejs.json b/bin/sharejs.json
new file mode 100644
index 00000000..0967ef42
--- /dev/null
+++ b/bin/sharejs.json
@@ -0,0 +1 @@
+{}
diff --git a/examples/README.md b/examples/README.md
new file mode 100644
index 00000000..e53d30c2
--- /dev/null
+++ b/examples/README.md
@@ -0,0 +1,50 @@
+This is a bunch of little demo apps using Share.js.
+
+Launch the example sharejs server with
+
+ % bin/exampleserver
+
+
+readonly
+--------
+
+Two little demos of live viewers for sharejs documents.
+
+Browse to http://localhost:8000/readonly/html.html
+and http://localhost:8000/readonly/markdown.html
+
+### html
+
+Dynamically update html content as a document changes
+
+### markdown
+
+Dynamically render markdown as a document is edited.
+
+
+ace
+---
+
+The ace editor live editing a sharejs document.
+
+Browse to http://localhost:8000/ace/
+
+
+staticrender
+------------
+
+This directory has a little mustache template rendering engine to do server-side rendering of documents.
+
+Access the rendered documents at http://localhost:8000/static/DOCNAME
+
+Eg: http://localhost:8000/static/html
+
+Some of the logic to wire this demo up is in `bin/exampleserver`. You should have a read.
+
+The documents are rendered statically on the server, so they don't update when as you edit them. You could obviously mix in the code from the html demo to make this also re-render as the document changes.
+
+
+wiki
+----
+
+A more complicated demo showing a wiki.
diff --git a/examples/_static/README.md b/examples/_static/README.md
new file mode 100644
index 00000000..49c8679d
--- /dev/null
+++ b/examples/_static/README.md
@@ -0,0 +1,8 @@
+This is a simple static renderer which uses mustache to render out an HTML page
+from the document named on the URL path.
+
+Access this demo by browsing to:
+/static/DOCNAME
+from your server.
+
+(Eg, try /static/html)
diff --git a/examples/_static/index.coffee b/examples/_static/index.coffee
new file mode 100644
index 00000000..675d3829
--- /dev/null
+++ b/examples/_static/index.coffee
@@ -0,0 +1,20 @@
+# This statically renders the document.
+
+fs = require 'fs'
+Mustache = try
+ require 'mustache'
+catch e
+ {to_html: -> "
% npm install mustache
to use this demo."}
+
+template = fs.readFileSync "#{__dirname}/template.html.mu", 'utf8'
+
+module.exports = (docName, model, res, next) ->
+ model.getSnapshot docName, (data) ->
+ if data.v == 0
+ # The document does not exist
+ next()
+ else
+ html = Mustache.to_html template, {content:data.snapshot, docName}
+ res.writeHead 200, {'content-type': 'text/html'}
+ res.end html
+
diff --git a/examples/_static/template.html.mu b/examples/_static/template.html.mu
new file mode 100644
index 00000000..2d066f11
--- /dev/null
+++ b/examples/_static/template.html.mu
@@ -0,0 +1,11 @@
+
+
+ {{docName}}
+
+
+
+
+
{{{content}}}
+
+
+
diff --git a/examples/_wiki/index.coffee b/examples/_wiki/index.coffee
new file mode 100644
index 00000000..7d3262b8
--- /dev/null
+++ b/examples/_wiki/index.coffee
@@ -0,0 +1,42 @@
+# This statically renders the wiki.
+
+fs = require 'fs'
+Mustache = try
+ require 'mustache'
+catch e
+ {to_html: -> "
% npm install mustache
to use this demo."}
+
+showdown = new (require('../lib/markdown/showdown').converter)()
+
+template = fs.readFileSync "#{__dirname}/wiki.html.mu", 'utf8'
+
+defaultContent = '''
+# Wowsers
+
+This wiki page is currently empty.
+
+You can put some content in it with the editor on the right. As you do so, the document will update live on the left, and live for everyone else editing at the same time as you. Isn't that cool?
+
+The text on the left is being rendered with markdown, so you can do all the usual markdown stuff like:
+
+- Bullet
+ - Points
+
+[links](http://google.com)
+
+[Go back to the main page](Main)
+'''
+
+module.exports = (docName, model, res) ->
+ model.getSnapshot docName, (data) ->
+ if data.v == 0
+ model.applyOp docName, {op:{type:'text'}, v:0}
+ model.applyOp docName, {op:[{i:defaultContent, p:0}], v:1}
+
+ content = data.snapshot || ''
+ markdown = showdown.makeHtml content
+ console.log markdown
+ html = Mustache.to_html template, {content, markdown, docName}
+ res.writeHead 200, {'content-type': 'text/html'}
+ res.end html
+
diff --git a/examples/_wiki/wiki.html.mu b/examples/_wiki/wiki.html.mu
new file mode 100644
index 00000000..c38f6ea5
--- /dev/null
+++ b/examples/_wiki/wiki.html.mu
@@ -0,0 +1,81 @@
+
+
+
+
+
+
+
+
+
{{{markdown}}}
+
+
{{{content}}}
+
+
+
+
+
+
+
+
+
diff --git a/examples/ace.html b/examples/ace/index.html
similarity index 55%
rename from examples/ace.html
rename to examples/ace/index.html
index 604afaca..8716c7a6 100644
--- a/examples/ace.html
+++ b/examples/ace/index.html
@@ -17,31 +17,30 @@
-
s around
+ // "paragraphs" that are wrapped in non-block-level tags, such as anchors,
+ // phrase emphasis, and spans. The list of tags we're looking for is
+ // hard-coded:
+ var block_tags_a = "p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del"
+ var block_tags_b = "p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math"
+
+ // First, look for nested blocks, e.g.:
+ //
+ //
+ // tags for inner block must be indented.
+ //
+ //
+ //
+ // The outermost tags must start at the left margin for this to match, and
+ // the inner nested divs must be indented.
+ // We need to do this before the next, more liberal match, because the next
+ // match will start at the first `
` and stop at the first `
`.
+
+ // attacklab: This regex can be expensive when it fails.
+ /*
+ var text = text.replace(/
+ ( // save in $1
+ ^ // start of line (with /m)
+ <($block_tags_a) // start tag = $2
+ \b // word break
+ // attacklab: hack around khtml/pcre bug...
+ [^\r]*?\n // any number of lines, minimally matching
+ \2> // the matching end tag
+ [ \t]* // trailing spaces/tabs
+ (?=\n+) // followed by a newline
+ ) // attacklab: there are sentinel newlines at end of document
+ /gm,function(){...}};
+ */
+ text = text.replace(/^(<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del)\b[^\r]*?\n<\/\2>[ \t]*(?=\n+))/gm,hashElement);
+
+ //
+ // Now match more liberally, simply from `\n` to `\n`
+ //
+
+ /*
+ var text = text.replace(/
+ ( // save in $1
+ ^ // start of line (with /m)
+ <($block_tags_b) // start tag = $2
+ \b // word break
+ // attacklab: hack around khtml/pcre bug...
+ [^\r]*? // any number of lines, minimally matching
+ .*\2> // the matching end tag
+ [ \t]* // trailing spaces/tabs
+ (?=\n+) // followed by a newline
+ ) // attacklab: there are sentinel newlines at end of document
+ /gm,function(){...}};
+ */
+ text = text.replace(/^(<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math)\b[^\r]*?.*<\/\2>[ \t]*(?=\n+)\n)/gm,hashElement);
+
+ // Special case just for . It was easier to make a special case than
+ // to make the other regex more complicated.
+
+ /*
+ text = text.replace(/
+ ( // save in $1
+ \n\n // Starting after a blank line
+ [ ]{0,3}
+ (<(hr) // start tag = $2
+ \b // word break
+ ([^<>])*? //
+ \/?>) // the matching end tag
+ [ \t]*
+ (?=\n{2,}) // followed by a blank line
+ )
+ /g,hashElement);
+ */
+ text = text.replace(/(\n[ ]{0,3}(<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g,hashElement);
+
+ // Special case for standalone HTML comments:
+
+ /*
+ text = text.replace(/
+ ( // save in $1
+ \n\n // Starting after a blank line
+ [ ]{0,3} // attacklab: g_tab_width - 1
+
+ [ \t]*
+ (?=\n{2,}) // followed by a blank line
+ )
+ /g,hashElement);
+ */
+ text = text.replace(/(\n\n[ ]{0,3}[ \t]*(?=\n{2,}))/g,hashElement);
+
+ // PHP and ASP-style processor instructions (...?> and <%...%>)
+
+ /*
+ text = text.replace(/
+ (?:
+ \n\n // Starting after a blank line
+ )
+ ( // save in $1
+ [ ]{0,3} // attacklab: g_tab_width - 1
+ (?:
+ <([?%]) // $2
+ [^\r]*?
+ \2>
+ )
+ [ \t]*
+ (?=\n{2,}) // followed by a blank line
+ )
+ /g,hashElement);
+ */
+ text = text.replace(/(?:\n\n)([ ]{0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g,hashElement);
+
+ // attacklab: Undo double lines (see comment at top of this function)
+ text = text.replace(/\n\n/g,"\n");
+ return text;
+}
+
+var hashElement = function(wholeMatch,m1) {
+ var blockText = m1;
+
+ // Undo double lines
+ blockText = blockText.replace(/\n\n/g,"\n");
+ blockText = blockText.replace(/^\n/,"");
+
+ // strip trailing blank lines
+ blockText = blockText.replace(/\n+$/g,"");
+
+ // Replace the element text with a marker ("~KxK" where x is its key)
+ blockText = "\n\n~K" + (g_html_blocks.push(blockText)-1) + "K\n\n";
+
+ return blockText;
+};
+
+var _RunBlockGamut = function(text) {
+//
+// These are all the transformations that form block-level
+// tags like paragraphs, headers, and list items.
+//
+ text = _DoHeaders(text);
+
+ // Do Horizontal Rules:
+ var key = hashBlock("");
+ text = text.replace(/^[ ]{0,2}([ ]?\*[ ]?){3,}[ \t]*$/gm,key);
+ text = text.replace(/^[ ]{0,2}([ ]?\-[ ]?){3,}[ \t]*$/gm,key);
+ text = text.replace(/^[ ]{0,2}([ ]?\_[ ]?){3,}[ \t]*$/gm,key);
+
+ text = _DoLists(text);
+ text = _DoCodeBlocks(text);
+ text = _DoBlockQuotes(text);
+
+ // We already ran _HashHTMLBlocks() before, in Markdown(), but that
+ // was to escape raw HTML in the original Markdown source. This time,
+ // we're escaping the markup we've just created, so that we don't wrap
+ //
");});
+
+ // atx-style headers:
+ // # Header 1
+ // ## Header 2
+ // ## Header 2 with closing hashes ##
+ // ...
+ // ###### Header 6
+ //
+
+ /*
+ text = text.replace(/
+ ^(\#{1,6}) // $1 = string of #'s
+ [ \t]*
+ (.+?) // $2 = Header text
+ [ \t]*
+ \#* // optional closing #'s (not counted)
+ \n+
+ /gm, function() {...});
+ */
+
+ text = text.replace(/^(\#{1,6})[ \t]*(.+?)[ \t]*\#*\n+/gm,
+ function(wholeMatch,m1,m2) {
+ var h_level = m1.length;
+ return hashBlock("" + _RunSpanGamut(m2) + "");
+ });
+
+ return text;
+}
+
+// This declaration keeps Dojo compressor from outputting garbage:
+var _ProcessListItems;
+
+var _DoLists = function(text) {
+//
+// Form HTML ordered (numbered) and unordered (bulleted) lists.
+//
+
+ // attacklab: add sentinel to hack around khtml/safari bug:
+ // http://bugs.webkit.org/show_bug.cgi?id=11231
+ text += "~0";
+
+ // Re-usable pattern to match any entirel ul or ol list:
+
+ /*
+ var whole_list = /
+ ( // $1 = whole list
+ ( // $2
+ [ ]{0,3} // attacklab: g_tab_width - 1
+ ([*+-]|\d+[.]) // $3 = first list item marker
+ [ \t]+
+ )
+ [^\r]+?
+ ( // $4
+ ~0 // sentinel for workaround; should be $
+ |
+ \n{2,}
+ (?=\S)
+ (?! // Negative lookahead for another list item marker
+ [ \t]*
+ (?:[*+-]|\d+[.])[ \t]+
+ )
+ )
+ )/g
+ */
+ var whole_list = /^(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm;
+
+ if (g_list_level) {
+ text = text.replace(whole_list,function(wholeMatch,m1,m2) {
+ var list = m1;
+ var list_type = (m2.search(/[*+-]/g)>-1) ? "ul" : "ol";
+
+ // Turn double returns into triple returns, so that we can make a
+ // paragraph for the last item in a list, if necessary:
+ list = list.replace(/\n{2,}/g,"\n\n\n");;
+ var result = _ProcessListItems(list);
+
+ // Trim any trailing whitespace, to put the closing `$list_type>`
+ // up on the preceding line, to get it past the current stupid
+ // HTML block parser. This is a hack to work around the terrible
+ // hack that is the HTML block parser.
+ result = result.replace(/\s+$/,"");
+ result = "<"+list_type+">" + result + ""+list_type+">\n";
+ return result;
+ });
+ } else {
+ whole_list = /(\n\n|^\n?)(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/g;
+ text = text.replace(whole_list,function(wholeMatch,m1,m2,m3) {
+ var runup = m1;
+ var list = m2;
+
+ var list_type = (m3.search(/[*+-]/g)>-1) ? "ul" : "ol";
+ // Turn double returns into triple returns, so that we can make a
+ // paragraph for the last item in a list, if necessary:
+ var list = list.replace(/\n{2,}/g,"\n\n\n");;
+ var result = _ProcessListItems(list);
+ result = runup + "<"+list_type+">\n" + result + ""+list_type+">\n";
+ return result;
+ });
+ }
+
+ // attacklab: strip sentinel
+ text = text.replace(/~0/,"");
+
+ return text;
+}
+
+_ProcessListItems = function(list_str) {
+//
+// Process the contents of a single ordered or unordered list, splitting it
+// into individual list items.
+//
+ // The $g_list_level global keeps track of when we're inside a list.
+ // Each time we enter a list, we increment it; when we leave a list,
+ // we decrement. If it's zero, we're not in a list anymore.
+ //
+ // We do this because when we're not inside a list, we want to treat
+ // something like this:
+ //
+ // I recommend upgrading to version
+ // 8. Oops, now this line is treated
+ // as a sub-list.
+ //
+ // As a single paragraph, despite the fact that the second line starts
+ // with a digit-period-space sequence.
+ //
+ // Whereas when we're inside a list (or sub-list), that line will be
+ // treated as the start of a sub-list. What a kludge, huh? This is
+ // an aspect of Markdown's syntax that's hard to parse perfectly
+ // without resorting to mind-reading. Perhaps the solution is to
+ // change the syntax rules such that sub-lists must start with a
+ // starting cardinal number; e.g. "1." or "a.".
+
+ g_list_level++;
+
+ // trim trailing blank lines:
+ list_str = list_str.replace(/\n{2,}$/,"\n");
+
+ // attacklab: add sentinel to emulate \z
+ list_str += "~0";
+
+ /*
+ list_str = list_str.replace(/
+ (\n)? // leading line = $1
+ (^[ \t]*) // leading whitespace = $2
+ ([*+-]|\d+[.]) [ \t]+ // list marker = $3
+ ([^\r]+? // list item text = $4
+ (\n{1,2}))
+ (?= \n* (~0 | \2 ([*+-]|\d+[.]) [ \t]+))
+ /gm, function(){...});
+ */
+ list_str = list_str.replace(/(\n)?(^[ \t]*)([*+-]|\d+[.])[ \t]+([^\r]+?(\n{1,2}))(?=\n*(~0|\2([*+-]|\d+[.])[ \t]+))/gm,
+ function(wholeMatch,m1,m2,m3,m4){
+ var item = m4;
+ var leading_line = m1;
+ var leading_space = m2;
+
+ if (leading_line || (item.search(/\n{2,}/)>-1)) {
+ item = _RunBlockGamut(_Outdent(item));
+ }
+ else {
+ // Recursion for sub-lists:
+ item = _DoLists(_Outdent(item));
+ item = item.replace(/\n$/,""); // chomp(item)
+ item = _RunSpanGamut(item);
+ }
+
+ return "
` blocks.
+//
+
+ /*
+ text = text.replace(text,
+ /(?:\n\n|^)
+ ( // $1 = the code block -- one or more lines, starting with a space/tab
+ (?:
+ (?:[ ]{4}|\t) // Lines must start with a tab or a tab-width of spaces - attacklab: g_tab_width
+ .*\n+
+ )+
+ )
+ (\n*[ ]{0,3}[^ \t\n]|(?=~0)) // attacklab: g_tab_width
+ /g,function(){...});
+ */
+
+ // attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug
+ text += "~0";
+
+ text = text.replace(/(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=~0))/g,
+ function(wholeMatch,m1,m2) {
+ var codeblock = m1;
+ var nextChar = m2;
+
+ codeblock = _EncodeCode( _Outdent(codeblock));
+ codeblock = _Detab(codeblock);
+ codeblock = codeblock.replace(/^\n+/g,""); // trim leading newlines
+ codeblock = codeblock.replace(/\n+$/g,""); // trim trailing whitespace
+
+ codeblock = "
" + codeblock + "\n
";
+
+ return hashBlock(codeblock) + nextChar;
+ }
+ );
+
+ // attacklab: strip sentinel
+ text = text.replace(/~0/,"");
+
+ return text;
+}
+
+var hashBlock = function(text) {
+ text = text.replace(/(^\n+|\n+$)/g,"");
+ return "\n\n~K" + (g_html_blocks.push(text)-1) + "K\n\n";
+}
+
+
+var _DoCodeSpans = function(text) {
+//
+// * Backtick quotes are used for spans.
+//
+// * You can use multiple backticks as the delimiters if you want to
+// include literal backticks in the code span. So, this input:
+//
+// Just type ``foo `bar` baz`` at the prompt.
+//
+// Will translate to:
+//
+//
Just type foo `bar` baz at the prompt.
+//
+// There's no arbitrary limit to the number of backticks you
+// can use as delimters. If you need three consecutive backticks
+// in your code, use four for delimiters, etc.
+//
+// * You can use spaces to get literal backticks at the edges:
+//
+// ... type `` `bar` `` ...
+//
+// Turns to:
+//
+// ... type `bar` ...
+//
+
+ /*
+ text = text.replace(/
+ (^|[^\\]) // Character before opening ` can't be a backslash
+ (`+) // $2 = Opening run of `
+ ( // $3 = The code block
+ [^\r]*?
+ [^`] // attacklab: work around lack of lookbehind
+ )
+ \2 // Matching closer
+ (?!`)
+ /gm, function(){...});
+ */
+
+ text = text.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,
+ function(wholeMatch,m1,m2,m3,m4) {
+ var c = m3;
+ c = c.replace(/^([ \t]*)/g,""); // leading whitespace
+ c = c.replace(/[ \t]*$/g,""); // trailing whitespace
+ c = _EncodeCode(c);
+ return m1+""+c+"";
+ });
+
+ return text;
+}
+
+
+var _EncodeCode = function(text) {
+//
+// Encode/escape certain characters inside Markdown code runs.
+// The point is that in code, these characters are literals,
+// and lose their special Markdown meanings.
+//
+ // Encode all ampersands; HTML entities are not
+ // entities within a Markdown code span.
+ text = text.replace(/&/g,"&");
+
+ // Do the angle bracket song and dance:
+ text = text.replace(//g,">");
+
+ // Now, escape characters that are magic in Markdown:
+ text = escapeCharacters(text,"\*_{}[]\\",false);
+
+// jj the line above breaks this:
+//---
+
+//* Item
+
+// 1. Subitem
+
+// special char: *
+//---
+
+ return text;
+}
+
+
+var _DoItalicsAndBold = function(text) {
+
+ // must go first:
+ text = text.replace(/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g,
+ "$2");
+
+ text = text.replace(/(\w)_(\w)/g, "$1~E95E$2") // ** GFM ** "~E95E" == escaped "_"
+ text = text.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g,
+ "$2");
+
+ return text;
+}
+
+
+var _DoBlockQuotes = function(text) {
+
+ /*
+ text = text.replace(/
+ ( // Wrap whole match in $1
+ (
+ ^[ \t]*>[ \t]? // '>' at the start of a line
+ .+\n // rest of the first line
+ (.+\n)* // subsequent consecutive lines
+ \n* // blanks
+ )+
+ )
+ /gm, function(){...});
+ */
+
+ text = text.replace(/((^[ \t]*>[ \t]?.+\n(.+\n)*\n*)+)/gm,
+ function(wholeMatch,m1) {
+ var bq = m1;
+
+ // attacklab: hack around Konqueror 3.5.4 bug:
+ // "----------bug".replace(/^-/g,"") == "bug"
+
+ bq = bq.replace(/^[ \t]*>[ \t]?/gm,"~0"); // trim one level of quoting
+
+ // attacklab: clean up hack
+ bq = bq.replace(/~0/g,"");
+
+ bq = bq.replace(/^[ \t]+$/gm,""); // trim whitespace-only lines
+ bq = _RunBlockGamut(bq); // recurse
+
+ bq = bq.replace(/(^|\n)/g,"$1 ");
+ // These leading spaces screw with
content, so we need to fix that:
+ bq = bq.replace(
+ /(\s*
[^\r]+?<\/pre>)/gm,
+ function(wholeMatch,m1) {
+ var pre = m1;
+ // attacklab: hack around Konqueror 3.5.4 bug:
+ pre = pre.replace(/^ /mg,"~0");
+ pre = pre.replace(/~0/g,"");
+ return pre;
+ });
+
+ return hashBlock("
\n" + bq + "\n
");
+ });
+ return text;
+}
+
+
+var _FormParagraphs = function(text) {
+//
+// Params:
+// $text - string to process with html
tags
+//
+
+ // Strip leading and trailing lines:
+ text = text.replace(/^\n+/g,"");
+ text = text.replace(/\n+$/g,"");
+
+ var grafs = text.split(/\n{2,}/g);
+ var grafsOut = new Array();
+
+ //
+ // Wrap