UNPKG

remarkable-plugin-heading-id

Version:
3 lines (2 loc) 1.05 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=0,n=function(){e++},r=function(){e=0},t=function(e){return"heading_open"===e.type},i=function(e){return"inline"===e.type},a=["h1","h2","h3","h4","h5","h6"];exports.remarkablePluginHeadingId=function(o){var u,d=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},l=o.renderer.rules.heading_open,c=null!==(u=d.targets)&&void 0!==u?u:a;r(),o.renderer.rules.heading_open=function(r,a){var o,u=r[a];if(!t(u))throw new Error("remarkablePluginHeadingId should take heading tag token, but got"+JSON.stringify(u));var h=l(r,a),g=r[a+1];if(!i(g))throw new Error("remarkablePluginHeadingId should take text token next to heading open token, but got"+JSON.stringify(g));var f=null!==(o=g.content)&&void 0!==o?o:"";return function(){var r="h".concat(u.hLevel);if(!c.includes(r))return h;if(d.createId){var t=h.replace(">",' id="'.concat(d.createId(u.hLevel,f,e),'">'));return n(),t}var i=h.replace(">",' id="'.concat(f,'">'));return n(),i}()}}; //# sourceMappingURL=main.min.js.map