Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import utility script for MDN links #363

Merged
merged 1 commit into from
Jul 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 7 additions & 60 deletions lib/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

var MarkdownIt = require('markdown-it');
var fs = require('graceful-fs');
var mdn = require('mdn-links');
var noop = function () {};
var path = require('path');
var TEMPLATE;
Expand Down Expand Up @@ -251,13 +252,11 @@ YUI.add('doc-builder', function (Y) {
}
}
if (!link && self.options.linkNatives) {
if (self.NATIVES && self.NATIVES[item]) {
href = self.NATIVES_LINKER(item);
if (href) {
className += ' external';
newWin = true;
link = true;
}
href = mdn.getLink.apply(mdn, item.split('/'));
if (href) {
className += ' external';
newWin = true;
link = true;
}
}
if (link) {
Expand All @@ -271,59 +270,7 @@ YUI.add('doc-builder', function (Y) {
}
return (raw) ? href : item;
},
/**
* List of native types to cross link to MDN
* @property NATIVES
* @type Object
*/
NATIVES: {
'Array': 1,
'Boolean': 1,
'Date': 1,
'decodeURI': 1,
'decodeURIComponent': 1,
'encodeURI': 1,
'encodeURIComponent': 1,
'eval': 1,
'Error': 1,
'EvalError': 1,
'Function': 1,
'Infinity': 1,
'isFinite': 1,
'isNaN': 1,
'Math': 1,
'NaN': 1,
'Number': 1,
'Object': 1,
'parseFloat': 1,
'parseInt': 1,
'RangeError': 1,
'ReferenceError': 1,
'RegExp': 1,
'String': 1,
'SyntaxError': 1,
'TypeError': 1,
'undefined': 1,
'URIError': 1,
'HTMLElement': 'https:/' + '/developer.mozilla.org/en/Document_Object_Model_(DOM)/',
'HTMLCollection': 'https:/' + '/developer.mozilla.org/en/Document_Object_Model_(DOM)/',
'DocumentFragment': 'https:/' + '/developer.mozilla.org/en/Document_Object_Model_(DOM)/',
'HTMLDocument': 'https:/' + '/developer.mozilla.org/en/Document_Object_Model_(DOM)/'
},
/**
* Function to link an external type uses `NATIVES` object
* @method NATIVES_LINKER
* @private
* @param {String} name The name of the type to link
* @return {String} The combined URL
*/
NATIVES_LINKER: function (name) {
var url = 'https:/' + '/developer.mozilla.org/en/JavaScript/Reference/Global_Objects/';
if (this.NATIVES[name] !== 1) {
url = this.NATIVES[name];
}
return url + name;
},

/**
* Mixes the various external data soures together into the local data, augmenting
* it with flags.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"express": "^4.13.0",
"graceful-fs": "^4.1.2",
"markdown-it": "^4.2.2",
"mdn-links": "^0.1.0",
"minimatch": "^2.0.8",
"rimraf": "2.x",
"yui": "^3.18.1"
Expand Down