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

markdown-it-auto-parnum

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

markdown-it-auto-parnum - npm Package Compare versions

Comparing version 1.1.1 to 2.0.0

CHANGELOG.md

12

dist/markdown-it-auto-parnum.js

@@ -1,2 +0,2 @@

/*! markdown-it-auto-parnum 1.1.1 @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.markdownItAutoParnum = 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-auto-parnum 2.0.0 @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.markdownItAutoParnum = 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){
'use strict'

@@ -118,3 +118,3 @@

// which should receive paragraph numbers.
let numberedElements = (options.numberedElements || 'paragraph')
let numberedElements = (options.numberedElements || 'p')
.replace(/(.+?)(,|$)+/g, '$1,$1_open$2').split(',').filter(v => v)

@@ -162,3 +162,5 @@

// We should check all tokens of types that can be numbered, as well as all headers
if ((numberedElements + ',heading_open').indexOf(state.tokens[i].type) > -1) {
if (state.tokens[i].type === 'heading_open' ||
(numberedElements.indexOf(state.tokens[i].tag) > -1 && /_open$/.test(state.tokens[i].type)) ||
numberedElements.indexOf(state.tokens[i].type) > -1) {
tag = /^h\d$/.test(state.tokens[i].tag) ? state.tokens[i].tag : 'p'

@@ -243,3 +245,5 @@ if ((setNum = state.tokens[i].attrGet(sign)) && /\d/.test(setNum)) {

/* eslint no-fallthrough: 0 */
if (nesting === 0 && numberedElements.indexOf(token.type) > -1) {
if (nesting === 0 && (
(numberedElements.indexOf(token.tag) > -1 && /_open$/.test(state.tokens[i].type)) ||
numberedElements.indexOf(token.type) > -1)) {
// Don't number if the numbering is off

@@ -246,0 +250,0 @@ if (!numbersOn) continue

@@ -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).markdownItAutoParnum=e()}}(function(){return function(){return function e(t,n,i){function s(r,a){if(!n[r]){if(!t[r]){var o="function"==typeof require&&require;if(!a&&o)return o(r,!0);if(l)return l(r,!0);var h=new Error("Cannot find module '"+r+"'");throw h.code="MODULE_NOT_FOUND",h}var d=n[r]={exports:{}};t[r][0].call(d.exports,function(e){return s(t[r][1][e]||e)},d,d.exports,e,t,n,i)}return n[r].exports}for(var l="function"==typeof require&&require,r=0;r<i.length;r++)s(i[r]);return s}}()({1:[function(e,t,n){"use strict";class i{constructor(e,t){this.state=e,this.options=t,this._elements=["p"],this._value=[],this._headingLevels=t.headingLevels}insertAt(e,t=!1){let n=t?this.options.headingSign:this.options.sign,i=new this.state.Token("paragraph_number","a",0);i.content=this.value,i.attrPush([this.options.sign,this.value]),i.attrPush(["id",n+this.value]),this.options.addLinks&&i.attrPush(["href",`#${n}${this.value}`]),1===this.state.tokens[e].nesting?"inline"===this.state.tokens[e+1].type?this.state.tokens[e+1].children.unshift(i):(this.state.tokens.splice(e+1,0,i),this.state.tokens[e].block=!1):this.state.tokens.splice(e,0,i)}increment(e="p"){let t=this._elements.indexOf(e);if(t>-1)for(this._value[2*t]++;t>0;)t--,this._value[2*t]=0}addHeadingElement(e,t=!1){if("number"==typeof t)this._elements[t]=e;else for(let t=this._headingLevels;t>0;t--)if(!this._elements[t]){this._elements[t]=e;break}}set value(e){let t=[...this._value].reverse().join("").replace(/\d+/g,0).split(/(\d+)/).filter(e=>e.length);e.split(/(\d+)/).filter(e=>e.length).forEach((e,n)=>{t[n]=e}),this._value=t.reverse()}get value(){return[...this._value].reverse().join("").replace(/(?:^[0\D]+|(?:[\D]+0)+$)/,"")}set headingLevels(e){this._headingLevels=e,e++,this._elements=this._elements.filter(e=>e),this._elements.length<e&&this._elements.fill(!1,this._elements.length,e-this._elements.length),this._value="0".repeat(e).split("").join(this.options.delimiter).split(/(0)/).filter(e=>e.length)}get headingLevels(){return this._headingLevels}get elements(){return this._elements.filter(e=>e)}}t.exports=function(e,t={}){function n(e){let n=(t.numberedElements||"paragraph").replace(/(.+?)(,|$)+/g,"$1,$1_open$2").split(",").filter(e=>e),s=(t.skippedElements||"footnote_block").replace(/(.+?)(,|$)+/g,"$1_open,$1_close$2").split(",").filter(e=>e),l=t.sign=t.sign||"\xb6";t.headingSign=t.headingSign||"";let r=!1!==t.numberHeadings;t.headingLevels=void 0===t.headingLevels?1:t.headingLevels;let a=t.delimiter=t.delimiter||".";t.addLinks=void 0===t.addLinks||Boolean(t.addLinks);let o,h,d,u,p=new i(e,t),f={p:0,h1:0,h2:0,h3:0,h4:0,h5:0,h6:0},g={p:"",h1:"",h2:"",h3:"",h4:"",h5:"",h6:""},c=!0,m=0,_=!1;for(let t=0;t<e.tokens.length;t++)(n+",heading_open").indexOf(e.tokens[t].type)>-1&&(d=/^h\d$/.test(e.tokens[t].tag)?e.tokens[t].tag:"p",(o=e.tokens[t].attrGet(l))&&/\d/.test(o)&&(o=o.replace(/[0-9]+/g,"0"),g[d]||(g[d]=o,g.p.length<g[d].length&&(g.p=g[d]+a+"0"))),f[d]++);g.p&&(p.headingLevels=g.p.split(/[^0-9]+/).length-1),["h6","h5","h4","h3","h2","h1"].forEach(e=>{g[e]&&(h=g[e].split(/[^0-9]+/).length,p.addHeadingElement(e,h))}),g.p||(g.p="0".repeat(p.headingLevels+1).split("").join(a)),p.elements.length<=p.headingLevels&&["h1","h2","h3","h4","h5","h6"].some(e=>{if(f[e]>1&&(1===p.elements.length||-1===p.elements.indexOf(e)&&p.elements[p.elements.length-1]<e)&&p.addHeadingElement(e),p.elements.length>p.headingLevels)return!0}),p.headingLevels=p.elements.filter(e=>e).length-1;for(let t=0;t<e.tokens.length;++t)if(!("paragraph_number"===e.tokens[t].type||t>0&&"paragraph_number"===e.tokens[t-1].type)){switch(u=e.tokens[t],o=e.tokens[t].attrGet(l)){case null:break;case"manual":_=!0;case"stop":case"off":c=!1;case"none":case"skip":continue;case"auto":_=!1;case"on":case"start":c=!0;break;default:if(/\d/.test(o)){p.value=o,c=!0,p.insertAt(t,/^h\d$/.test(u.tag));continue}}if(0===m&&n.indexOf(u.type)>-1){if(!c)continue;if(_)continue;if(e.tokens[t+2].tag===e.tokens[t].tag&&"inline"===e.tokens[t+1].type&&1===e.tokens[t+1].children.length&&"text"===e.tokens[t+1].children[0].type&&""===e.tokens[t+1].children[0].content.trim())continue;if(u.hidden&&!["auto","on","start"].indexOf(o)>-1&&(0===t||!("list_item_open"===e.tokens[t-1].type&&["auto","on","start"].indexOf(e.tokens[t-1].attrGet(l))>-1)))continue;p.increment(),p.insertAt(t)}else 0===m&&c&&"heading_open"===u.type&&(p.increment(e.tokens[t].tag),r&&p.elements.indexOf(u.tag)>0&&p.insertAt(t,!0));s.indexOf(u.type)>-1&&(m+=u.nesting)}}e.renderer.rules.paragraph_number=function(e,t,n,i,s){return`<a${s.renderAttrs(e[t])}>${e[t].content}</a>`},e.core.ruler.__find__("autoParNum")>-1?e.core.ruler.at("autoParNum",n):e.core.ruler.push("autoParNum",n)}},{}]},{},[1])(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).markdownItAutoParnum=e()}}(function(){return function(){return function e(t,n,s){function i(r,o){if(!n[r]){if(!t[r]){var a="function"==typeof require&&require;if(!o&&a)return a(r,!0);if(l)return l(r,!0);var h=new Error("Cannot find module '"+r+"'");throw h.code="MODULE_NOT_FOUND",h}var d=n[r]={exports:{}};t[r][0].call(d.exports,function(e){return i(t[r][1][e]||e)},d,d.exports,e,t,n,s)}return n[r].exports}for(var l="function"==typeof require&&require,r=0;r<s.length;r++)i(s[r]);return i}}()({1:[function(e,t,n){"use strict";class s{constructor(e,t){this.state=e,this.options=t,this._elements=["p"],this._value=[],this._headingLevels=t.headingLevels}insertAt(e,t=!1){let n=t?this.options.headingSign:this.options.sign,s=new this.state.Token("paragraph_number","a",0);s.content=this.value,s.attrPush([this.options.sign,this.value]),s.attrPush(["id",n+this.value]),this.options.addLinks&&s.attrPush(["href",`#${n}${this.value}`]),1===this.state.tokens[e].nesting?"inline"===this.state.tokens[e+1].type?this.state.tokens[e+1].children.unshift(s):(this.state.tokens.splice(e+1,0,s),this.state.tokens[e].block=!1):this.state.tokens.splice(e,0,s)}increment(e="p"){let t=this._elements.indexOf(e);if(t>-1)for(this._value[2*t]++;t>0;)t--,this._value[2*t]=0}addHeadingElement(e,t=!1){if("number"==typeof t)this._elements[t]=e;else for(let t=this._headingLevels;t>0;t--)if(!this._elements[t]){this._elements[t]=e;break}}set value(e){let t=[...this._value].reverse().join("").replace(/\d+/g,0).split(/(\d+)/).filter(e=>e.length);e.split(/(\d+)/).filter(e=>e.length).forEach((e,n)=>{t[n]=e}),this._value=t.reverse()}get value(){return[...this._value].reverse().join("").replace(/(?:^[0\D]+|(?:[\D]+0)+$)/,"")}set headingLevels(e){this._headingLevels=e,e++,this._elements=this._elements.filter(e=>e),this._elements.length<e&&this._elements.fill(!1,this._elements.length,e-this._elements.length),this._value="0".repeat(e).split("").join(this.options.delimiter).split(/(0)/).filter(e=>e.length)}get headingLevels(){return this._headingLevels}get elements(){return this._elements.filter(e=>e)}}t.exports=function(e,t={}){function n(e){let n=(t.numberedElements||"p").replace(/(.+?)(,|$)+/g,"$1,$1_open$2").split(",").filter(e=>e),i=(t.skippedElements||"footnote_block").replace(/(.+?)(,|$)+/g,"$1_open,$1_close$2").split(",").filter(e=>e),l=t.sign=t.sign||"\xb6";t.headingSign=t.headingSign||"";let r=!1!==t.numberHeadings;t.headingLevels=void 0===t.headingLevels?1:t.headingLevels;let o=t.delimiter=t.delimiter||".";t.addLinks=void 0===t.addLinks||Boolean(t.addLinks);let a,h,d,u,p=new s(e,t),f={p:0,h1:0,h2:0,h3:0,h4:0,h5:0,h6:0},g={p:"",h1:"",h2:"",h3:"",h4:"",h5:"",h6:""},c=!0,m=0,_=!1;for(let t=0;t<e.tokens.length;t++)("heading_open"===e.tokens[t].type||n.indexOf(e.tokens[t].tag)>-1&&/_open$/.test(e.tokens[t].type)||n.indexOf(e.tokens[t].type)>-1)&&(d=/^h\d$/.test(e.tokens[t].tag)?e.tokens[t].tag:"p",(a=e.tokens[t].attrGet(l))&&/\d/.test(a)&&(a=a.replace(/[0-9]+/g,"0"),g[d]||(g[d]=a,g.p.length<g[d].length&&(g.p=g[d]+o+"0"))),f[d]++);g.p&&(p.headingLevels=g.p.split(/[^0-9]+/).length-1),["h6","h5","h4","h3","h2","h1"].forEach(e=>{g[e]&&(h=g[e].split(/[^0-9]+/).length,p.addHeadingElement(e,h))}),g.p||(g.p="0".repeat(p.headingLevels+1).split("").join(o)),p.elements.length<=p.headingLevels&&["h1","h2","h3","h4","h5","h6"].some(e=>{if(f[e]>1&&(1===p.elements.length||-1===p.elements.indexOf(e)&&p.elements[p.elements.length-1]<e)&&p.addHeadingElement(e),p.elements.length>p.headingLevels)return!0}),p.headingLevels=p.elements.filter(e=>e).length-1;for(let t=0;t<e.tokens.length;++t)if(!("paragraph_number"===e.tokens[t].type||t>0&&"paragraph_number"===e.tokens[t-1].type)){switch(u=e.tokens[t],a=e.tokens[t].attrGet(l)){case null:break;case"manual":_=!0;case"stop":case"off":c=!1;case"none":case"skip":continue;case"auto":_=!1;case"on":case"start":c=!0;break;default:if(/\d/.test(a)){p.value=a,c=!0,p.insertAt(t,/^h\d$/.test(u.tag));continue}}if(0===m&&(n.indexOf(u.tag)>-1&&/_open$/.test(e.tokens[t].type)||n.indexOf(u.type)>-1)){if(!c)continue;if(_)continue;if(e.tokens[t+2].tag===e.tokens[t].tag&&"inline"===e.tokens[t+1].type&&1===e.tokens[t+1].children.length&&"text"===e.tokens[t+1].children[0].type&&""===e.tokens[t+1].children[0].content.trim())continue;if(u.hidden&&!["auto","on","start"].indexOf(a)>-1&&(0===t||!("list_item_open"===e.tokens[t-1].type&&["auto","on","start"].indexOf(e.tokens[t-1].attrGet(l))>-1)))continue;p.increment(),p.insertAt(t)}else 0===m&&c&&"heading_open"===u.type&&(p.increment(e.tokens[t].tag),r&&p.elements.indexOf(u.tag)>0&&p.insertAt(t,!0));i.indexOf(u.type)>-1&&(m+=u.nesting)}}e.renderer.rules.paragraph_number=function(e,t,n,s,i){return`<a${i.renderAttrs(e[t])}>${e[t].content}</a>`},e.core.ruler.__find__("autoParNum")>-1?e.core.ruler.at("autoParNum",n):e.core.ruler.push("autoParNum",n)}},{}]},{},[1])(1)});

@@ -117,3 +117,3 @@ 'use strict'

// which should receive paragraph numbers.
let numberedElements = (options.numberedElements || 'paragraph')
let numberedElements = (options.numberedElements || 'p')
.replace(/(.+?)(,|$)+/g, '$1,$1_open$2').split(',').filter(v => v)

@@ -161,3 +161,5 @@

// We should check all tokens of types that can be numbered, as well as all headers
if ((numberedElements + ',heading_open').indexOf(state.tokens[i].type) > -1) {
if (state.tokens[i].type === 'heading_open' ||
(numberedElements.indexOf(state.tokens[i].tag) > -1 && /_open$/.test(state.tokens[i].type)) ||
numberedElements.indexOf(state.tokens[i].type) > -1) {
tag = /^h\d$/.test(state.tokens[i].tag) ? state.tokens[i].tag : 'p'

@@ -242,3 +244,5 @@ if ((setNum = state.tokens[i].attrGet(sign)) && /\d/.test(setNum)) {

/* eslint no-fallthrough: 0 */
if (nesting === 0 && numberedElements.indexOf(token.type) > -1) {
if (nesting === 0 && (
(numberedElements.indexOf(token.tag) > -1 && /_open$/.test(state.tokens[i].type)) ||
numberedElements.indexOf(token.type) > -1)) {
// Don't number if the numbering is off

@@ -245,0 +249,0 @@ if (!numbersOn) continue

@@ -65,2 +65,3 @@ # Manifesto

<!-- {¶=none} hides list paragraph number for Ocean-flavored markdown -->
- being specific

@@ -70,2 +71,3 @@ - being concise

- being meaningful
{¶=none}

@@ -92,2 +94,3 @@ The following sections detail each of the reference schemes mentioned above,

<!-- {¶=auto} numbers list for Commonmark extended -->
- All citations in most news stories, e.g. "A recent study..." {¶=auto}

@@ -94,0 +97,0 @@ - All citations in most social media posts

{
"name": "markdown-it-auto-parnum",
"version": "1.1.1",
"version": "2.0.0",
"description": "A markdown-it plugin for automatic paragraph numbering.",

@@ -30,2 +30,3 @@ "main": "index.js",

"nyc": "^14.1.1",
"ocean-markdown-it": "^2.0.0",
"terser": "^3.17.0"

@@ -32,0 +33,0 @@ },

@@ -29,4 +29,4 @@ ![build](https://travis-ci.org/dnotes/markdown-it-auto-parnum.svg?branch=master)

- headingSign (''): A symbol or text that should be placed in the html id attribute given to numbered headings. For example, if this is set to "sec", the headers will be rendered with `id="sec1"`.
- numberedElements ('paragraph'): A comma-separated list of markdown-it token types which should receive paragraph numbers. Only **block-level elements** can receive paragraph numbers. To give each fenced code block a paragraph number, one could set this to `'paragraph,fence'`.
- skippedElements ('footnote_block'): A comma-separted list of markdown-it token types inside which any paragraphs should not be numbered. Only **block-level elements with nesting** can be skipped. To number blockquotes but not the paragraphs inside them, one could set the options `{ numberedElements: 'paragraph,blockquote', skippedElements: 'blockquote' }`.
- numberedElements ('p'): A comma-separated list of HTML elements or markdown-it token types which should receive paragraph numbers. Only **block-level elements** can receive paragraph numbers. To give each fenced code block a paragraph number, one could set this to `'p,fence'`, where `p` is the HTML tag and `fence` is the markdown-it token type.
- skippedElements ('footnote_block'): A comma-separted list of markdown-it token types **only** inside which any paragraphs should not be numbered. Only **block-level elements with nesting** can be skipped. To number blockquotes but not the paragraphs inside them, one could set the options `{ numberedElements: 'paragraph,blockquote', skippedElements: 'blockquote' }`.

@@ -33,0 +33,0 @@ ### Multi-level numbering

@@ -14,2 +14,3 @@ #!/usr/bin/env node

.use(require('..'))
const ocean = require('ocean-markdown-it').use(require('..'))
const manifesto = fs.readFileSync(path.resolve(__dirname, '../manifesto.md'), 'utf8').toString()

@@ -30,1 +31,5 @@

htmlize(cm.render(manifesto)))
fs.writeFileSync(
path.resolve(__dirname, '../test/fixtures/html/manifesto-ocean.html'),
htmlize(ocean.render(manifesto)))
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