mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-03 12:49:09 +00:00
fix: some test
This commit is contained in:
parent
b1667ecb9d
commit
e49238df55
@ -35,7 +35,7 @@ exports.parse = function() {
|
||||
this.parser.pos = this.matchRegExp.lastIndex;
|
||||
// Create the link unless it is suppressed
|
||||
if(this.match[0].substr(0,1) === "~") {
|
||||
return [{type: "text", text: this.match[0].substr(1)}];
|
||||
return [{type: "text", text: this.match[0].substr(1), start: start, end: this.parser.pos}];
|
||||
} else {
|
||||
return [{
|
||||
type: "element",
|
||||
@ -53,10 +53,9 @@ exports.parse = function() {
|
||||
}
|
||||
};
|
||||
|
||||
// Serialize method for the extlink rule
|
||||
exports.serialize = function(tree, serialize) {
|
||||
if(tree.type === "text") {
|
||||
return tree.text;
|
||||
return "~" + tree.text;
|
||||
} else if(tree.type === "element" && tree.tag === "a") {
|
||||
return tree.attributes.href.value;
|
||||
}
|
||||
|
@ -78,12 +78,13 @@ exports.serialize = function(tree) {
|
||||
if(tree.attributes.tooltip) serialized += "|" + tree.attributes.tooltip.value;
|
||||
// Template title
|
||||
if(tree.attributes.template) serialized += "||" + tree.attributes.template.value;
|
||||
serialized += "}}}";
|
||||
serialized += "}}";
|
||||
// Inline styles
|
||||
if(tree.attributes.style) serialized += tree.attributes.style.value;
|
||||
serialized += "}"
|
||||
// CSS classes
|
||||
if(tree.attributes.itemClass) serialized += "." + tree.attributes.itemClass.value.split(" ").join(".");
|
||||
return serialized;
|
||||
return serialized + "\n";
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -77,9 +77,10 @@ exports.serialize = function(tree) {
|
||||
if(tree.attributes.tooltip) serialized += "|" + tree.attributes.tooltip.value;
|
||||
// Template title
|
||||
if(tree.attributes.template) serialized += "||" + tree.attributes.template.value;
|
||||
serialized += "}}}";
|
||||
serialized += "}}";
|
||||
// Inline styles
|
||||
if(tree.attributes.style) serialized += tree.attributes.style.value;
|
||||
serialized += "}"
|
||||
// CSS classes
|
||||
if(tree.attributes.itemClass) serialized += "." + tree.attributes.itemClass.value.split(" ").join(".");
|
||||
return serialized;
|
||||
|
@ -199,9 +199,9 @@ exports.serialize = function(tree, serialize) {
|
||||
var tag = tree.tag;
|
||||
var attributes = Object.keys(tree.attributes).map(function(key) {
|
||||
return key + '="' + tree.attributes[key].value + '"';
|
||||
}).join(" ");
|
||||
});
|
||||
// Children
|
||||
var children = tree.children ? serialize(tree.children).join('') : '';
|
||||
var children = tree.children ? serialize(tree.children) : '';
|
||||
// Self-closing tag
|
||||
if(tree.isSelfClosing) {
|
||||
return "<" + tag + (attributes ? " " + attributes : "") + " />";
|
||||
|
@ -169,7 +169,7 @@ function serializeList(node, serialize, depth) {
|
||||
// Classes
|
||||
var classes = child.attributes && child.attributes.class ? child.attributes.class.value.split(" ").join(".") : "";
|
||||
// Serialized children
|
||||
var children = serialize(child.children).join('');
|
||||
var children = serialize(child.children);
|
||||
// Construct the serialized list item
|
||||
return Array(depth + 1).join(listTag[0]) + (classes ? "." + classes : "") + " " + children;
|
||||
}).join("\n");
|
||||
|
@ -134,7 +134,7 @@ exports.serializeParseTree = function serializeParseTree(tree,tiddlerType) {
|
||||
output.push(serializeParseTree(node,tiddlerType));
|
||||
});
|
||||
} else {
|
||||
if(tree.type === "text") {
|
||||
if(tree.type === "text" && !tree.rule) {
|
||||
output.push(tree.text);
|
||||
} else {
|
||||
var Parser = $tw.wiki.getParser(tiddlerType);
|
||||
@ -145,6 +145,9 @@ exports.serializeParseTree = function serializeParseTree(tree,tiddlerType) {
|
||||
output.push(Rule.prototype.serialize(tree,serializeParseTree));
|
||||
} else if(tree.rule === "parseBlock") {
|
||||
output.push(serializeParseTree(tree.children,tiddlerType),"\n\n");
|
||||
} else {
|
||||
// when no rule is found, just serialize the children
|
||||
output.push(serializeParseTree(tree.children,tiddlerType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -96,7 +96,6 @@ describe('WikiAST serialization tests', function () {
|
||||
);
|
||||
});
|
||||
|
||||
// Test case for commentblock rule
|
||||
wiki.addTiddler({
|
||||
title: 'CommentBlockTest',
|
||||
text: '<!-- This is a comment -->\n\nSome text\n\n<!-- Another comment -->\n\nMore text',
|
||||
@ -106,7 +105,6 @@ describe('WikiAST serialization tests', function () {
|
||||
expect(serialized).toBe(wiki.getTiddlerText('CommentBlockTest').trimEnd());
|
||||
});
|
||||
|
||||
// Test case for commentinline rule
|
||||
wiki.addTiddler({
|
||||
title: 'CommentInlineTest',
|
||||
text: 'This is some text with an inline comment <!-- This is a comment --> and some more text.',
|
||||
@ -116,7 +114,6 @@ describe('WikiAST serialization tests', function () {
|
||||
expect(serialized).toBe(wiki.getTiddlerText('CommentInlineTest').trimEnd());
|
||||
});
|
||||
|
||||
// Test case for conditional rule
|
||||
wiki.addTiddler({
|
||||
title: 'ConditionalTest',
|
||||
text: 'This is a <% if [{something}] %>Elephant<% elseif [{else}] %>Pelican<% else %>Crocodile<% endif %>',
|
||||
@ -126,7 +123,6 @@ describe('WikiAST serialization tests', function () {
|
||||
expect(serialized).toBe(wiki.getTiddlerText('ConditionalTest').trimEnd());
|
||||
});
|
||||
|
||||
// Test case for dash rule
|
||||
wiki.addTiddler({
|
||||
title: 'DashTest',
|
||||
text: 'This is an en-dash: --\n\nThis is an em-dash: ---',
|
||||
@ -136,7 +132,6 @@ describe('WikiAST serialization tests', function () {
|
||||
expect(serialized).toBe(wiki.getTiddlerText('DashTest').trimEnd());
|
||||
});
|
||||
|
||||
// Test case for entity rule
|
||||
wiki.addTiddler({
|
||||
title: 'EntityTest',
|
||||
text: 'This is a copyright symbol: ©',
|
||||
@ -146,7 +141,6 @@ describe('WikiAST serialization tests', function () {
|
||||
expect(serialized).toBe(wiki.getTiddlerText('EntityTest').trimEnd());
|
||||
});
|
||||
|
||||
// Test case for extlink rule
|
||||
wiki.addTiddler({
|
||||
title: 'ExtLinkTest',
|
||||
text: 'An external link: https://www.tiddlywiki.com/\n\nA suppressed external link: ~http://www.tiddlyspace.com/',
|
||||
@ -156,7 +150,6 @@ describe('WikiAST serialization tests', function () {
|
||||
expect(serialized).toBe(wiki.getTiddlerText('ExtLinkTest').trimEnd());
|
||||
});
|
||||
|
||||
// Test case for filteredtranscludeblock rule
|
||||
wiki.addTiddler({
|
||||
title: 'FilteredTranscludeBlockTest',
|
||||
text: '{{{ [tag[docs]] }}}\n{{{ [tag[docs]] |tooltip}}}\n{{{ [tag[docs]] ||TemplateTitle}}}\n{{{ [tag[docs]] |tooltip||TemplateTitle}}}\n{{{ [tag[docs]] }}width:40;height:50;}.class.class',
|
||||
@ -166,7 +159,6 @@ describe('WikiAST serialization tests', function () {
|
||||
expect(serialized).toBe(wiki.getTiddlerText('FilteredTranscludeBlockTest').trimEnd());
|
||||
});
|
||||
|
||||
// Test case for filteredtranscludeinline rule
|
||||
wiki.addTiddler({
|
||||
title: 'FilteredTranscludeInlineTest',
|
||||
text: '{{{ [tag[docs]] }}} {{{ [tag[docs]] |tooltip}}} {{{ [tag[docs]] ||TemplateTitle}}} {{{ [tag[docs]] |tooltip||TemplateTitle}}} {{{ [tag[docs]] }}width:40;height:50;}.class.class',
|
||||
@ -185,8 +177,8 @@ describe('WikiAST serialization tests', function () {
|
||||
var serialized = $tw.utils.serializeParseTree(wiki.parseTiddler('FunctionDefinition').tree).trimEnd();
|
||||
expect(serialized).toBe(wiki.getTiddlerText('FunctionDefinition').trimEnd());
|
||||
});
|
||||
return;
|
||||
|
||||
// Test case for hardlinebreaks rule
|
||||
wiki.addTiddler({
|
||||
title: 'HardLineBreaksTest',
|
||||
text: '"""\nThis is some text\nThat is set like\nIt is a Poem\nWhen it is\nClearly\nNot\n"""\n',
|
||||
@ -196,7 +188,6 @@ describe('WikiAST serialization tests', function () {
|
||||
expect(serialized).toBe(wiki.getTiddlerText('HardLineBreaksTest').trimEnd());
|
||||
});
|
||||
|
||||
// Test case for heading rule
|
||||
wiki.addTiddler({
|
||||
title: 'HeadingTest',
|
||||
text: '! Heading 1\n!! Heading 2\n!!! Heading 3\n!!!! Heading 4\n!!!!! Heading 5\n!!!!!! Heading 6',
|
||||
@ -206,7 +197,6 @@ describe('WikiAST serialization tests', function () {
|
||||
expect(serialized).toBe(wiki.getTiddlerText('HeadingTest').trimEnd());
|
||||
});
|
||||
|
||||
// Test case for html rule
|
||||
wiki.addTiddler({
|
||||
title: 'HtmlTest',
|
||||
text: '<aside>\nThis is an HTML5 aside element\n</aside>\n\n<$slider target="MyTiddler">\nThis is a widget invocation\n</$slider>',
|
||||
@ -216,7 +206,6 @@ describe('WikiAST serialization tests', function () {
|
||||
expect(serialized).toBe(wiki.getTiddlerText('HtmlTest').trimEnd());
|
||||
});
|
||||
|
||||
// Test case for image rule
|
||||
wiki.addTiddler({
|
||||
title: 'ImageTest',
|
||||
text: '[img[https://tiddlywiki.com/fractalveg.jpg]]\n[img width=23 height=24 [https://tiddlywiki.com/fractalveg.jpg]]\n[img width={{!!width}} height={{!!height}} [https://tiddlywiki.com/fractalveg.jpg]]\n[img[Description of image|https://tiddlywiki.com/fractalveg.jpg]]\n[img[TiddlerTitle]]\n[img[Description of image|TiddlerTitle]]',
|
||||
@ -226,7 +215,6 @@ describe('WikiAST serialization tests', function () {
|
||||
expect(serialized).toBe(wiki.getTiddlerText('ImageTest').trimEnd());
|
||||
});
|
||||
|
||||
// Test case for import rule
|
||||
wiki.addTiddler({
|
||||
title: 'ImportTest',
|
||||
text: '\\import [[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]]',
|
||||
@ -236,7 +224,6 @@ describe('WikiAST serialization tests', function () {
|
||||
expect(serialized).toBe(wiki.getTiddlerText('ImportTest').trimEnd());
|
||||
});
|
||||
|
||||
// Test case for list rule
|
||||
wiki.addTiddler({
|
||||
title: 'ListTest',
|
||||
text: '* This is an unordered list\n* It has two items\n\n# This is a numbered list\n## With a subitem\n# And a third item\n\n; This is a term that is being defined\n: This is the definition of that term\n\n#** One\n#* Two\n#** Three\n#**** Four\n#**# Five\n#**## Six\n## Seven\n### Eight\n## Nine\n\n* List item one\n*.active List item two has the class `active`\n* List item three',
|
||||
@ -246,7 +233,6 @@ describe('WikiAST serialization tests', function () {
|
||||
expect(serialized).toBe(wiki.getTiddlerText('ListTest').trimEnd());
|
||||
});
|
||||
|
||||
// Test case for macrocallblock rule
|
||||
wiki.addTiddler({
|
||||
title: 'MacroCallBlockTest',
|
||||
text: '<<name value value2>>',
|
||||
@ -256,7 +242,6 @@ describe('WikiAST serialization tests', function () {
|
||||
expect(serialized).toBe(wiki.getTiddlerText('MacroCallBlockTest').trimEnd());
|
||||
});
|
||||
|
||||
// Test case for macrocallinline rule
|
||||
wiki.addTiddler({
|
||||
title: 'MacroCallInlineTest',
|
||||
text: 'This is a macro call: <<name value value2>>',
|
||||
@ -266,7 +251,6 @@ describe('WikiAST serialization tests', function () {
|
||||
expect(serialized).toBe(wiki.getTiddlerText('MacroCallInlineTest').trimEnd());
|
||||
});
|
||||
|
||||
// Test case for macrodef rule
|
||||
wiki.addTiddler({
|
||||
title: 'MacroDefTest',
|
||||
text: '\\define name(param:defaultvalue,param2:defaultvalue)\ndefinition text, including $param$ markers\n\\end',
|
||||
@ -276,7 +260,6 @@ describe('WikiAST serialization tests', function () {
|
||||
expect(serialized).toBe(wiki.getTiddlerText('MacroDefTest').trimEnd());
|
||||
});
|
||||
|
||||
// Test case for parameters rule
|
||||
wiki.addTiddler({
|
||||
title: 'ParametersTest',
|
||||
text: '\\parameters(param:defaultvalue,param2:defaultvalue)',
|
||||
@ -286,7 +269,6 @@ describe('WikiAST serialization tests', function () {
|
||||
expect(serialized).toBe(wiki.getTiddlerText('ParametersTest').trimEnd());
|
||||
});
|
||||
|
||||
// Test case for parsermode rule
|
||||
wiki.addTiddler({
|
||||
title: 'ParserModeTest',
|
||||
text: '\\parsermode block\n\\parsermode inline',
|
||||
@ -296,7 +278,6 @@ describe('WikiAST serialization tests', function () {
|
||||
expect(serialized).toBe(wiki.getTiddlerText('ParserModeTest').trimEnd());
|
||||
});
|
||||
|
||||
// Test case for prettyextlink rule
|
||||
wiki.addTiddler({
|
||||
title: 'PrettyExtLinkTest',
|
||||
text: '[ext[https://tiddlywiki.com/fractalveg.jpg]]\n[ext[Tooltip|https://tiddlywiki.com/fractalveg.jpg]]',
|
||||
@ -306,7 +287,6 @@ describe('WikiAST serialization tests', function () {
|
||||
expect(serialized).toBe(wiki.getTiddlerText('PrettyExtLinkTest').trimEnd());
|
||||
});
|
||||
|
||||
// Test case for prettylink rule
|
||||
wiki.addTiddler({
|
||||
title: 'PrettyLinkTest',
|
||||
text: '[[Introduction]]\n[[Link description|TiddlerTitle]]',
|
||||
|
Loading…
Reference in New Issue
Block a user