Skip to content
This repository has been archived by the owner on Jan 23, 2022. It is now read-only.

Commit

Permalink
feat(ngdocs): update to angularjs 1.2.7 code
Browse files Browse the repository at this point in the history
  • Loading branch information
m7r committed Jan 8, 2014
1 parent f9646eb commit 7261ead
Show file tree
Hide file tree
Showing 5 changed files with 1,209 additions and 216 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"license": "MIT",
"readmeFilename": "README.md",
"dependencies": {
"showdown": "0.3.1"
"marked": "0.2.9"
},
"peerDependencies": {
"grunt": "0.4.x"
Expand Down
79 changes: 62 additions & 17 deletions src/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,49 @@

exports.DOM = DOM;
exports.htmlEscape = htmlEscape;
exports.normalizeHeaderToId = normalizeHeaderToId;

//////////////////////////////////////////////////////////

function htmlEscape(text){
return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
return text
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/\{\{/g, '<span>{{</span>')
.replace(/\}\}/g, '<span>}}</span>');
}

function nonEmpty(header) {
return !!header;
}

function idFromCurrentHeaders(headers) {
if (headers.length === 1) return headers[0];
// Do not include the first level title, as that's the title of the page.
return headers.slice(1).filter(nonEmpty).join('_');
}

function normalizeHeaderToId(header) {
if (typeof header !== 'string') {
return '';
}

return header.toLowerCase()
.replace(/<.*>/g, '') // html tags
.replace(/[\!\?\:\.\']/g, '') // special characters
.replace(/&#\d\d;/g, '') // html entities
.replace(/\(.*\)/mg, '') // stuff in parenthesis
.replace(/\s$/, '') // trailing spaces
.replace(/\s+/g, '-'); // replace whitespaces with dashes
}


function DOM() {
this.out = [];
this.headingDepth = 0;
this.currentHeaders = [];
this.anchors = [];
}

var INLINE_TAGS = {
Expand All @@ -39,16 +71,28 @@ 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);
}
if (!html) return;

var self = this;
// rewrite header levels, add ids and collect the ids
html = html.replace(/<h(\d)(.*?)>([\s\S]+?)<\/h\1>/gm, function(_, level, attrs, content) {
level = parseInt(level, 10) + self.headingDepth; // change header level based on the context

self.currentHeaders[level - 1] = normalizeHeaderToId(content);
self.currentHeaders.length = level;

var id = idFromCurrentHeaders(self.currentHeaders);
self.anchors.push(id);
return '<h' + level + attrs + ' id="' + id + '">' + content + '</h' + level + '>';
});

// collect anchors
html = html.replace(/<a name="(\w*)">/g, function(match, anchor) {
self.anchors.push(anchor);
return match;
});

this.out.push(html);
},

tag: function(name, attr, text) {
Expand Down Expand Up @@ -79,17 +123,18 @@ DOM.prototype = {

h: function(heading, content, fn){
if (content==undefined || (content instanceof Array && content.length == 0)) return;

this.headingDepth++;
this.currentHeaders[this.headingDepth - 1] = normalizeHeaderToId(heading);
this.currentHeaders.length = this.headingDepth;

var className = null,
anchor = null;
if (typeof heading == 'string') {
var id = heading.
replace(/\(.*\)/mg, '').
replace(/[^\d\w\$]/mg, '.').
replace(/-+/gm, '-').
replace(/-*$/gm, '');
var id = idFromCurrentHeaders(this.currentHeaders);
this.anchors.push(id);
anchor = {'id': id};
var classNameValue = id.toLowerCase().replace(/[._]/mg, '-');
var classNameValue = this.currentHeaders[this.headingDepth - 1]
if(classNameValue == 'hide') classNameValue = '';
className = {'class': classNameValue};
}
Expand Down
7 changes: 5 additions & 2 deletions src/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ exports.Example = function(scenarios) {
this.html = [];
this.css = [];
this.js = [];
this.json = [];
this.unit = [];
this.scenario = [];
this.scenarios = scenarios;
Expand Down Expand Up @@ -88,6 +89,7 @@ exports.Example.prototype.toHtmlEdit = function() {
out.push(' source-edit-html="' + ids(this.html) + '"');
out.push(' source-edit-css="' + ids(this.css) + '"');
out.push(' source-edit-js="' + ids(this.js) + '"');
out.push(' source-edit-json="' + ids(this.json) + '"');
out.push(' source-edit-unit="' + ids(this.unit) + '"');
out.push(' source-edit-scenario="' + ids(this.scenario) + '"');
out.push('></div>\n');
Expand All @@ -102,6 +104,7 @@ exports.Example.prototype.toHtmlTabs = function() {
htmlTabs(this.html);
htmlTabs(this.css);
htmlTabs(this.js);
htmlTabs(this.json);
htmlTabs(this.unit);
htmlTabs(this.scenario);
out.push('</div>');
Expand All @@ -114,7 +117,7 @@ exports.Example.prototype.toHtmlTabs = function() {
name = source.name;

if (name === 'index.html') {
wrap = ' ng-html-wrap-loaded="' + self.module + ' ' + self.deps.join(' ') + '"';
wrap = ' ng-html-wrap="' + self.module + ' ' + self.deps.join(' ') + '"';
}
if (name == 'scenario.js') name = 'End to end test';

Expand All @@ -131,7 +134,7 @@ exports.Example.prototype.toHtmlTabs = function() {

exports.Example.prototype.toHtmlEmbed = function() {
var out = [];
out.push('<div class="well doc-example-live animator-container"');
out.push('<div class="well doc-example-live animate-container"');
if(this.animations) {
out.push(" ng-class=\"{'animations-off':animationsOff == true}\"");
}
Expand Down
Loading

0 comments on commit 7261ead

Please sign in to comment.