'use strict';

var plugins = module.parent.require('./plugins'),
	fs = require('fs'),
	path = require('path'),
	util = require('util'),
	app;

var plugin = {};

plugin.parse = function(data, callback) {

	if (data && typeof data === 'string') {
		// preview
		data = parser(data);
	} else if (data.postData && data.postData.content) {
		// post
		data.postData.content = parser(data.postData.content);
	} else if (data.userData && data.userData.signature) {
		// signature
		data.userData.signature = parser(data.userData.signature);
	}

	callback(null, data);
}

// replace [spoiler] fake tags with real tags
function parser(data) {
	data = data
		.replace('[spoiler]', '<span class="spoiler blur" onclick="toggleBlur(this);">')
		.replace('[/spoiler]', '</span>');
	return data;
}

module.exports = plugin;

@@ -655,16 +655,94 @@
 ata) %7B%0D%0A
+%09// replace inline spoilers%0D%0A%09var spoilers = /%5C%5Bspoiler%5C%5D.*?%5C%5B%5C/spoiler%5C%5D/g;%0D%0A
 %09data = 
@@ -745,20 +745,16 @@
 a = data
-%0D%0A%09%09
 .replace
@@ -758,20 +758,45 @@
 ace(
-'%5B
 spoiler
-%5D',
+s, function(match) %7B%0D%0A%09%09return
  '%3Cs
@@ -853,13 +853,114 @@
 ;%22%3E'
-)%0D%0A%09%09
+ + match.substring(9, match.length - 10) + '%3C/span%3E';%0D%0A%09%7D);%0D%0A%09// replace multi-line spoilers%0D%0A%09data = data
 .rep
@@ -966,17 +966,16 @@
 place('%5B
-/
 spoiler%5D
@@ -979,21 +979,100 @@
 er%5D', '%3C
-/span
+div class=%22spoiler blur%22 onclick=%22toggleBlur(this);%22%3E').replace('%5B/spoiler%5D', '%3C/div
 %3E');%0D%0A%09r

Fix spoilers with line breaks.