diff options
| author | Misko Hevery | 2011-01-25 21:55:11 -0800 |
|---|---|---|
| committer | Igor Minar | 2011-01-26 23:31:15 -0800 |
| commit | bd33f60276a0fa37acffbad7a0cdcff92db594c8 (patch) | |
| tree | 7cd957c19182ddc430a6320b77b2f03cb1bd223d /docs/src/dom.js | |
| parent | 8682befc7284a3c0b35cd5d85d4f42b1484ec71a (diff) | |
| download | angular.js-bd33f60276a0fa37acffbad7a0cdcff92db594c8.tar.bz2 | |
Added part of guide documentation and supporting changes to doc generator
Diffstat (limited to 'docs/src/dom.js')
| -rw-r--r-- | docs/src/dom.js | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/docs/src/dom.js b/docs/src/dom.js index fedd4e19..7708cbc9 100644 --- a/docs/src/dom.js +++ b/docs/src/dom.js @@ -3,12 +3,18 @@ */ exports.DOM = DOM; +exports.htmlEscape = htmlEscape; ////////////////////////////////////////////////////////// +function htmlEscape(text){ + return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); +} + + function DOM(){ this.out = []; - this.headingDepth = 1; + this.headingDepth = 0; } var INLINE_TAGS = { @@ -23,7 +29,7 @@ DOM.prototype = { text: function(content) { if (typeof content == "string") { - this.out.push(content.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')); + this.out.push(htmlEscape(content)); } else if (typeof content == 'function') { content.call(this, this); } else if (content instanceof Array) { @@ -33,6 +39,13 @@ DOM.prototype = { html: function(html) { if (html) { + var headingDepth = this.headingDepth; + for ( var i = 10; i > 0; --i) { + html = html + .replace(new RegExp('(<\/?h)' + i + '(>)', 'gm'), function(all, start, end){ + return start + (i + headingDepth) + end; + }); + } this.out.push(html); } }, @@ -80,15 +93,17 @@ DOM.prototype = { h: function(heading, content, fn){ if (content==undefined || content && content.legth == 0) return; - this.tag('h' + this.headingDepth, heading); this.headingDepth++; + this.tag('h' + this.headingDepth, heading); var className = typeof heading == 'string' - ? {'class': heading.toLowerCase().replace(/[^\d\w_]/, '-')} + ? {'class': heading.toLowerCase().replace(/[^\d\w_]/mg, '-').replace(/-+/gm, '-')} : null; if (content instanceof Array) { this.ul(content, className, fn); } else if (fn) { - this.tag('div', className, fn); + this.tag('div', className, function(){ + fn.call(this, content); + }); } else { this.tag('div', className, content); } |
