mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-04-09 04:06:39 +00:00
feat: generate more rule and tests
This commit is contained in:
parent
2aff9fecf1
commit
bfd116a438
@ -47,4 +47,17 @@ exports.parse = function() {
|
||||
}];
|
||||
};
|
||||
|
||||
exports.serialize = function(tree, serialize) {
|
||||
// tree: { type: 'element', tag: 'strong', children: [{ type: 'text', text: 'bold' }] }
|
||||
// serialize: function that accepts array of nodes or a node and returns a string
|
||||
// Initialize the serialized string with the opening delimiter
|
||||
var serialized = "''";
|
||||
// Serialize the children of the bold element
|
||||
serialized += serialize(tree.children);
|
||||
// Close the serialized string with the closing delimiter
|
||||
serialized += "''";
|
||||
// Return the complete serialized string
|
||||
return serialized;
|
||||
};
|
||||
|
||||
})();
|
@ -47,4 +47,17 @@ exports.parse = function() {
|
||||
}];
|
||||
};
|
||||
|
||||
exports.serialize = function(tree, serialize) {
|
||||
// tree: { type: 'element', tag: 'em', children: [{ type: 'text', text: 'italic' }] }
|
||||
// serialize: function that accepts array of nodes or a node and returns a string
|
||||
// Initialize the serialized string with the opening delimiter
|
||||
var serialized = "//";
|
||||
// Serialize the children of the italic element
|
||||
serialized += serialize(tree.children);
|
||||
// Close the serialized string with the closing delimiter
|
||||
serialized += "//";
|
||||
// Return the complete serialized string
|
||||
return serialized;
|
||||
};
|
||||
|
||||
})();
|
@ -47,4 +47,17 @@ exports.parse = function() {
|
||||
}];
|
||||
};
|
||||
|
||||
exports.serialize = function(tree, serialize) {
|
||||
// tree: { type: 'element', tag: 'strike', children: [{ type: 'text', text: 'strikethrough' }] }
|
||||
// serialize: function that accepts array of nodes or a node and returns a string
|
||||
// Initialize the serialized string with the opening delimiter
|
||||
var serialized = "~~";
|
||||
// Serialize the children of the strikethrough element
|
||||
serialized += serialize(tree.children);
|
||||
// Close the serialized string with the closing delimiter
|
||||
serialized += "~~";
|
||||
// Return the complete serialized string
|
||||
return serialized;
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -47,4 +47,17 @@ exports.parse = function() {
|
||||
}];
|
||||
};
|
||||
|
||||
exports.serialize = function(tree, serialize) {
|
||||
// tree: { type: 'element', tag: 'sub', children: [{ type: 'text', text: 'subscript' }] }
|
||||
// serialize: function that accepts array of nodes or a node and returns a string
|
||||
// Initialize the serialized string with the opening delimiter
|
||||
var serialized = ",,";
|
||||
// Serialize the children of the subscript element
|
||||
serialized += serialize(tree.children);
|
||||
// Close the serialized string with the closing delimiter
|
||||
serialized += ",,";
|
||||
// Return the complete serialized string
|
||||
return serialized;
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -47,4 +47,17 @@ exports.parse = function() {
|
||||
}];
|
||||
};
|
||||
|
||||
exports.serialize = function(tree, serialize) {
|
||||
// tree: { type: 'element', tag: 'sup', children: [{ type: 'text', text: 'superscript' }] }
|
||||
// serialize: function that accepts array of nodes or a node and returns a string
|
||||
// Initialize the serialized string with the opening delimiter
|
||||
var serialized = "^^";
|
||||
// Serialize the children of the superscript element
|
||||
serialized += serialize(tree.children);
|
||||
// Close the serialized string with the closing delimiter
|
||||
serialized += "^^";
|
||||
// Return the complete serialized string
|
||||
return serialized;
|
||||
};
|
||||
|
||||
})();
|
@ -47,4 +47,17 @@ exports.parse = function() {
|
||||
}];
|
||||
};
|
||||
|
||||
exports.serialize = function(tree, serialize) {
|
||||
// tree: { type: 'element', tag: 'u', children: [{ type: 'text', text: 'underscore' }] }
|
||||
// serialize: function that accepts array of nodes or a node and returns a string
|
||||
// Initialize the serialized string with the opening delimiter
|
||||
var serialized = "__";
|
||||
// Serialize the children of the underscore element
|
||||
serialized += serialize(tree.children);
|
||||
// Close the serialized string with the closing delimiter
|
||||
serialized += "__";
|
||||
// Return the complete serialized string
|
||||
return serialized;
|
||||
};
|
||||
|
||||
})();
|
@ -44,7 +44,7 @@ Parse the most recent match
|
||||
exports.parse = function() {
|
||||
// Retrieve the most recent match so that recursive calls don't overwrite it
|
||||
var tag = this.nextTag;
|
||||
if (!tag.isSelfClosing) {
|
||||
if(!tag.isSelfClosing) {
|
||||
tag.openTagStart = tag.start;
|
||||
tag.openTagEnd = tag.end;
|
||||
}
|
||||
@ -66,22 +66,22 @@ exports.parse = function() {
|
||||
}
|
||||
tag.end = this.parser.pos;
|
||||
tag.closeTagEnd = tag.end;
|
||||
if (tag.closeTagEnd === tag.openTagEnd || this.parser.source[tag.closeTagEnd - 1] !== '>') {
|
||||
if(tag.closeTagEnd === tag.openTagEnd || this.parser.source[tag.closeTagEnd - 1] !== '>') {
|
||||
tag.closeTagStart = tag.end;
|
||||
} else {
|
||||
tag.closeTagStart = tag.closeTagEnd - 2;
|
||||
var closeTagMinPos = tag.children.length > 0 ? tag.children[tag.children.length-1].end : tag.openTagEnd;
|
||||
if (!Number.isSafeInteger(closeTagMinPos)) closeTagMinPos = tag.openTagEnd;
|
||||
while (tag.closeTagStart >= closeTagMinPos) {
|
||||
if(!Number.isSafeInteger(closeTagMinPos)) closeTagMinPos = tag.openTagEnd;
|
||||
while(tag.closeTagStart >= closeTagMinPos) {
|
||||
var char = this.parser.source[tag.closeTagStart];
|
||||
if (char === '>') {
|
||||
if(char === '>') {
|
||||
tag.closeTagStart = -1;
|
||||
break;
|
||||
}
|
||||
if (char === '<') break;
|
||||
if(char === '<') break;
|
||||
tag.closeTagStart -= 1;
|
||||
}
|
||||
if (tag.closeTagStart < closeTagMinPos) {
|
||||
if(tag.closeTagStart < closeTagMinPos) {
|
||||
tag.closeTagStart = tag.end;
|
||||
}
|
||||
}
|
||||
|
@ -73,4 +73,17 @@ exports.parse = function() {
|
||||
}];
|
||||
};
|
||||
|
||||
exports.serialize = function(tree, serialize) {
|
||||
// tree: { type: 'element', tag: 'blockquote', attributes: { class: { type: 'string', value: 'tc-quote' } }, children: [{ type: 'text', text: 'Quote text' }] }
|
||||
// serialize: function that accepts array of nodes or a node and returns a string
|
||||
// Split the class attribute value into an array of classes, classes: ['tc-quote']
|
||||
var classes = tree.attributes.class.value.split(" ");
|
||||
// Start the serialized string with the opening delimiter and classes, serialized: '<<<tc-quote\n'
|
||||
var serialized = "<<<" + classes.join(" ") + "\n";
|
||||
// Serialize the children of the blockquote, serialized: '<<<tc-quote\nQuote text'
|
||||
serialized += serialize(tree.children);
|
||||
// Return the complete serialized string with the closing delimiter, serialized: '<<<tc-quote\nQuote text\n<<<'
|
||||
return serialized + "\n<<<";
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -61,4 +61,17 @@ exports.parse = function() {
|
||||
return [];
|
||||
};
|
||||
|
||||
exports.serialize = function(tree, serialize) {
|
||||
// tree: { type: 'pragma', name: 'rules', args: ['except', 'ruleone', 'ruletwo', 'rulethree'] }
|
||||
// serialize: function that accepts array of nodes or a node and returns a string
|
||||
// Start the serialized string with the pragma name
|
||||
var serialized = "\\rules";
|
||||
// Iterate over the arguments and append them to the serialized string
|
||||
for(var i = 0; i < tree.args.length; i++) {
|
||||
serialized += " " + tree.args[i];
|
||||
}
|
||||
// Return the complete serialized string
|
||||
return serialized;
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -70,4 +70,26 @@ exports.parse = function() {
|
||||
return tree;
|
||||
};
|
||||
|
||||
exports.serialize = function(tree, serialize) {
|
||||
// tree: [{ type: 'element', tag: 'p', attributes: { class: { type: 'string', value: 'myClass' }, style: { type: 'string', value: 'background-color:red;' } }, children: [{ type: 'text', text: 'This paragraph will have the CSS class `myClass`.' }] }]
|
||||
// serialize: function that accepts array of nodes or a node and returns a string
|
||||
// Initialize the serialized string with the opening delimiter
|
||||
var serialized = "@@";
|
||||
// Check for styles and append them to the serialized string
|
||||
if(tree[0].attributes.style) {
|
||||
serialized += tree[0].attributes.style.value;
|
||||
}
|
||||
// Check for classes and append them to the serialized string
|
||||
if(tree[0].attributes.class) {
|
||||
var classes = tree[0].attributes.class.value.split(" ");
|
||||
for(var i = 0; i < classes.length; i++) {
|
||||
serialized += "." + classes[i];
|
||||
}
|
||||
}
|
||||
// Append the serialized children and the closing delimiter
|
||||
serialized += "\n" + serialize(tree) + "\n@@";
|
||||
// Return the complete serialized string
|
||||
return serialized;
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -55,4 +55,26 @@ exports.parse = function() {
|
||||
return [node];
|
||||
};
|
||||
|
||||
exports.serialize = function(tree, serialize) {
|
||||
// tree: { type: 'element', tag: 'span', attributes: { class: { type: 'string', value: 'myClass' }, style: { type: 'string', value: 'background-color:red;' } }, children: [{ type: 'text', text: 'This is some text with a class and a background colour' }] }
|
||||
// serialize: function that accepts array of nodes or a node and returns a string
|
||||
// Initialize the serialized string with the opening delimiter
|
||||
var serialized = "@@";
|
||||
// Check for styles and append them to the serialized string
|
||||
if(tree.attributes.style) {
|
||||
serialized += tree.attributes.style.value;
|
||||
}
|
||||
// Check for classes and append them to the serialized string
|
||||
if(tree.attributes.class) {
|
||||
var classes = tree.attributes.class.value.split(" ");
|
||||
for(var i = 0; i < classes.length; i++) {
|
||||
serialized += "." + classes[i] + " ";
|
||||
}
|
||||
}
|
||||
// Append the serialized children and the closing delimiter
|
||||
serialized += serialize(tree.children) + "@@";
|
||||
// Return the complete serialized string
|
||||
return serialized;
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -50,4 +50,17 @@ exports.parse = function() {
|
||||
}
|
||||
};
|
||||
|
||||
exports.serialize = function(tree, serialize) {
|
||||
// tree: { type: 'link', attributes: { to: { type: 'string', value: '$:TiddlerTitle' } }, children: [{ type: 'text', text: '$:TiddlerTitle' }] }
|
||||
// serialize: function that accepts array of nodes or a node and returns a string
|
||||
// Check if the link is suppressed
|
||||
var isSuppressed = tree.children[0].text.substr(0,1) === "~";
|
||||
// Initialize the serialized string
|
||||
var serialized = isSuppressed ? "~" : "";
|
||||
// Append the link value
|
||||
serialized += tree.attributes.to.value;
|
||||
// Return the complete serialized string
|
||||
return serialized;
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -185,4 +185,33 @@ exports.parse = function() {
|
||||
return [table];
|
||||
};
|
||||
|
||||
exports.serialize = function(tree, serialize) {
|
||||
// tree: { type: 'element', tag: 'table', children: [{ type: 'element', tag: 'thead', children: [{ type: 'element', tag: 'tr', children: [{ type: 'element', tag: 'th', children: [{ type: 'text', text: 'Alpha' }] }, { type: 'element', tag: 'th', children: [{ type: 'text', text: 'Beta' }] }, { type: 'element', tag: 'th', children: [{ type: 'text', text: 'Gamma' }] }, { type: 'element', tag: 'th', children: [{ type: 'text', text: 'Delta' }] }] }] }, { type: 'element', tag: 'tbody', children: [{ type: 'element', tag: 'tr', children: [{ type: 'element', tag: 'th', children: [{ type: 'text', text: 'One' }] }, { type: 'element', tag: 'td', children: [] }, { type: 'element', tag: 'td', children: [] }, { type: 'element', tag: 'td', children: [] }, { type: 'element', tag: 'td', children: [] }] }, { type: 'element', tag: 'tr', children: [{ type: 'element', tag: 'th', children: [{ type: 'text', text: 'Two' }] }, { type: 'element', tag: 'td', children: [] }, { type: 'element', tag: 'td', children: [] }, { type: 'element', tag: 'td', children: [] }, { type: 'element', tag: 'td', children: [] }] }, { type: 'element', tag: 'tr', children: [{ type: 'element', tag: 'th', children: [{ type: 'text', text: 'Three' }] }, { type: 'element', tag: 'td', children: [] }, { type: 'element', tag: 'td', children: [] }, { type: 'element', tag: 'td', children: [] }, { type: 'element', tag: 'td', children: [] }] }] }] }
|
||||
// serialize: function that accepts array of nodes or a node and returns a string
|
||||
// Initialize the serialized string
|
||||
var serialized = "";
|
||||
// Iterate over the table rows
|
||||
for(var i = 0; i < tree.children.length; i++) {
|
||||
var rowContainer = tree.children[i];
|
||||
// Iterate over the rows in the row container
|
||||
for(var j = 0; j < rowContainer.children.length; j++) {
|
||||
var row = rowContainer.children[j];
|
||||
// Start the row
|
||||
serialized += "|";
|
||||
// Iterate over the cells in the row
|
||||
for(var k = 0; k < row.children.length; k++) {
|
||||
var cell = row.children[k];
|
||||
// Serialize the cell content
|
||||
serialized += serialize(cell.children);
|
||||
// End the cell
|
||||
serialized += "|";
|
||||
}
|
||||
// End the row
|
||||
serialized += "\n";
|
||||
}
|
||||
}
|
||||
// Return the complete serialized string
|
||||
return serialized;
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -86,4 +86,41 @@ exports.parse = function() {
|
||||
}
|
||||
};
|
||||
|
||||
exports.serialize = function(tree, serialize) {
|
||||
// tree: { type: 'transclude', attributes: { $tiddler: { name: '$tiddler', type: 'string', value: 'MyTiddler' }, $field: { name: '$field', type: 'string', value: 'text' } }, isBlock: true }
|
||||
// serialize: function that accepts array of nodes or a node and returns a string
|
||||
// Initialize the serialized string
|
||||
var serialized = "{{";
|
||||
// Check for tiddler attribute
|
||||
if(tree.attributes.$tiddler) {
|
||||
serialized += tree.attributes.$tiddler.value;
|
||||
// Check for field attribute
|
||||
if(tree.attributes.$field) {
|
||||
serialized += "##" + tree.attributes.$field.value;
|
||||
}
|
||||
// Check for index attribute
|
||||
if(tree.attributes.$index) {
|
||||
serialized += "!!" + tree.attributes.$index.value;
|
||||
}
|
||||
}
|
||||
// Check for template attribute
|
||||
if(tree.attributes.$template) {
|
||||
serialized += "||" + tree.attributes.$template.value;
|
||||
}
|
||||
// Check for parameters
|
||||
var params = [];
|
||||
for(var key in tree.attributes) {
|
||||
if(key !== "$tiddler" && key !== "$field" && key !== "$index" && key !== "$template") {
|
||||
params.push(tree.attributes[key].value);
|
||||
}
|
||||
}
|
||||
if(params.length > 0) {
|
||||
serialized += "|" + params.join("|");
|
||||
}
|
||||
// Close the serialized string
|
||||
serialized += "}}";
|
||||
// Return the complete serialized string
|
||||
return serialized;
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -84,4 +84,41 @@ exports.parse = function() {
|
||||
}
|
||||
};
|
||||
|
||||
exports.serialize = function(tree, serialize) {
|
||||
// tree: { type: 'transclude', attributes: { $tiddler: { name: '$tiddler', type: 'string', value: 'MyTiddler' }, $field: { name: '$field', type: 'string', value: 'text' } } }
|
||||
// serialize: function that accepts array of nodes or a node and returns a string
|
||||
// Initialize the serialized string
|
||||
var serialized = "{{";
|
||||
// Check for tiddler attribute
|
||||
if(tree.attributes.$tiddler) {
|
||||
serialized += tree.attributes.$tiddler.value;
|
||||
// Check for field attribute
|
||||
if(tree.attributes.$field) {
|
||||
serialized += "##" + tree.attributes.$field.value;
|
||||
}
|
||||
// Check for index attribute
|
||||
if(tree.attributes.$index) {
|
||||
serialized += "!!" + tree.attributes.$index.value;
|
||||
}
|
||||
}
|
||||
// Check for template attribute
|
||||
if(tree.attributes.$template) {
|
||||
serialized += "||" + tree.attributes.$template.value;
|
||||
}
|
||||
// Check for parameters
|
||||
var params = [];
|
||||
for(var key in tree.attributes) {
|
||||
if(key !== "$tiddler" && key !== "$field" && key !== "$index" && key !== "$template") {
|
||||
params.push(tree.attributes[key].value);
|
||||
}
|
||||
}
|
||||
if(params.length > 0) {
|
||||
serialized += "|" + params.join("|");
|
||||
}
|
||||
// Close the serialized string
|
||||
serialized += "}}";
|
||||
// Return the complete serialized string
|
||||
return serialized;
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -83,4 +83,19 @@ exports.parse = function() {
|
||||
}
|
||||
};
|
||||
|
||||
exports.serialize = function (tree, serialize) {
|
||||
// tree: { type: 'element', tag: 'pre', children: [{ type: 'text', text: 'This will be rendered as JavaScript' }] }
|
||||
// serialize: function that accepts array of nodes or a node and returns a string
|
||||
// Initialize the serialized string with the opening delimiter and type
|
||||
var serialized = '$$$'; // Extract the type from the tree node (assuming it's stored in a specific attribute)
|
||||
if(tree.attributes && tree.attributes.type) {
|
||||
serialized += tree.attributes.type.value;
|
||||
}
|
||||
serialized += '\n'; // Serialize the children of the block
|
||||
serialized += serialize(tree.children); // Close the serialized string
|
||||
serialized += "\n$$$";
|
||||
// Return the complete serialized string
|
||||
return serialized;
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -65,4 +65,17 @@ exports.parse = function() {
|
||||
}];
|
||||
};
|
||||
|
||||
exports.serialize = function(tree, serialize) {
|
||||
// tree: { type: 'link', attributes: { to: { type: 'string', value: 'AWikiLink' } }, children: [{ type: 'text', text: 'AWikiLink' }] }
|
||||
// serialize: function that accepts array of nodes or a node and returns a string
|
||||
// Check if the link is suppressed
|
||||
var isSuppressed = tree.children[0].text.substr(0,1) === $tw.config.textPrimitives.unWikiLink;
|
||||
// Initialize the serialized string
|
||||
var serialized = isSuppressed ? $tw.config.textPrimitives.unWikiLink : "";
|
||||
// Append the link text
|
||||
serialized += tree.attributes.to.value;
|
||||
// Return the complete serialized string
|
||||
return serialized;
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -37,4 +37,15 @@ exports.parse = function() {
|
||||
return [{type: "text", text: linkText.substr(1)}];
|
||||
};
|
||||
|
||||
exports.serialize = function(tree, serialize) {
|
||||
// tree: { type: 'text', text: 'SuppressedLink' }
|
||||
// serialize: function that accepts array of nodes or a node and returns a string
|
||||
// Initialize the serialized string with the unwikilink character
|
||||
var serialized = $tw.config.textPrimitives.unWikiLink;
|
||||
// Append the text
|
||||
serialized += tree.text;
|
||||
// Return the complete serialized string
|
||||
return serialized;
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -10,6 +10,60 @@ Tests the wikitext inverse-rendering from Wiki AST.
|
||||
describe('WikiAST serialization tests', function () {
|
||||
var wiki = new $tw.Wiki();
|
||||
|
||||
wiki.addTiddler({
|
||||
title: 'BoldEmphasisTest',
|
||||
text: "This is ''bold'' text"
|
||||
});
|
||||
it('should serialize bold emphasis correctly', function () {
|
||||
var serialized = $tw.utils.serializeParseTree(wiki.parseTiddler('BoldEmphasisTest').tree).trimEnd();
|
||||
expect(serialized).toBe(wiki.getTiddlerText('BoldEmphasisTest').trimEnd());
|
||||
});
|
||||
|
||||
wiki.addTiddler({
|
||||
title: 'ItalicEmphasisTest',
|
||||
text: "This is //italic// text"
|
||||
});
|
||||
it('should serialize italic emphasis correctly', function () {
|
||||
var serialized = $tw.utils.serializeParseTree(wiki.parseTiddler('ItalicEmphasisTest').tree).trimEnd();
|
||||
expect(serialized).toBe(wiki.getTiddlerText('ItalicEmphasisTest').trimEnd());
|
||||
});
|
||||
|
||||
wiki.addTiddler({
|
||||
title: 'StrikethroughEmphasisTest',
|
||||
text: "This is ~~strikethrough~~ text"
|
||||
});
|
||||
it('should serialize strikethrough emphasis correctly', function () {
|
||||
var serialized = $tw.utils.serializeParseTree(wiki.parseTiddler('StrikethroughEmphasisTest').tree).trimEnd();
|
||||
expect(serialized).toBe(wiki.getTiddlerText('StrikethroughEmphasisTest').trimEnd());
|
||||
});
|
||||
|
||||
wiki.addTiddler({
|
||||
title: 'SubscriptEmphasisTest',
|
||||
text: "This is ,,subscript,, text"
|
||||
});
|
||||
it('should serialize subscript emphasis correctly', function () {
|
||||
var serialized = $tw.utils.serializeParseTree(wiki.parseTiddler('SubscriptEmphasisTest').tree).trimEnd();
|
||||
expect(serialized).toBe(wiki.getTiddlerText('SubscriptEmphasisTest').trimEnd());
|
||||
});
|
||||
|
||||
wiki.addTiddler({
|
||||
title: 'SuperscriptEmphasisTest',
|
||||
text: "This is ^^superscript^^ text"
|
||||
});
|
||||
it('should serialize superscript emphasis correctly', function () {
|
||||
var serialized = $tw.utils.serializeParseTree(wiki.parseTiddler('SuperscriptEmphasisTest').tree).trimEnd();
|
||||
expect(serialized).toBe(wiki.getTiddlerText('SuperscriptEmphasisTest').trimEnd());
|
||||
});
|
||||
|
||||
wiki.addTiddler({
|
||||
title: 'UnderscoreEmphasisTest',
|
||||
text: "This is __underscore__ text"
|
||||
});
|
||||
it('should serialize underscore emphasis correctly', function () {
|
||||
var serialized = $tw.utils.serializeParseTree(wiki.parseTiddler('UnderscoreEmphasisTest').tree).trimEnd();
|
||||
expect(serialized).toBe(wiki.getTiddlerText('UnderscoreEmphasisTest').trimEnd());
|
||||
});
|
||||
|
||||
wiki.addTiddler({ title: 'TiddlerOne', text: 'The quick brown fox' });
|
||||
it('should render tiddlers with no special markup as-is', function () {
|
||||
// `trimEnd` because when we handle `p` element when parsing block rules, we always add a newline. But original text that may not have a trailing newline, will still be recognized as a block.
|
||||
@ -261,4 +315,103 @@ describe('WikiAST serialization tests', function () {
|
||||
var serialized = $tw.utils.serializeParseTree(wiki.parseTiddler('PrettyLinkTest').tree).trimEnd();
|
||||
expect(serialized).toBe(wiki.getTiddlerText('PrettyLinkTest').trimEnd());
|
||||
});
|
||||
|
||||
wiki.addTiddler({
|
||||
title: 'QuoteBlockTest',
|
||||
text: '<<<tc-quote\nQuote text\n<<<',
|
||||
});
|
||||
it('should serialize quote blocks correctly', function () {
|
||||
var serialized = $tw.utils.serializeParseTree(wiki.parseTiddler('QuoteBlockTest').tree).trimEnd();
|
||||
expect(serialized).toBe(wiki.getTiddlerText('QuoteBlockTest').trimEnd());
|
||||
});
|
||||
|
||||
wiki.addTiddler({
|
||||
title: 'RulesPragmaTest',
|
||||
text: '\\rules except ruleone ruletwo rulethree\n\\rules only ruleone ruletwo rulethree',
|
||||
});
|
||||
it('should serialize rules pragma correctly', function () {
|
||||
var serialized = $tw.utils.serializeParseTree(wiki.parseTiddler('RulesPragmaTest').tree).trimEnd();
|
||||
expect(serialized).toBe(wiki.getTiddlerText('RulesPragmaTest').trimEnd());
|
||||
});
|
||||
|
||||
wiki.addTiddler({
|
||||
title: 'StyleBlockTest',
|
||||
text: '@@.myClass\n@@background-color:red;\nThis paragraph will have the CSS class `myClass`.\n\n* The `<ul>` around this list will also have the class `myClass`\n* List item 2\n@@',
|
||||
});
|
||||
it('should serialize style blocks correctly', function () {
|
||||
var serialized = $tw.utils.serializeParseTree(wiki.parseTiddler('StyleBlockTest').tree).trimEnd();
|
||||
expect(serialized).toBe(wiki.getTiddlerText('StyleBlockTest').trimEnd());
|
||||
});
|
||||
|
||||
wiki.addTiddler({
|
||||
title: 'StyleInlineTest',
|
||||
text: '@@.myClass This is some text with a class@@\n@@background-color:red;This is some text with a background colour@@\n@@width:100px;.myClass This is some text with a class and a width@@',
|
||||
});
|
||||
it('should serialize style inlines correctly', function () {
|
||||
var serialized = $tw.utils.serializeParseTree(wiki.parseTiddler('StyleInlineTest').tree).trimEnd();
|
||||
expect(serialized).toBe(wiki.getTiddlerText('StyleInlineTest').trimEnd());
|
||||
});
|
||||
|
||||
wiki.addTiddler({
|
||||
title: 'SysLinkTest',
|
||||
text: '$:TiddlerTitle\n~$:TiddlerTitle'
|
||||
});
|
||||
it('should serialize system links correctly', function () {
|
||||
var serialized = $tw.utils.serializeParseTree(wiki.parseTiddler('SysLinkTest').tree).trimEnd();
|
||||
expect(serialized).toBe(wiki.getTiddlerText('SysLinkTest').trimEnd());
|
||||
});
|
||||
|
||||
wiki.addTiddler({
|
||||
title: 'TableTest',
|
||||
text: '|! |!Alpha |!Beta |!Gamma |!Delta |\n|!One | | | | |\n|!Two | | | | |\n|!Three | | | | |'
|
||||
});
|
||||
it('should serialize tables correctly', function () {
|
||||
var serialized = $tw.utils.serializeParseTree(wiki.parseTiddler('TableTest').tree).trimEnd();
|
||||
expect(serialized).toBe(wiki.getTiddlerText('TableTest').trimEnd());
|
||||
});
|
||||
|
||||
wiki.addTiddler({
|
||||
title: 'TranscludeBlockTest',
|
||||
text: '{{MyTiddler}}\n{{MyTiddler||TemplateTitle}}'
|
||||
});
|
||||
it('should serialize block-level transclusions correctly', function () {
|
||||
var serialized = $tw.utils.serializeParseTree(wiki.parseTiddler('TranscludeBlockTest').tree).trimEnd();
|
||||
expect(serialized).toBe(wiki.getTiddlerText('TranscludeBlockTest').trimEnd());
|
||||
});
|
||||
|
||||
wiki.addTiddler({
|
||||
title: 'TranscludeInlineTest',
|
||||
text: '{{MyTiddler}}\n{{MyTiddler||TemplateTitle}}'
|
||||
});
|
||||
it('should serialize inline-level transclusions correctly', function () {
|
||||
var serialized = $tw.utils.serializeParseTree(wiki.parseTiddler('TranscludeInlineTest').tree).trimEnd();
|
||||
expect(serialized).toBe(wiki.getTiddlerText('TranscludeInlineTest').trimEnd());
|
||||
});
|
||||
|
||||
wiki.addTiddler({
|
||||
title: 'TypedBlockTest',
|
||||
text: '$$$.js\nThis will be rendered as JavaScript\n$$$\n$$$.svg\n<svg xmlns="http://www.w3.org/2000/svg" width="150" height="100">\n <circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red" />\n</svg>\n$$$\n$$$text/vnd.tiddlywiki>text/html\nThis will be rendered as an //HTML representation// of WikiText\n$$$'
|
||||
});
|
||||
it('should serialize typed blocks correctly', function () {
|
||||
var serialized = $tw.utils.serializeParseTree(wiki.parseTiddler('TypedBlockTest').tree).trimEnd();
|
||||
expect(serialized).toBe(wiki.getTiddlerText('TypedBlockTest').trimEnd());
|
||||
});
|
||||
|
||||
wiki.addTiddler({
|
||||
title: 'WikiLinkTest',
|
||||
text: 'AWikiLink\nAnotherLink\n~SuppressedLink'
|
||||
});
|
||||
it('should serialize wiki links correctly', function () {
|
||||
var serialized = $tw.utils.serializeParseTree(wiki.parseTiddler('WikiLinkTest').tree).trimEnd();
|
||||
expect(serialized).toBe(wiki.getTiddlerText('WikiLinkTest').trimEnd());
|
||||
});
|
||||
|
||||
wiki.addTiddler({
|
||||
title: 'WikiLinkPrefixTest',
|
||||
text: '~SuppressedLink'
|
||||
});
|
||||
it('should serialize suppressed wiki links correctly', function () {
|
||||
var serialized = $tw.utils.serializeParseTree(wiki.parseTiddler('WikiLinkPrefixTest').tree).trimEnd();
|
||||
expect(serialized).toBe(wiki.getTiddlerText('WikiLinkPrefixTest').trimEnd());
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user