Allow distinguishing tag names in badpenny.
This commit is contained in:
@@ -7,7 +7,7 @@ badpenny = rr.Parser({
|
|||||||
rr.Literal('}}')),
|
rr.Literal('}}')),
|
||||||
rr.Sequence(
|
rr.Sequence(
|
||||||
rr.Literal('{{('),
|
rr.Literal('{{('),
|
||||||
rr.SavedLiteral('tagname'),
|
rr.Node('name', rr.SingleLineText()),
|
||||||
rr.Literal('}}'),
|
rr.Literal('}}'),
|
||||||
rr.MultiLineText(),
|
rr.MultiLineText(),
|
||||||
rr.Literal('{{)'),
|
rr.Literal('{{)'),
|
||||||
@@ -22,7 +22,7 @@ badpenny = rr.Parser({
|
|||||||
rr.Literal('}}')),
|
rr.Literal('}}')),
|
||||||
rr.Sequence(
|
rr.Sequence(
|
||||||
rr.Literal('{{['),
|
rr.Literal('{{['),
|
||||||
rr.SavedLiteral('tagname'),
|
rr.Node('name', rr.SingleLineText()),
|
||||||
rr.Literal('}}'),
|
rr.Literal('}}'),
|
||||||
rr.MultiLineText(),
|
rr.MultiLineText(),
|
||||||
rr.Literal('{{]'),
|
rr.Literal('{{]'),
|
||||||
@@ -31,7 +31,7 @@ badpenny = rr.Parser({
|
|||||||
|
|
||||||
'value': rr.Node('value', rr.Sequence(
|
'value': rr.Node('value', rr.Sequence(
|
||||||
rr.Literal('{{'),
|
rr.Literal('{{'),
|
||||||
rr.SingleLineText(),
|
rr.Node('name', rr.SingleLineText()),
|
||||||
rr.Literal('}}'))),
|
rr.Literal('}}'))),
|
||||||
|
|
||||||
'chunk': rr.Or(
|
'chunk': rr.Or(
|
||||||
@@ -44,4 +44,7 @@ badpenny = rr.Parser({
|
|||||||
rr.ZeroOrMore(rr.Ref('chunk')),
|
rr.ZeroOrMore(rr.Ref('chunk')),
|
||||||
rr.EndOfText()))
|
rr.EndOfText()))
|
||||||
}, [
|
}, [
|
||||||
|
rr.ChildToAttribute('container', 'name'),
|
||||||
|
rr.ChildToAttribute('repeated', 'name'),
|
||||||
|
rr.ChildToAttribute('value', 'name')
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -114,14 +114,16 @@ QUnit.test('Base', function(assert) {
|
|||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
var content = [
|
var content = [
|
||||||
'foo{{value1}}bar',
|
'foo{{value1}}bar',
|
||||||
'foo{{(container}}contents{{)nottheend}}more contents{{)container}}bar',
|
'foo{{(container1}}contents{{)nottheend}}more contents{{)container1}}bar',
|
||||||
'foo{{[repeated}}testing{{]notthis}}{{)repeated}}zig{{]repeated}}bar'
|
'foo{{[repeated1}}testing{{]notthis}}{{)repeated1}}zig{{]repeated1}}bar'
|
||||||
].join('\n');
|
].join('\n');
|
||||||
|
|
||||||
var expected = [
|
var expected = [
|
||||||
'foo<value>value1</value>bar\n',
|
'foo<value name="value1"></value>bar\n',
|
||||||
'foo<container>contents{{)nottheend}}more contents</container>bar\n',
|
'foo<container name="container1">contents{{)nottheend}}more contents',
|
||||||
'foo<repeated>testing{{]notthis}}{{)repeated}}zig</repeated>bar'
|
'</container>bar\n',
|
||||||
|
'foo<repeated name="repeated1">testing{{]notthis}}{{)repeated1}}zig',
|
||||||
|
'</repeated>bar'
|
||||||
].join('');
|
].join('');
|
||||||
|
|
||||||
assert.equal(badpenny.parseFromString(content).innerHTML, expected);
|
assert.equal(badpenny.parseFromString(content).innerHTML, expected);
|
||||||
|
|||||||
Reference in New Issue
Block a user