further tighten entity-matching regex, add basic test for entity matching

This commit is contained in:
Dan Cech 2015-05-21 16:20:37 -04:00
parent ab16d713ae
commit 18048eeadf
4 changed files with 19 additions and 1 deletions

View File

@ -32,7 +32,8 @@ var entities = {
};
function decodeEntities(data) {
return data.replace(/&([a-z0-9#]+);/gi, function(match, entityName) {
// match numeric, hexadecimal & named entities
return data.replace(/&(#\d+|#x[0-9a-fA-F]+|[a-zA-Z0-9]+);/g, function(match, entityName) {
return entities[entityName] || '${entity:' + entityName + '}';
});
}

4
test/compiler-tests.js Normal file → Executable file
View File

@ -58,6 +58,10 @@ describe('marko/compiler' , function() {
testCompiler('fixtures/templates/compiler/hello-dynamic');
});
it('should compile a simple template with entities', function() {
testCompiler('fixtures/templates/compiler/entities');
});
// it.only('should compile a template with <c:invoke>', function() {
// testCompiler('test-project/tabs.marko');
// });

View File

@ -0,0 +1,9 @@
exports.create = function(__helpers) {
var str = __helpers.s,
empty = __helpers.e,
notEmpty = __helpers.ne;
return function render(data, out) {
out.w('Hello John &amp; Suzy Invalid Entity: &amp;b ; Valid Numeric Entity: &#34;\nValid Hexadecimal Entity:\n&#x00A2;');
};
}

View File

@ -0,0 +1,4 @@
Hello John &amp; Suzy
Invalid Entity: &b ;
Valid Numeric Entity: &#34;
Valid Hexadecimal Entity: &#x00A2;