Socket
Socket
Sign inDemoInstall

remark-custom-blocks

Package Overview
Dependencies
Maintainers
2
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remark-custom-blocks - npm Package Compare versions

Comparing version 2.6.0 to 2.6.1

162

dist/index.js
"use strict";
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
var spaceSeparated = require('space-separated-tokens');
const spaceSeparated = require('space-separated-tokens');
function escapeRegExp(str) {
return str.replace(new RegExp("[-[\\]{}()*+?.\\\\^$|/]", 'g'), '\\$&');
return str.replace(/[-[\]{}()*+?.\\^$|/]/g, '\\$&');
}
var C_NEWLINE = '\n';
var C_FENCE = '|';
const C_NEWLINE = '\n';
const C_FENCE = '|';
function compilerFactory(nodeType) {
var text;
var title;
let text;
let title;
return {
blockHeading: function blockHeading(node) {
blockHeading(node) {
title = this.all(node).join('');
return '';
},
blockBody: function blockBody(node) {
text = this.all(node).map(function (s) {
return s.replace(/\n/g, '\n| ');
}).join('\n|\n| ');
blockBody(node) {
text = this.all(node).map(s => s.replace(/\n/g, '\n| ')).join('\n|\n| ');
return text;
},
block: function block(node) {
block(node) {
text = '';
title = '';
this.all(node);
if (title) {
return "[[".concat(nodeType, " | ").concat(title, "]]\n| ").concat(text);
return `[[${nodeType} | ${title}]]\n| ${text}`;
} else {
return "[[".concat(nodeType, "]]\n| ").concat(text);
return `[[${nodeType}]]\n| ${text}`;
}

@@ -59,39 +33,29 @@ }

}
module.exports = function blockPlugin() {
var availableBlocks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var pattern = Object.keys(availableBlocks).map(escapeRegExp).join('|');
module.exports = function blockPlugin(availableBlocks = {}) {
const pattern = Object.keys(availableBlocks).map(escapeRegExp).join('|');
if (!pattern) {
throw new Error('remark-custom-blocks needs to be passed a configuration object as option');
}
var regex = new RegExp("\\[\\[(".concat(pattern, ")(?: *\\| *(.*))?\\]\\]\n"));
const regex = new RegExp(`\\[\\[(${pattern})(?: *\\| *(.*))?\\]\\]\n`);
function blockTokenizer(eat, value, silent) {
var now = eat.now();
var keep = regex.exec(value);
const now = eat.now();
const keep = regex.exec(value);
if (!keep) return;
if (keep.index !== 0) return;
const [eaten, blockType] = keep;
const potentialBlock = availableBlocks[blockType];
const blockTitle = keep[2] || potentialBlock.defaultTitle;
var _keep = _slicedToArray(keep, 2),
eaten = _keep[0],
blockType = _keep[1];
var potentialBlock = availableBlocks[blockType];
var blockTitle = keep[2] || potentialBlock.defaultTitle;
/* istanbul ignore if - never used (yet) */
if (silent) return true;
var linesToEat = [];
var content = [];
var idx = 0;
const linesToEat = [];
const content = [];
let idx = 0;
while ((idx = value.indexOf(C_NEWLINE)) !== -1) {
var next = value.indexOf(C_NEWLINE, idx + 1); // either slice until next NEWLINE or slice until end of string
var lineToEat = next !== -1 ? value.slice(idx + 1, next) : value.slice(idx + 1);
if (lineToEat[0] !== C_FENCE) break; // remove leading `FENCE ` or leading `FENCE`
var line = lineToEat.slice(lineToEat.startsWith("".concat(C_FENCE, " ")) ? 2 : 1);
const next = value.indexOf(C_NEWLINE, idx + 1);
// either slice until next NEWLINE or slice until end of string
const lineToEat = next !== -1 ? value.slice(idx + 1, next) : value.slice(idx + 1);
if (lineToEat[0] !== C_FENCE) break;
// remove leading `FENCE ` or leading `FENCE`
const line = lineToEat.slice(lineToEat.startsWith(`${C_FENCE} `) ? 2 : 1);
linesToEat.push(lineToEat);

@@ -101,11 +65,9 @@ content.push(line);

}
var contentString = content.join(C_NEWLINE);
var stringToEat = eaten + linesToEat.join(C_NEWLINE);
var titleAllowed = potentialBlock.title && ['optional', 'required'].includes(potentialBlock.title);
var titleRequired = potentialBlock.title && potentialBlock.title === 'required';
const contentString = content.join(C_NEWLINE);
const stringToEat = eaten + linesToEat.join(C_NEWLINE);
const titleAllowed = potentialBlock.title && ['optional', 'required'].includes(potentialBlock.title);
const titleRequired = potentialBlock.title && potentialBlock.title === 'required';
if (titleRequired && !blockTitle) return;
if (!titleAllowed && blockTitle) return;
var add = eat(stringToEat);
const add = eat(stringToEat);
if (potentialBlock.details) {

@@ -115,6 +77,5 @@ potentialBlock.containerElement = 'details';

}
var exit = this.enterBlock();
var contents = {
type: "".concat(blockType, "CustomBlockBody"),
const exit = this.enterBlock();
const contents = {
type: `${blockType}CustomBlockBody`,
data: {

@@ -129,8 +90,7 @@ hName: potentialBlock.contentsElement ? potentialBlock.contentsElement : 'div',

exit();
var blockChildren = [contents];
const blockChildren = [contents];
if (titleAllowed && blockTitle) {
var titleElement = potentialBlock.titleElement ? potentialBlock.titleElement : 'div';
var titleNode = {
type: "".concat(blockType, "CustomBlockHeading"),
const titleElement = potentialBlock.titleElement ? potentialBlock.titleElement : 'div';
const titleNode = {
type: `${blockType}CustomBlockHeading`,
data: {

@@ -146,6 +106,5 @@ hName: titleElement,

}
var classList = spaceSeparated.parse(potentialBlock.classes || '');
const classList = spaceSeparated.parse(potentialBlock.classes || '');
return add({
type: "".concat(blockType, "CustomBlock"),
type: `${blockType}CustomBlock`,
children: blockChildren,

@@ -155,3 +114,3 @@ data: {

hProperties: {
className: ['custom-block'].concat(_toConsumableArray(classList))
className: ['custom-block', ...classList]
}

@@ -161,26 +120,25 @@ }

}
const Parser = this.Parser;
var Parser = this.Parser; // Inject blockTokenizer
var blockTokenizers = Parser.prototype.blockTokenizers;
var blockMethods = Parser.prototype.blockMethods;
// Inject blockTokenizer
const blockTokenizers = Parser.prototype.blockTokenizers;
const blockMethods = Parser.prototype.blockMethods;
blockTokenizers.customBlocks = blockTokenizer;
blockMethods.splice(blockMethods.indexOf('fencedCode') + 1, 0, 'customBlocks');
var Compiler = this.Compiler;
const Compiler = this.Compiler;
if (Compiler) {
var visitors = Compiler.prototype.visitors;
const visitors = Compiler.prototype.visitors;
if (!visitors) return;
Object.keys(availableBlocks).forEach(function (key) {
var compiler = compilerFactory(key);
visitors["".concat(key, "CustomBlock")] = compiler.block;
visitors["".concat(key, "CustomBlockHeading")] = compiler.blockHeading;
visitors["".concat(key, "CustomBlockBody")] = compiler.blockBody;
Object.keys(availableBlocks).forEach(key => {
const compiler = compilerFactory(key);
visitors[`${key}CustomBlock`] = compiler.block;
visitors[`${key}CustomBlockHeading`] = compiler.blockHeading;
visitors[`${key}CustomBlockBody`] = compiler.blockBody;
});
} // Inject into interrupt rules
}
var interruptParagraph = Parser.prototype.interruptParagraph;
var interruptList = Parser.prototype.interruptList;
var interruptBlockquote = Parser.prototype.interruptBlockquote;
// Inject into interrupt rules
const interruptParagraph = Parser.prototype.interruptParagraph;
const interruptList = Parser.prototype.interruptList;
const interruptBlockquote = Parser.prototype.interruptBlockquote;
interruptParagraph.splice(interruptParagraph.indexOf('fencedCode') + 1, 0, ['customBlocks']);

@@ -187,0 +145,0 @@ interruptList.splice(interruptList.indexOf('fencedCode') + 1, 0, ['customBlocks']);

{
"name": "remark-custom-blocks",
"version": "2.6.0",
"version": "2.6.1",
"repository": {

@@ -16,3 +16,3 @@ "url": "https://github.com/zestedesavoir/zmarkdown/tree/master/packages/remark-custom-blocks",

"pretest": "eslint .",
"build": "del-cli dist && cross-env BABEL_ENV=production babel src --out-dir dist",
"build": "babel --root-mode upward --delete-dir-on-start --env-name production --out-dir dist src",
"test": "jest",

@@ -35,3 +35,3 @@ "coverage": "jest --coverage"

},
"gitHead": "e2c975ab153bdb0d205275ac7bf71f788ee1590d"
"gitHead": "b278abe5320c5ca01bdaed3c833f5f68ab389663"
}
const spaceSeparated = require('space-separated-tokens')
function escapeRegExp (str) {
return str.replace(new RegExp(`[-[\\]{}()*+?.\\\\^$|/]`, 'g'), '\\$&')
return str.replace(/[-[\]{}()*+?.\\^$|/]/g, '\\$&')
}

@@ -32,3 +32,3 @@

}
},
}
}

@@ -101,6 +101,6 @@ }

hProperties: {
className: 'custom-block-body',
},
className: 'custom-block-body'
}
},
children: this.tokenizeBlock(contentString, now),
children: this.tokenizeBlock(contentString, now)
}

@@ -111,3 +111,2 @@ exit()

if (titleAllowed && blockTitle) {
const titleElement = potentialBlock.titleElement ? potentialBlock.titleElement : 'div'

@@ -119,6 +118,6 @@ const titleNode = {

hProperties: {
className: 'custom-block-heading',
},
className: 'custom-block-heading'
}
},
children: this.tokenizeInline(blockTitle, now),
children: this.tokenizeInline(blockTitle, now)
}

@@ -137,5 +136,5 @@

hProperties: {
className: ['custom-block', ...classList],
},
},
className: ['custom-block', ...classList]
}
}
})

@@ -142,0 +141,0 @@ }

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