diff --git a/core/modules/deserializers.js b/core/modules/deserializers.js index 7a4ce7cc6..6c6119e25 100644 --- a/core/modules/deserializers.js +++ b/core/modules/deserializers.js @@ -36,30 +36,35 @@ var parseTiddlerDiv = function(text /* [,fields] */) { } } // Parse the DIV body - var divRegExp = /^\s*
([(?:\s|\S)]*)<\/pre>\s*$/gi, - attrRegExp = /\s*([^=\s]+)\s*=\s*"([^"]*)"/gi, - match = divRegExp.exec(text); + var startRegExp = /^\s*]*)>(\s*)?/gi, + endRegExp, + match = startRegExp.exec(text); if(match) { - var subMatch = subDivRegExp.exec(match[2]); // Body of thetag - if(subMatch) { - result.text = subMatch[1]; + // Old-style DIVs don't have thetag + if(match[2]) { + endRegExp = /<\/pre>\s*<\/div>\s*$/gi; } else { - result.text = match[2]; + endRegExp = /<\/div>\s*$/gi; + } + var endMatch = endRegExp.exec(text); + if(endMatch) { + // Extract the text + result.text = text.substring(match.index + match[0].length,endMatch.index); + // Process the attributes + var attrRegExp = /\s*([^=\s]+)\s*=\s*"([^"]*)"/gi, + attrMatch; + do { + attrMatch = attrRegExp.exec(match[1]); + if(attrMatch) { + var name = attrMatch[1]; + var value = attrMatch[2]; + result[name] = value; + } + } while(attrMatch); + return result; } - var attrMatch; - do { - attrMatch = attrRegExp.exec(match[1]); - if(attrMatch) { - var name = attrMatch[1]; - var value = attrMatch[2]; - result[name] = value; - } - } while(attrMatch); - return result; - } else { - return undefined; } + return undefined; }; exports["application/x-tiddler-html-div"] = function(text,fields) {