aboutsummaryrefslogtreecommitdiffstats
path: root/src/ng/compile.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/ng/compile.js')
-rw-r--r--src/ng/compile.js31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/ng/compile.js b/src/ng/compile.js
index de65c83e..e4bf230e 100644
--- a/src/ng/compile.js
+++ b/src/ng/compile.js
@@ -502,7 +502,8 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
var hasDirectives = {},
Suffix = 'Directive',
COMMENT_DIRECTIVE_REGEXP = /^\s*directive\:\s*([\d\w\-_]+)\s+(.*)$/,
- CLASS_DIRECTIVE_REGEXP = /(([\d\w\-_]+)(?:\:([^;]+))?;?)/;
+ CLASS_DIRECTIVE_REGEXP = /(([\d\w\-_]+)(?:\:([^;]+))?;?)/,
+ TABLE_CONTENT_REGEXP = /^<\s*(tr|th|td|tbody)(\s+[^>]*)?>/i;
// Ref: http://developers.whatwg.org/webappapis.html#event-handler-idl-attributes
// The assumption is that future DOM event attribute names will begin with
@@ -1243,9 +1244,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
if (directive.replace) {
replaceDirective = directive;
- $template = jqLite('<div>' +
- trim(directiveValue) +
- '</div>').contents();
+ $template = directiveTemplateContents(directiveValue);
compileNode = $template[0];
if ($template.length != 1 || compileNode.nodeType !== 1) {
@@ -1644,6 +1643,28 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
}
+ function directiveTemplateContents(template) {
+ var type;
+ template = trim(template);
+ if ((type = TABLE_CONTENT_REGEXP.exec(template))) {
+ type = type[1].toLowerCase();
+ var table = jqLite('<table>' + template + '</table>'),
+ tbody = table.children('tbody'),
+ leaf = /(td|th)/.test(type) && table.find('tr');
+ if (tbody.length && type !== 'tbody') {
+ table = tbody;
+ }
+ if (leaf && leaf.length) {
+ table = leaf;
+ }
+ return table.contents();
+ }
+ return jqLite('<div>' +
+ template +
+ '</div>').contents();
+ }
+
+
function compileTemplateUrl(directives, $compileNode, tAttrs,
$rootElement, childTranscludeFn, preLinkFns, postLinkFns, previousCompileContext) {
var linkQueue = [],
@@ -1668,7 +1689,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
content = denormalizeTemplate(content);
if (origAsyncDirective.replace) {
- $template = jqLite('<div>' + trim(content) + '</div>').contents();
+ $template = directiveTemplateContents(content);
compileNode = $template[0];
if ($template.length != 1 || compileNode.nodeType !== 1) {