markdown-it-include
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -1,2 +0,2 @@ | ||
/*! markdown-it-include 1.0.1 https://github.com//camelaissani//markdown-it-include @license MIT */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.markdownitInclude = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ | ||
/*! markdown-it-include 1.1.0 https://github.com//camelaissani//markdown-it-include @license MIT */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.markdownitInclude = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ | ||
@@ -503,3 +503,15 @@ },{}],2:[function(require,module,exports){ | ||
module.exports = function include_plugin(md, basedir) { | ||
module.exports = function include_plugin(md, options) { | ||
var root = '.', | ||
includeRe = INCLUDE_RE; | ||
if (options) { | ||
if (typeof options === 'string') { | ||
root = options; | ||
} else { | ||
root = options.root || root; | ||
includeRe = options.includeRe || includeRe; | ||
} | ||
} | ||
function _replaceIncludeByContent(src, rootdir, parentFilePath, filesProcessed) { | ||
@@ -513,4 +525,4 @@ filesProcessed = filesProcessed ? filesProcessed.slice() : []; // making a copy | ||
} | ||
while ((cap = INCLUDE_RE.exec(src))) { | ||
filePath = path.resolve(rootdir, cap[1]); | ||
while ((cap = includeRe.exec(src))) { | ||
filePath = path.resolve(rootdir, cap[1].trim()); | ||
@@ -532,4 +544,3 @@ // check if circular reference | ||
function _includeFileParts(state) { | ||
var rootdir = basedir || '.'; | ||
state.src = _replaceIncludeByContent(state.src, rootdir); | ||
state.src = _replaceIncludeByContent(state.src, root); | ||
} | ||
@@ -536,0 +547,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).markdownitInclude=e()}}(function(){return function o(u,f,s){function c(r,e){if(!f[r]){if(!u[r]){var n="function"==typeof require&&require;if(!e&&n)return n(r,!0);if(l)return l(r,!0);var t=new Error("Cannot find module '"+r+"'");throw t.code="MODULE_NOT_FOUND",t}var i=f[r]={exports:{}};u[r][0].call(i.exports,function(e){return c(u[r][1][e]||e)},i,i.exports,o,u,f,s)}return f[r].exports}for(var l="function"==typeof require&&require,e=0;e<s.length;e++)c(s[e]);return c}({1:[function(e,r,n){},{}],2:[function(e,r,c){(function(i){function o(e,r){for(var n=0,t=e.length-1;0<=t;t--){var i=e[t];"."===i?e.splice(t,1):".."===i?(e.splice(t,1),n++):n&&(e.splice(t,1),n--)}if(r)for(;n--;n)e.unshift("..");return e}function u(e,r){if(e.filter)return e.filter(r);for(var n=[],t=0;t<e.length;t++)r(e[t],t,e)&&n.push(e[t]);return n}c.resolve=function(){for(var e="",r=!1,n=arguments.length-1;-1<=n&&!r;n--){var t=0<=n?arguments[n]:i.cwd();if("string"!=typeof t)throw new TypeError("Arguments to path.resolve must be strings");t&&(e=t+"/"+e,r="/"===t.charAt(0))}return(r?"/":"")+(e=o(u(e.split("/"),function(e){return!!e}),!r).join("/"))||"."},c.normalize=function(e){var r=c.isAbsolute(e),n="/"===t(e,-1);return(e=o(u(e.split("/"),function(e){return!!e}),!r).join("/"))||r||(e="."),e&&n&&(e+="/"),(r?"/":"")+e},c.isAbsolute=function(e){return"/"===e.charAt(0)},c.join=function(){var e=Array.prototype.slice.call(arguments,0);return c.normalize(u(e,function(e,r){if("string"!=typeof e)throw new TypeError("Arguments to path.join must be strings");return e}).join("/"))},c.relative=function(e,r){function n(e){for(var r=0;r<e.length&&""===e[r];r++);for(var n=e.length-1;0<=n&&""===e[n];n--);return n<r?[]:e.slice(r,n-r+1)}e=c.resolve(e).substr(1),r=c.resolve(r).substr(1);for(var t=n(e.split("/")),i=n(r.split("/")),o=Math.min(t.length,i.length),u=o,f=0;f<o;f++)if(t[f]!==i[f]){u=f;break}var s=[];for(f=u;f<t.length;f++)s.push("..");return(s=s.concat(i.slice(u))).join("/")},c.sep="/",c.delimiter=":",c.dirname=function(e){if("string"!=typeof e&&(e+=""),0===e.length)return".";for(var r=e.charCodeAt(0),n=47===r,t=-1,i=!0,o=e.length-1;1<=o;--o)if(47===(r=e.charCodeAt(o))){if(!i){t=o;break}}else i=!1;return-1===t?n?"/":".":n&&1===t?"/":e.slice(0,t)},c.basename=function(e,r){var n=function(e){"string"!=typeof e&&(e+="");var r,n=0,t=-1,i=!0;for(r=e.length-1;0<=r;--r)if(47===e.charCodeAt(r)){if(!i){n=r+1;break}}else-1===t&&(i=!1,t=r+1);return-1===t?"":e.slice(n,t)}(e);return r&&n.substr(-1*r.length)===r&&(n=n.substr(0,n.length-r.length)),n},c.extname=function(e){"string"!=typeof e&&(e+="");for(var r=-1,n=0,t=-1,i=!0,o=0,u=e.length-1;0<=u;--u){var f=e.charCodeAt(u);if(47===f){if(i)continue;n=u+1;break}-1===t&&(i=!1,t=u+1),46===f?-1===r?r=u:1!==o&&(o=1):-1!==r&&(o=-1)}return-1===r||-1===t||0===o||1===o&&r===t-1&&r===n+1?"":e.slice(r,t)};var t="b"==="ab".substr(-1)?function(e,r,n){return e.substr(r,n)}:function(e,r,n){return r<0&&(r=e.length+r),e.substr(r,n)}}).call(this,e("_process"))},{_process:3}],3:[function(e,r,n){var t,i,o=r.exports={};function u(){throw new Error("setTimeout has not been defined")}function f(){throw new Error("clearTimeout has not been defined")}function s(r){if(t===setTimeout)return setTimeout(r,0);if((t===u||!t)&&setTimeout)return t=setTimeout,setTimeout(r,0);try{return t(r,0)}catch(e){try{return t.call(null,r,0)}catch(e){return t.call(this,r,0)}}}!function(){try{t="function"==typeof setTimeout?setTimeout:u}catch(e){t=u}try{i="function"==typeof clearTimeout?clearTimeout:f}catch(e){i=f}}();var c,l=[],a=!1,h=-1;function p(){a&&c&&(a=!1,c.length?l=c.concat(l):h=-1,l.length&&d())}function d(){if(!a){var e=s(p);a=!0;for(var r=l.length;r;){for(c=l,l=[];++h<r;)c&&c[h].run();h=-1,r=l.length}c=null,a=!1,function(r){if(i===clearTimeout)return clearTimeout(r);if((i===f||!i)&&clearTimeout)return i=clearTimeout,clearTimeout(r);try{i(r)}catch(e){try{return i.call(null,r)}catch(e){return i.call(this,r)}}}(e)}}function v(e,r){this.fun=e,this.array=r}function g(){}o.nextTick=function(e){var r=new Array(arguments.length-1);if(1<arguments.length)for(var n=1;n<arguments.length;n++)r[n-1]=arguments[n];l.push(new v(e,r)),1!==l.length||a||s(d)},v.prototype.run=function(){this.fun.apply(null,this.array)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=g,o.addListener=g,o.once=g,o.off=g,o.removeListener=g,o.removeAllListeners=g,o.emit=g,o.prependListener=g,o.prependOnceListener=g,o.listeners=function(e){return[]},o.binding=function(e){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(e){throw new Error("process.chdir is not supported")},o.umask=function(){return 0}},{}],4:[function(e,r,n){"use strict";var c=e("path"),l=e("fs"),a=/\!{3}\s*include\s*\(\s*(.+?)\s*\)\s*\!{3}/i;r.exports=function(e,n){e.core.ruler.before("normalize","include",function(e){var r=n||".";e.src=function e(r,n,t,i){var o,u,f,s;for(i=i?i.slice():[],t&&i.push(t);o=a.exec(r);){if(u=c.resolve(n,o[1]),-1!==(s=i.indexOf(u)))throw new Error("Circular reference between "+u+" and "+i[s]);f=e(f=l.readFileSync(u,"utf8"),c.dirname(u),u,i),r=r.slice(0,o.index)+f+r.slice(o.index+o[0].length,r.length)}return r}(e.src,r)})}},{fs:1,path:2}]},{},[4])(4)}); | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).markdownitInclude=e()}}(function(){return function o(u,f,s){function c(r,e){if(!f[r]){if(!u[r]){var n="function"==typeof require&&require;if(!e&&n)return n(r,!0);if(l)return l(r,!0);var t=new Error("Cannot find module '"+r+"'");throw t.code="MODULE_NOT_FOUND",t}var i=f[r]={exports:{}};u[r][0].call(i.exports,function(e){return c(u[r][1][e]||e)},i,i.exports,o,u,f,s)}return f[r].exports}for(var l="function"==typeof require&&require,e=0;e<s.length;e++)c(s[e]);return c}({1:[function(e,r,n){},{}],2:[function(e,r,c){(function(i){function o(e,r){for(var n=0,t=e.length-1;0<=t;t--){var i=e[t];"."===i?e.splice(t,1):".."===i?(e.splice(t,1),n++):n&&(e.splice(t,1),n--)}if(r)for(;n--;n)e.unshift("..");return e}function u(e,r){if(e.filter)return e.filter(r);for(var n=[],t=0;t<e.length;t++)r(e[t],t,e)&&n.push(e[t]);return n}c.resolve=function(){for(var e="",r=!1,n=arguments.length-1;-1<=n&&!r;n--){var t=0<=n?arguments[n]:i.cwd();if("string"!=typeof t)throw new TypeError("Arguments to path.resolve must be strings");t&&(e=t+"/"+e,r="/"===t.charAt(0))}return(r?"/":"")+(e=o(u(e.split("/"),function(e){return!!e}),!r).join("/"))||"."},c.normalize=function(e){var r=c.isAbsolute(e),n="/"===t(e,-1);return(e=o(u(e.split("/"),function(e){return!!e}),!r).join("/"))||r||(e="."),e&&n&&(e+="/"),(r?"/":"")+e},c.isAbsolute=function(e){return"/"===e.charAt(0)},c.join=function(){var e=Array.prototype.slice.call(arguments,0);return c.normalize(u(e,function(e,r){if("string"!=typeof e)throw new TypeError("Arguments to path.join must be strings");return e}).join("/"))},c.relative=function(e,r){function n(e){for(var r=0;r<e.length&&""===e[r];r++);for(var n=e.length-1;0<=n&&""===e[n];n--);return n<r?[]:e.slice(r,n-r+1)}e=c.resolve(e).substr(1),r=c.resolve(r).substr(1);for(var t=n(e.split("/")),i=n(r.split("/")),o=Math.min(t.length,i.length),u=o,f=0;f<o;f++)if(t[f]!==i[f]){u=f;break}var s=[];for(f=u;f<t.length;f++)s.push("..");return(s=s.concat(i.slice(u))).join("/")},c.sep="/",c.delimiter=":",c.dirname=function(e){if("string"!=typeof e&&(e+=""),0===e.length)return".";for(var r=e.charCodeAt(0),n=47===r,t=-1,i=!0,o=e.length-1;1<=o;--o)if(47===(r=e.charCodeAt(o))){if(!i){t=o;break}}else i=!1;return-1===t?n?"/":".":n&&1===t?"/":e.slice(0,t)},c.basename=function(e,r){var n=function(e){"string"!=typeof e&&(e+="");var r,n=0,t=-1,i=!0;for(r=e.length-1;0<=r;--r)if(47===e.charCodeAt(r)){if(!i){n=r+1;break}}else-1===t&&(i=!1,t=r+1);return-1===t?"":e.slice(n,t)}(e);return r&&n.substr(-1*r.length)===r&&(n=n.substr(0,n.length-r.length)),n},c.extname=function(e){"string"!=typeof e&&(e+="");for(var r=-1,n=0,t=-1,i=!0,o=0,u=e.length-1;0<=u;--u){var f=e.charCodeAt(u);if(47===f){if(i)continue;n=u+1;break}-1===t&&(i=!1,t=u+1),46===f?-1===r?r=u:1!==o&&(o=1):-1!==r&&(o=-1)}return-1===r||-1===t||0===o||1===o&&r===t-1&&r===n+1?"":e.slice(r,t)};var t="b"==="ab".substr(-1)?function(e,r,n){return e.substr(r,n)}:function(e,r,n){return r<0&&(r=e.length+r),e.substr(r,n)}}).call(this,e("_process"))},{_process:3}],3:[function(e,r,n){var t,i,o=r.exports={};function u(){throw new Error("setTimeout has not been defined")}function f(){throw new Error("clearTimeout has not been defined")}function s(r){if(t===setTimeout)return setTimeout(r,0);if((t===u||!t)&&setTimeout)return t=setTimeout,setTimeout(r,0);try{return t(r,0)}catch(e){try{return t.call(null,r,0)}catch(e){return t.call(this,r,0)}}}!function(){try{t="function"==typeof setTimeout?setTimeout:u}catch(e){t=u}try{i="function"==typeof clearTimeout?clearTimeout:f}catch(e){i=f}}();var c,l=[],a=!1,h=-1;function p(){a&&c&&(a=!1,c.length?l=c.concat(l):h=-1,l.length&&d())}function d(){if(!a){var e=s(p);a=!0;for(var r=l.length;r;){for(c=l,l=[];++h<r;)c&&c[h].run();h=-1,r=l.length}c=null,a=!1,function(r){if(i===clearTimeout)return clearTimeout(r);if((i===f||!i)&&clearTimeout)return i=clearTimeout,clearTimeout(r);try{i(r)}catch(e){try{return i.call(null,r)}catch(e){return i.call(this,r)}}}(e)}}function g(e,r){this.fun=e,this.array=r}function v(){}o.nextTick=function(e){var r=new Array(arguments.length-1);if(1<arguments.length)for(var n=1;n<arguments.length;n++)r[n-1]=arguments[n];l.push(new g(e,r)),1!==l.length||a||s(d)},g.prototype.run=function(){this.fun.apply(null,this.array)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=v,o.addListener=v,o.once=v,o.off=v,o.removeListener=v,o.removeAllListeners=v,o.emit=v,o.prependListener=v,o.prependOnceListener=v,o.listeners=function(e){return[]},o.binding=function(e){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(e){throw new Error("process.chdir is not supported")},o.umask=function(){return 0}},{}],4:[function(e,r,n){"use strict";var l=e("path"),a=e("fs"),t=/\!{3}\s*include\s*\(\s*(.+?)\s*\)\s*\!{3}/i;r.exports=function(e,r){var n=".",c=t;r&&("string"==typeof r?n=r:(n=r.root||n,c=r.includeRe||c)),e.core.ruler.before("normalize","include",function(e){e.src=function e(r,n,t,i){var o,u,f,s;for(i=i?i.slice():[],t&&i.push(t);o=c.exec(r);){if(u=l.resolve(n,o[1].trim()),-1!==(s=i.indexOf(u)))throw new Error("Circular reference between "+u+" and "+i[s]);f=e(f=a.readFileSync(u,"utf8"),l.dirname(u),u,i),r=r.slice(0,o.index)+f+r.slice(o.index+o[0].length,r.length)}return r}(e.src,n)})}},{fs:1,path:2}]},{},[4])(4)}); |
21
index.js
@@ -8,3 +8,15 @@ 'use strict'; | ||
module.exports = function include_plugin(md, basedir) { | ||
module.exports = function include_plugin(md, options) { | ||
var root = '.', | ||
includeRe = INCLUDE_RE; | ||
if (options) { | ||
if (typeof options === 'string') { | ||
root = options; | ||
} else { | ||
root = options.root || root; | ||
includeRe = options.includeRe || includeRe; | ||
} | ||
} | ||
function _replaceIncludeByContent(src, rootdir, parentFilePath, filesProcessed) { | ||
@@ -18,4 +30,4 @@ filesProcessed = filesProcessed ? filesProcessed.slice() : []; // making a copy | ||
} | ||
while ((cap = INCLUDE_RE.exec(src))) { | ||
filePath = path.resolve(rootdir, cap[1]); | ||
while ((cap = includeRe.exec(src))) { | ||
filePath = path.resolve(rootdir, cap[1].trim()); | ||
@@ -37,4 +49,3 @@ // check if circular reference | ||
function _includeFileParts(state) { | ||
var rootdir = basedir || '.'; | ||
state.src = _replaceIncludeByContent(state.src, rootdir); | ||
state.src = _replaceIncludeByContent(state.src, root); | ||
} | ||
@@ -41,0 +52,0 @@ |
{ | ||
"name": "markdown-it-include", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Markdown-it plugin which adds the ability to include markdown fragment files.", | ||
@@ -9,3 +9,3 @@ "keywords": [ | ||
"markdown", | ||
"inlcude" | ||
"include" | ||
], | ||
@@ -12,0 +12,0 @@ "repository": { |
@@ -58,2 +58,25 @@ # markdown-it-include | ||
## Options | ||
```js | ||
var md = require('markdown-it')() | ||
.use(require('markdown-it-include'), [, options]); | ||
``` | ||
* Type: `String|Object` | ||
If it's a string, it's the same as `options.root`. | ||
### root | ||
* Type: `String` | ||
* Default: `.` | ||
`root` is the base directory of all the markdown files. | ||
### includeRe | ||
* Type: `RegExp` | ||
* Default: `/\!{3}\s*include\s*\(\s*(.+?)\s*\)\s*\!{3}/i` | ||
By default the `!!!include( )!!!` statement is used to include markdown fragment files. This option allows to change the regular expression and then customize this statement. | ||
## Disclaimer | ||
@@ -60,0 +83,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28866
570
88