Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mokuji.js

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mokuji.js - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

.editorconfig

307

dist/mokuji.js
/*!
* mokuji.js v1.0.0
* mokuji.js v1.1.0
* https://github.com/hiro0218/mokuji.js

@@ -150,4 +150,6 @@ *

});
exports.init = init;
exports.init = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _extend = __webpack_require__(0);

@@ -163,2 +165,4 @@

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
'use strict';

@@ -170,186 +174,209 @@

function init(element, options) {
if (!element) {
return;
}
var init = exports.init = function () {
function init(element, options) {
_classCallCheck(this, init);
// set options
options = (0, _extend2.default)(defaults, options);
if (!element) {
return;
}
// generate mokuji list
var mokuji = generateMokuji(element, options);
// set options
options = (0, _extend2.default)(defaults, options);
if (!mokuji) {
return;
// mokuji start
var mokuji = this.start(element, options);
return mokuji;
}
// remove duplicates by adding suffix
removeDuplicateIds(mokuji);
_createClass(init, [{
key: 'start',
value: function start(element, options) {
// generate mokuji list
var mokuji = this.generateMokuji(element, options);
return mokuji;
}
if (!mokuji) {
return;
}
function createHeadingWalker(element) {
return document.createTreeWalker(element, NodeFilter.SHOW_ELEMENT, function (node) {
return (/^H[1-6]$/.test(node.tagName) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
);
}, false);
}
// remove duplicates by adding suffix
this.removeDuplicateIds(mokuji);
function generateMokuji(element, options) {
// get heading tags
var walker = createHeadingWalker(element);
var node = null;
var number = 1;
return mokuji;
}
}, {
key: 'generateMokuji',
value: function generateMokuji(element, options) {
// get heading tags
var walker = this.createHeadingWalker(element);
var node = null;
var number = 1;
var ol = document.createElement('ol');
var li = document.createElement('li');
var a = document.createElement('a');
var ol = document.createElement('ol');
var li = document.createElement('li');
var a = document.createElement('a');
while (node = walker.nextNode()) {
var currentNumber = node.tagName.match(/\d/g).join(''); // heading number
while (node = walker.nextNode()) {
var currentNumber = node.tagName.match(/\d/g).join(''); // heading number
// check list hierarchy
if (number < currentNumber) {
// number of the heading is large (small as heading)
var next = document.createElement('ol');
ol.lastChild.appendChild(next);
ol = next;
} else if (number > currentNumber) {
// number of heading is small (large as heading)
for (var i = 0; i < number - currentNumber; i++) {
if ((0, _hasParentNode2.default)(ol, ol.parentNode)) {
ol = ol.parentNode.parentNode;
// check list hierarchy
if (number < currentNumber) {
// number of the heading is large (small as heading)
var next = document.createElement('ol');
ol.lastChild.appendChild(next);
ol = next;
} else if (number > currentNumber) {
// number of heading is small (large as heading)
for (var i = 0; i < number - currentNumber; i++) {
if ((0, _hasParentNode2.default)(ol, ol.parentNode)) {
ol = ol.parentNode.parentNode;
}
}
}
}
}
// add to wrapper
node.id = setAnchor(node.id, node.textContent, options.anchorType);
ol.appendChild(buildList(node, a.cloneNode(false), li.cloneNode(false)));
// add to wrapper
node.id = this.setAnchor(node.id, node.textContent, options.anchorType);
ol.appendChild(this.buildList(node, a.cloneNode(false), li.cloneNode(false)));
// upadte current number
number = currentNumber;
}
// upadte current number
number = currentNumber;
}
ol = reverseMokuji(ol);
ol = this.reverseMokuji(ol);
return ol;
}
return ol;
}
}, {
key: 'createHeadingWalker',
value: function createHeadingWalker(element) {
return document.createTreeWalker(element, NodeFilter.SHOW_ELEMENT, function (node) {
return (/^H[1-6]$/.test(node.tagName) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
);
}, false);
}
}, {
key: 'setAnchor',
value: function setAnchor(id, text, type) {
// convert spaces to _
var anchor = id || this.replaceSpace2Underscore(text);
function setAnchor(id, text, type) {
// convert spaces to _
var anchor = id || replaceSpace2Underscore(text);
// remove &
anchor = anchor.replace(/\&+/g, '');
anchor = anchor.replace(/\&amp;+/g, '');
// remove &
anchor = anchor.replace(/\&+/g, '');
anchor = anchor.replace(/\&amp;+/g, '');
if (type === 'wikipedia') {
anchor = encodeURIComponent(anchor);
anchor = anchor.replace(/\%+/g, '.');
}
if (type === 'wikipedia') {
anchor = encodeURIComponent(anchor);
anchor = anchor.replace(/\%+/g, '.');
}
return anchor;
}
}, {
key: 'replaceSpace2Underscore',
value: function replaceSpace2Underscore(text) {
return String(text).replace(/\s+/g, '_');
}
}, {
key: 'buildList',
value: function buildList(node, a, li) {
a.href = '#' + node.id;
a.textContent = node.textContent;
li.appendChild(a);
return anchor;
}
return li;
}
}, {
key: 'reverseMokuji',
value: function reverseMokuji(ol) {
while (ol.parentNode) {
ol = ol.parentNode;
}
function replaceSpace2Underscore(text) {
return String(text).replace(/\s+/g, '_');
}
return ol;
}
}, {
key: 'removeDuplicateIds',
value: function removeDuplicateIds(mokuji) {
var lists = mokuji.getElementsByTagName('a');
function buildList(node, a, li) {
a.href = '#' + node.id;
a.textContent = node.textContent;
li.appendChild(a);
for (var i = 0; i < lists.length; i++) {
var id = lists[i].innerText;
var hash = lists[i].hash;
var headings = document.querySelectorAll('[id="' + id + '"]');
return li;
}
if (headings.length === 1) {
continue;
}
function reverseMokuji(ol) {
while (ol.parentNode) {
ol = ol.parentNode;
}
// duplicated id
var count = 0;
return ol;
}
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
function removeDuplicateIds(mokuji) {
var lists = mokuji.getElementsByTagName('a');
try {
for (var _iterator = headings[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var heading = _step.value;
for (var i = 0; i < lists.length; i++) {
var id = lists[i].innerText;
var hash = lists[i].hash;
var headings = document.querySelectorAll('[id="' + id + '"]');
var id = heading.id + '-' + count;
if (headings.length === 1) {
continue;
}
// search duplicate list
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
// duplicated id
var count = 0;
try {
for (var _iterator2 = lists[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var list = _step2.value;
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
if (list.hash === hash) {
// update hash
list.href = '#' + id;
break;
}
}
try {
for (var _iterator = headings[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var heading = _step.value;
// update id
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
var id = heading.id + '-' + count;
// search duplicate list
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = lists[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var list = _step2.value;
if (list.hash === hash) {
// update hash
list.href = '#' + id;
break;
}
heading.id = id;
count++;
}
// update id
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
if (_didIteratorError) {
throw _iteratorError;
}
}
}
heading.id = id;
count++;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
}
}]);
return init;
}();
/***/ })
/******/ ]);
});
/*!
* mokuji.js v1.0.0
* mokuji.js v1.1.0
* https://github.com/hiro0218/mokuji.js

@@ -7,2 +7,2 @@ *

*/
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Mokuji=t():e.Mokuji=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.i=function(e){return e},t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e["default"]}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=2)}([function(e,t,r){"use strict";e.exports=function(e,t){var r,n={};for(r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);for(r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r]);return n}},function(e,t,r){"use strict";e.exports=function(e,t){for(;e;){if(e===t)return!0;e=e.parentNode}return!1}},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e,t){if(e){t=(0,s["default"])(h,t);var r=a(e,t);if(r)return d(r),r}}function i(e){return document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,function(e){return/^H[1-6]$/.test(e.tagName)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},!1)}function a(e,t){for(var r=i(e),n=null,o=1,a=document.createElement("ol"),c=document.createElement("li"),d=document.createElement("a");n=r.nextNode();){var p=n.tagName.match(/\d/g).join("");if(o<p){var s=document.createElement("ol");a.lastChild.appendChild(s),a=s}else if(o>p)for(var y=0;y<o-p;y++)(0,m["default"])(a,a.parentNode)&&(a=a.parentNode.parentNode);n.id=u(n.id,n.textContent,t.anchorType),a.appendChild(f(n,d.cloneNode(!1),c.cloneNode(!1))),o=p}return a=l(a)}function u(e,t,r){var n=e||c(t);return n=n.replace(/\&+/g,""),n=n.replace(/\&amp;+/g,""),"wikipedia"===r&&(n=encodeURIComponent(n),n=n.replace(/\%+/g,".")),n}function c(e){return String(e).replace(/\s+/g,"_")}function f(e,t,r){return t.href="#"+e.id,t.textContent=e.textContent,r.appendChild(t),r}function l(e){for(;e.parentNode;)e=e.parentNode;return e}function d(e){for(var t=e.getElementsByTagName("a"),r=0;r<t.length;r++){var n=t[r].innerText,o=t[r].hash,i=document.querySelectorAll('[id="'+n+'"]');if(1!==i.length){var a=0,u=!0,c=!1,f=undefined;try{for(var l,d=i[Symbol.iterator]();!(u=(l=d.next()).done);u=!0){var p=l.value,n=p.id+"-"+a,s=!0,y=!1,m=undefined;try{for(var h,v=t[Symbol.iterator]();!(s=(h=v.next()).done);s=!0){var x=h.value;if(x.hash===o){x.href="#"+n;break}}}catch(e){y=!0,m=e}finally{try{!s&&v["return"]&&v["return"]()}finally{if(y)throw m}}p.id=n,a++}}catch(e){c=!0,f=e}finally{try{!u&&d["return"]&&d["return"]()}finally{if(c)throw f}}}}}Object.defineProperty(t,"__esModule",{value:!0}),t.init=o;var p=r(0),s=n(p),y=r(1),m=n(y),h={anchorType:""}}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Mokuji=t():e.Mokuji=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.i=function(e){return e},t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e["default"]}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=2)}([function(e,t,r){"use strict";e.exports=function(e,t){var r,n={};for(r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);for(r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r]);return n}},function(e,t,r){"use strict";e.exports=function(e,t){for(;e;){if(e===t)return!0;e=e.parentNode}return!1}},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0}),t.init=undefined;var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),a=r(0),u=n(a),c=r(1),l=n(c),f={anchorType:""};t.init=function(){function e(t,r){if(o(this,e),t){r=(0,u["default"])(f,r);return this.start(t,r)}}return i(e,[{key:"start",value:function(e,t){var r=this.generateMokuji(e,t);if(r)return this.removeDuplicateIds(r),r}},{key:"generateMokuji",value:function(e,t){for(var r=this.createHeadingWalker(e),n=null,o=1,i=document.createElement("ol"),a=document.createElement("li"),u=document.createElement("a");n=r.nextNode();){var c=n.tagName.match(/\d/g).join("");if(o<c){var f=document.createElement("ol");i.lastChild.appendChild(f),i=f}else if(o>c)for(var d=0;d<o-c;d++)(0,l["default"])(i,i.parentNode)&&(i=i.parentNode.parentNode);n.id=this.setAnchor(n.id,n.textContent,t.anchorType),i.appendChild(this.buildList(n,u.cloneNode(!1),a.cloneNode(!1))),o=c}return i=this.reverseMokuji(i)}},{key:"createHeadingWalker",value:function(e){return document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,function(e){return/^H[1-6]$/.test(e.tagName)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},!1)}},{key:"setAnchor",value:function(e,t,r){var n=e||this.replaceSpace2Underscore(t);return n=n.replace(/\&+/g,""),n=n.replace(/\&amp;+/g,""),"wikipedia"===r&&(n=encodeURIComponent(n),n=n.replace(/\%+/g,".")),n}},{key:"replaceSpace2Underscore",value:function(e){return String(e).replace(/\s+/g,"_")}},{key:"buildList",value:function(e,t,r){return t.href="#"+e.id,t.textContent=e.textContent,r.appendChild(t),r}},{key:"reverseMokuji",value:function(e){for(;e.parentNode;)e=e.parentNode;return e}},{key:"removeDuplicateIds",value:function(e){for(var t=e.getElementsByTagName("a"),r=0;r<t.length;r++){var n=t[r].innerText,o=t[r].hash,i=document.querySelectorAll('[id="'+n+'"]');if(1!==i.length){var a=0,u=!0,c=!1,l=undefined;try{for(var f,d=i[Symbol.iterator]();!(u=(f=d.next()).done);u=!0){var p=f.value,n=p.id+"-"+a,s=!0,y=!1,h=undefined;try{for(var v,m=t[Symbol.iterator]();!(s=(v=m.next()).done);s=!0){var b=v.value;if(b.hash===o){b.href="#"+n;break}}}catch(e){y=!0,h=e}finally{try{!s&&m["return"]&&m["return"]()}finally{if(y)throw h}}p.id=n,a++}}catch(e){c=!0,l=e}finally{try{!u&&d["return"]&&d["return"]()}finally{if(c)throw l}}}}}}]),e}()}])});

@@ -6,4 +6,6 @@ 'use strict';

});
exports.init = init;
exports.init = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _extend = require('./extend');

@@ -19,2 +21,4 @@

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
'use strict';

@@ -26,182 +30,205 @@

function init(element, options) {
if (!element) {
return;
}
var init = exports.init = function () {
function init(element, options) {
_classCallCheck(this, init);
// set options
options = (0, _extend2.default)(defaults, options);
if (!element) {
return;
}
// generate mokuji list
var mokuji = generateMokuji(element, options);
// set options
options = (0, _extend2.default)(defaults, options);
if (!mokuji) {
return;
// mokuji start
var mokuji = this.start(element, options);
return mokuji;
}
// remove duplicates by adding suffix
removeDuplicateIds(mokuji);
_createClass(init, [{
key: 'start',
value: function start(element, options) {
// generate mokuji list
var mokuji = this.generateMokuji(element, options);
return mokuji;
}
if (!mokuji) {
return;
}
function createHeadingWalker(element) {
return document.createTreeWalker(element, NodeFilter.SHOW_ELEMENT, function (node) {
return (/^H[1-6]$/.test(node.tagName) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
);
}, false);
}
// remove duplicates by adding suffix
this.removeDuplicateIds(mokuji);
function generateMokuji(element, options) {
// get heading tags
var walker = createHeadingWalker(element);
var node = null;
var number = 1;
return mokuji;
}
}, {
key: 'generateMokuji',
value: function generateMokuji(element, options) {
// get heading tags
var walker = this.createHeadingWalker(element);
var node = null;
var number = 1;
var ol = document.createElement('ol');
var li = document.createElement('li');
var a = document.createElement('a');
var ol = document.createElement('ol');
var li = document.createElement('li');
var a = document.createElement('a');
while (node = walker.nextNode()) {
var currentNumber = node.tagName.match(/\d/g).join(''); // heading number
while (node = walker.nextNode()) {
var currentNumber = node.tagName.match(/\d/g).join(''); // heading number
// check list hierarchy
if (number < currentNumber) {
// number of the heading is large (small as heading)
var next = document.createElement('ol');
ol.lastChild.appendChild(next);
ol = next;
} else if (number > currentNumber) {
// number of heading is small (large as heading)
for (var i = 0; i < number - currentNumber; i++) {
if ((0, _hasParentNode2.default)(ol, ol.parentNode)) {
ol = ol.parentNode.parentNode;
// check list hierarchy
if (number < currentNumber) {
// number of the heading is large (small as heading)
var next = document.createElement('ol');
ol.lastChild.appendChild(next);
ol = next;
} else if (number > currentNumber) {
// number of heading is small (large as heading)
for (var i = 0; i < number - currentNumber; i++) {
if ((0, _hasParentNode2.default)(ol, ol.parentNode)) {
ol = ol.parentNode.parentNode;
}
}
}
}
}
// add to wrapper
node.id = setAnchor(node.id, node.textContent, options.anchorType);
ol.appendChild(buildList(node, a.cloneNode(false), li.cloneNode(false)));
// add to wrapper
node.id = this.setAnchor(node.id, node.textContent, options.anchorType);
ol.appendChild(this.buildList(node, a.cloneNode(false), li.cloneNode(false)));
// upadte current number
number = currentNumber;
}
// upadte current number
number = currentNumber;
}
ol = reverseMokuji(ol);
ol = this.reverseMokuji(ol);
return ol;
}
return ol;
}
}, {
key: 'createHeadingWalker',
value: function createHeadingWalker(element) {
return document.createTreeWalker(element, NodeFilter.SHOW_ELEMENT, function (node) {
return (/^H[1-6]$/.test(node.tagName) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
);
}, false);
}
}, {
key: 'setAnchor',
value: function setAnchor(id, text, type) {
// convert spaces to _
var anchor = id || this.replaceSpace2Underscore(text);
function setAnchor(id, text, type) {
// convert spaces to _
var anchor = id || replaceSpace2Underscore(text);
// remove &
anchor = anchor.replace(/\&+/g, '');
anchor = anchor.replace(/\&amp;+/g, '');
// remove &
anchor = anchor.replace(/\&+/g, '');
anchor = anchor.replace(/\&amp;+/g, '');
if (type === 'wikipedia') {
anchor = encodeURIComponent(anchor);
anchor = anchor.replace(/\%+/g, '.');
}
if (type === 'wikipedia') {
anchor = encodeURIComponent(anchor);
anchor = anchor.replace(/\%+/g, '.');
}
return anchor;
}
}, {
key: 'replaceSpace2Underscore',
value: function replaceSpace2Underscore(text) {
return String(text).replace(/\s+/g, '_');
}
}, {
key: 'buildList',
value: function buildList(node, a, li) {
a.href = '#' + node.id;
a.textContent = node.textContent;
li.appendChild(a);
return anchor;
}
return li;
}
}, {
key: 'reverseMokuji',
value: function reverseMokuji(ol) {
while (ol.parentNode) {
ol = ol.parentNode;
}
function replaceSpace2Underscore(text) {
return String(text).replace(/\s+/g, '_');
}
return ol;
}
}, {
key: 'removeDuplicateIds',
value: function removeDuplicateIds(mokuji) {
var lists = mokuji.getElementsByTagName('a');
function buildList(node, a, li) {
a.href = '#' + node.id;
a.textContent = node.textContent;
li.appendChild(a);
for (var i = 0; i < lists.length; i++) {
var id = lists[i].innerText;
var hash = lists[i].hash;
var headings = document.querySelectorAll('[id="' + id + '"]');
return li;
}
if (headings.length === 1) {
continue;
}
function reverseMokuji(ol) {
while (ol.parentNode) {
ol = ol.parentNode;
}
// duplicated id
var count = 0;
return ol;
}
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
function removeDuplicateIds(mokuji) {
var lists = mokuji.getElementsByTagName('a');
try {
for (var _iterator = headings[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var heading = _step.value;
for (var i = 0; i < lists.length; i++) {
var id = lists[i].innerText;
var hash = lists[i].hash;
var headings = document.querySelectorAll('[id="' + id + '"]');
var id = heading.id + '-' + count;
if (headings.length === 1) {
continue;
}
// search duplicate list
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
// duplicated id
var count = 0;
try {
for (var _iterator2 = lists[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var list = _step2.value;
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
if (list.hash === hash) {
// update hash
list.href = '#' + id;
break;
}
}
try {
for (var _iterator = headings[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var heading = _step.value;
// update id
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
var id = heading.id + '-' + count;
// search duplicate list
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = lists[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var list = _step2.value;
if (list.hash === hash) {
// update hash
list.href = '#' + id;
break;
}
heading.id = id;
count++;
}
// update id
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
if (_didIteratorError) {
throw _iteratorError;
}
}
}
heading.id = id;
count++;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
}
}]);
return init;
}();
{
"name": "mokuji.js",
"version": "1.0.0",
"version": "1.1.0",
"description": "Library Description",

@@ -11,3 +11,4 @@ "main": "lib/index.js",

"clean": "rimraf lib dist coverage",
"lint": "eslint src"
"lint": "eslint src",
"test": "npm run lint"
},

@@ -33,3 +34,3 @@ "repository": {

"cross-env": "^5.0.1",
"eslint": "^3.19.0",
"eslint": "^4.0.0",
"rimraf": "^2.5.2",

@@ -36,0 +37,0 @@ "webpack": "^2.6.1"

mokuji.js
===
[![npm version](https://badge.fury.io/js/mokuji.js.svg)](https://www.npmjs.com/package/mokuji.js)
generate "table of contents".
## Usage
```html
<script src="../dist/mokuji.js"></script>
<script>
var mokuji = new Mokuji.init(document.getElementById('target'));
var list = document.getElementById('list');
list.appendChild(mokuji);
</script>
```
### options
```
{
anchorType: 'wikipedia'
}
```
## Installation
```bash
npm install --save mokuji.js
```

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc