UNPKG

markdown-it-checkbox

Version:

Plugin to create checkboxes for markdown-it markdown parser

2 lines 1.85 kB
/*! markdown-it-checkbox 1.0.0 https://github.com//mcecot/markdown-it-checkbox @license MIT */ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.markdownitCheckbox=e()}}(function(){return function e(n,t,r){function o(u,c){if(!t[u]){if(!n[u]){var f="function"==typeof require&&require;if(!c&&f)return f(u,!0);if(i)return i(u,!0);var l=new Error("Cannot find module '"+u+"'");throw l.code="MODULE_NOT_FOUND",l}var s=t[u]={exports:{}};n[u][0].call(s.exports,function(e){var t=n[u][1][e];return o(t?t:e)},s,s.exports,e,n,t,r)}return t[u].exports}for(var i="function"==typeof require&&require,u=0;u<r.length;u++)o(r[u]);return o}({1:[function(e,n){"use strict";function t(e){function n(e,n){var t,u,c,f,l,s,p,a,d;return p=e.content,l=[],f=p.match(i),d=f[1],c=f[2],t=null!=(s="X"===d||"x"===d)?s:{"true":!1},o.divWrap&&(a=new n("checkbox_open","div",1),a.attrs=[["class","checkbox"]],l.push(a)),u="checkbox"+r,r+=1,a=new n("checkbox_input","input",0),a.attrs=[["type","checkbox"],["id",u]],t===!0&&a.attrs.push(["checked","true"]),l.push(a),a=new n("label_open","label",1),a.attrs=[["for",u]],l.push(a),a=new n("text","",0),a.content=c,l.push(a),l.push(new n("label_close","label",-1)),o.div_wrap&&l.push(new n("checkbox_close","div",-1)),l}var t,r,o,i,n;return t=e.utils.arrayReplaceAt,r=0,o={divWrap:!1},i=/\[(X|\s|\_|\-)\]\s(.*)/i,function(e){var r,o,u,c,f,l;for(r=e.tokens,u=0,c=r.length;c>u;)if("inline"===r[u].type){for(l=r[u].children,o=l.length-1;o>=0;)f=l[o],"text"===f.type&&i.test(f.content)&&(r[u].children=l=t(l,o,n(f,e.Token))),o--;u++}else u++}}n.exports=function(e){e.core.ruler.push("checkbox",t(e))}},{}]},{},[1])(1)});