New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

turndown-plugin-gfm

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

turndown-plugin-gfm - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

72

dist/turndown-plugin-gfm.js
var turndownPluginGfm = (function (exports) {
'use strict';
var highlightRegExp = /highlight-(?:text|source)-([a-z0-9]+)/;
function highlightedCodeBlock (turndownService) {
turndownService.addRule('highlightedCodeBlock', {
filter: function (node) {
var firstChild = node.firstChild;
return (
node.nodeName === 'DIV' &&
highlightRegExp.test(node.className) &&
firstChild &&
firstChild.nodeName === 'PRE'
)
},
replacement: function (content, node, options) {
var className = node.className || '';
var language = (className.match(highlightRegExp) || [null, ''])[1];
return (
'\n\n' + options.fence + language + '\n' +
node.firstChild.textContent +
'\n' + options.fence + '\n\n'
)
}
});
}
function strikethrough (turndownService) {

@@ -13,2 +39,4 @@ turndownService.addRule('strikethrough', {

var indexOf = Array.prototype.indexOf;
var every = Array.prototype.every;
var rules = {};

@@ -29,6 +57,6 @@

if (node.parentNode.nodeName === 'THEAD') {
if (isHeadingRow(node)) {
for (var i = 0; i < node.childNodes.length; i++) {
var border = '---';
var align = node.childNodes[i].attributes.align;
var border = '---';

@@ -60,4 +88,34 @@ if (align) border = alignMap[align.value] || border;

// A tr is a heading row if:
// - the parent is a THEAD
// - or if its the first child of the TABLE or the first TBODY (possibly
// following a blank THEAD)
// - and every cell is a TH
function isHeadingRow (tr) {
var parentNode = tr.parentNode;
return (
parentNode.nodeName === 'THEAD' ||
(
parentNode.firstChild === tr &&
(parentNode.nodeName === 'TABLE' || isFirstTbody(parentNode)) &&
every.call(tr.childNodes, function (n) { return n.nodeName === 'TH' })
)
)
}
function isFirstTbody (element) {
var previousSibling = element.previousSibling;
return (
element.nodeName === 'TBODY' && (
!previousSibling ||
(
previousSibling.nodeName === 'THEAD' &&
/^\s*$/i.test(previousSibling.textContent)
)
)
)
}
function cell (content, node) {
var index = Array.prototype.indexOf.call(node.parentNode.childNodes, node);
var index = indexOf.call(node.parentNode.childNodes, node);
var prefix = ' ';

@@ -84,6 +142,12 @@ if (index === 0) prefix = '| ';

function gfm (turndownService) {
turndownService.use([strikethrough, tables, taskListItems]);
turndownService.use([
highlightedCodeBlock,
strikethrough,
tables,
taskListItems
]);
}
exports.gfm = gfm;
exports.highlightedCodeBlock = highlightedCodeBlock;
exports.strikethrough = strikethrough;

@@ -90,0 +154,0 @@ exports.tables = tables;

@@ -5,2 +5,28 @@ 'use strict';

var highlightRegExp = /highlight-(?:text|source)-([a-z0-9]+)/;
function highlightedCodeBlock (turndownService) {
turndownService.addRule('highlightedCodeBlock', {
filter: function (node) {
var firstChild = node.firstChild;
return (
node.nodeName === 'DIV' &&
highlightRegExp.test(node.className) &&
firstChild &&
firstChild.nodeName === 'PRE'
)
},
replacement: function (content, node, options) {
var className = node.className || '';
var language = (className.match(highlightRegExp) || [null, ''])[1];
return (
'\n\n' + options.fence + language + '\n' +
node.firstChild.textContent +
'\n' + options.fence + '\n\n'
)
}
});
}
function strikethrough (turndownService) {

@@ -15,2 +41,4 @@ turndownService.addRule('strikethrough', {

var indexOf = Array.prototype.indexOf;
var every = Array.prototype.every;
var rules = {};

@@ -31,6 +59,6 @@

if (node.parentNode.nodeName === 'THEAD') {
if (isHeadingRow(node)) {
for (var i = 0; i < node.childNodes.length; i++) {
var border = '---';
var align = node.childNodes[i].attributes.align;
var border = '---';

@@ -62,4 +90,34 @@ if (align) border = alignMap[align.value] || border;

// A tr is a heading row if:
// - the parent is a THEAD
// - or if its the first child of the TABLE or the first TBODY (possibly
// following a blank THEAD)
// - and every cell is a TH
function isHeadingRow (tr) {
var parentNode = tr.parentNode;
return (
parentNode.nodeName === 'THEAD' ||
(
parentNode.firstChild === tr &&
(parentNode.nodeName === 'TABLE' || isFirstTbody(parentNode)) &&
every.call(tr.childNodes, function (n) { return n.nodeName === 'TH' })
)
)
}
function isFirstTbody (element) {
var previousSibling = element.previousSibling;
return (
element.nodeName === 'TBODY' && (
!previousSibling ||
(
previousSibling.nodeName === 'THEAD' &&
/^\s*$/i.test(previousSibling.textContent)
)
)
)
}
function cell (content, node) {
var index = Array.prototype.indexOf.call(node.parentNode.childNodes, node);
var index = indexOf.call(node.parentNode.childNodes, node);
var prefix = ' ';

@@ -86,8 +144,14 @@ if (index === 0) prefix = '| ';

function gfm (turndownService) {
turndownService.use([strikethrough, tables, taskListItems]);
turndownService.use([
highlightedCodeBlock,
strikethrough,
tables,
taskListItems
]);
}
exports.gfm = gfm;
exports.highlightedCodeBlock = highlightedCodeBlock;
exports.strikethrough = strikethrough;
exports.tables = tables;
exports.taskListItems = taskListItems;

@@ -0,1 +1,27 @@

var highlightRegExp = /highlight-(?:text|source)-([a-z0-9]+)/;
function highlightedCodeBlock (turndownService) {
turndownService.addRule('highlightedCodeBlock', {
filter: function (node) {
var firstChild = node.firstChild;
return (
node.nodeName === 'DIV' &&
highlightRegExp.test(node.className) &&
firstChild &&
firstChild.nodeName === 'PRE'
)
},
replacement: function (content, node, options) {
var className = node.className || '';
var language = (className.match(highlightRegExp) || [null, ''])[1];
return (
'\n\n' + options.fence + language + '\n' +
node.firstChild.textContent +
'\n' + options.fence + '\n\n'
)
}
});
}
function strikethrough (turndownService) {

@@ -10,2 +36,4 @@ turndownService.addRule('strikethrough', {

var indexOf = Array.prototype.indexOf;
var every = Array.prototype.every;
var rules = {};

@@ -26,6 +54,6 @@

if (node.parentNode.nodeName === 'THEAD') {
if (isHeadingRow(node)) {
for (var i = 0; i < node.childNodes.length; i++) {
var border = '---';
var align = node.childNodes[i].attributes.align;
var border = '---';

@@ -57,4 +85,34 @@ if (align) border = alignMap[align.value] || border;

// A tr is a heading row if:
// - the parent is a THEAD
// - or if its the first child of the TABLE or the first TBODY (possibly
// following a blank THEAD)
// - and every cell is a TH
function isHeadingRow (tr) {
var parentNode = tr.parentNode;
return (
parentNode.nodeName === 'THEAD' ||
(
parentNode.firstChild === tr &&
(parentNode.nodeName === 'TABLE' || isFirstTbody(parentNode)) &&
every.call(tr.childNodes, function (n) { return n.nodeName === 'TH' })
)
)
}
function isFirstTbody (element) {
var previousSibling = element.previousSibling;
return (
element.nodeName === 'TBODY' && (
!previousSibling ||
(
previousSibling.nodeName === 'THEAD' &&
/^\s*$/i.test(previousSibling.textContent)
)
)
)
}
function cell (content, node) {
var index = Array.prototype.indexOf.call(node.parentNode.childNodes, node);
var index = indexOf.call(node.parentNode.childNodes, node);
var prefix = ' ';

@@ -81,5 +139,10 @@ if (index === 0) prefix = '| ';

function gfm (turndownService) {
turndownService.use([strikethrough, tables, taskListItems]);
turndownService.use([
highlightedCodeBlock,
strikethrough,
tables,
taskListItems
]);
}
export { gfm, strikethrough, tables, taskListItems };
export { gfm, highlightedCodeBlock, strikethrough, tables, taskListItems };

@@ -5,2 +5,28 @@ 'use strict';

var highlightRegExp = /highlight-(?:text|source)-([a-z0-9]+)/;
function highlightedCodeBlock (turndownService) {
turndownService.addRule('highlightedCodeBlock', {
filter: function (node) {
var firstChild = node.firstChild;
return (
node.nodeName === 'DIV' &&
highlightRegExp.test(node.className) &&
firstChild &&
firstChild.nodeName === 'PRE'
)
},
replacement: function (content, node, options) {
var className = node.className || '';
var language = (className.match(highlightRegExp) || [null, ''])[1];
return (
'\n\n' + options.fence + language + '\n' +
node.firstChild.textContent +
'\n' + options.fence + '\n\n'
)
}
});
}
function strikethrough (turndownService) {

@@ -15,2 +41,4 @@ turndownService.addRule('strikethrough', {

var indexOf = Array.prototype.indexOf;
var every = Array.prototype.every;
var rules = {};

@@ -31,6 +59,6 @@

if (node.parentNode.nodeName === 'THEAD') {
if (isHeadingRow(node)) {
for (var i = 0; i < node.childNodes.length; i++) {
var border = '---';
var align = node.childNodes[i].attributes.align;
var border = '---';

@@ -62,4 +90,34 @@ if (align) border = alignMap[align.value] || border;

// A tr is a heading row if:
// - the parent is a THEAD
// - or if its the first child of the TABLE or the first TBODY (possibly
// following a blank THEAD)
// - and every cell is a TH
function isHeadingRow (tr) {
var parentNode = tr.parentNode;
return (
parentNode.nodeName === 'THEAD' ||
(
parentNode.firstChild === tr &&
(parentNode.nodeName === 'TABLE' || isFirstTbody(parentNode)) &&
every.call(tr.childNodes, function (n) { return n.nodeName === 'TH' })
)
)
}
function isFirstTbody (element) {
var previousSibling = element.previousSibling;
return (
element.nodeName === 'TBODY' && (
!previousSibling ||
(
previousSibling.nodeName === 'THEAD' &&
/^\s*$/i.test(previousSibling.textContent)
)
)
)
}
function cell (content, node) {
var index = Array.prototype.indexOf.call(node.parentNode.childNodes, node);
var index = indexOf.call(node.parentNode.childNodes, node);
var prefix = ' ';

@@ -86,8 +144,14 @@ if (index === 0) prefix = '| ';

function gfm (turndownService) {
turndownService.use([strikethrough, tables, taskListItems]);
turndownService.use([
highlightedCodeBlock,
strikethrough,
tables,
taskListItems
]);
}
exports.gfm = gfm;
exports.highlightedCodeBlock = highlightedCodeBlock;
exports.strikethrough = strikethrough;
exports.tables = tables;
exports.taskListItems = taskListItems;

@@ -0,1 +1,27 @@

var highlightRegExp = /highlight-(?:text|source)-([a-z0-9]+)/;
function highlightedCodeBlock (turndownService) {
turndownService.addRule('highlightedCodeBlock', {
filter: function (node) {
var firstChild = node.firstChild;
return (
node.nodeName === 'DIV' &&
highlightRegExp.test(node.className) &&
firstChild &&
firstChild.nodeName === 'PRE'
)
},
replacement: function (content, node, options) {
var className = node.className || '';
var language = (className.match(highlightRegExp) || [null, ''])[1];
return (
'\n\n' + options.fence + language + '\n' +
node.firstChild.textContent +
'\n' + options.fence + '\n\n'
)
}
});
}
function strikethrough (turndownService) {

@@ -10,2 +36,4 @@ turndownService.addRule('strikethrough', {

var indexOf = Array.prototype.indexOf;
var every = Array.prototype.every;
var rules = {};

@@ -26,6 +54,6 @@

if (node.parentNode.nodeName === 'THEAD') {
if (isHeadingRow(node)) {
for (var i = 0; i < node.childNodes.length; i++) {
var border = '---';
var align = node.childNodes[i].attributes.align;
var border = '---';

@@ -57,4 +85,34 @@ if (align) border = alignMap[align.value] || border;

// A tr is a heading row if:
// - the parent is a THEAD
// - or if its the first child of the TABLE or the first TBODY (possibly
// following a blank THEAD)
// - and every cell is a TH
function isHeadingRow (tr) {
var parentNode = tr.parentNode;
return (
parentNode.nodeName === 'THEAD' ||
(
parentNode.firstChild === tr &&
(parentNode.nodeName === 'TABLE' || isFirstTbody(parentNode)) &&
every.call(tr.childNodes, function (n) { return n.nodeName === 'TH' })
)
)
}
function isFirstTbody (element) {
var previousSibling = element.previousSibling;
return (
element.nodeName === 'TBODY' && (
!previousSibling ||
(
previousSibling.nodeName === 'THEAD' &&
/^\s*$/i.test(previousSibling.textContent)
)
)
)
}
function cell (content, node) {
var index = Array.prototype.indexOf.call(node.parentNode.childNodes, node);
var index = indexOf.call(node.parentNode.childNodes, node);
var prefix = ' ';

@@ -81,5 +139,10 @@ if (index === 0) prefix = '| ';

function gfm (turndownService) {
turndownService.use([strikethrough, tables, taskListItems]);
turndownService.use([
highlightedCodeBlock,
strikethrough,
tables,
taskListItems
]);
}
export { gfm, strikethrough, tables, taskListItems };
export { gfm, highlightedCodeBlock, strikethrough, tables, taskListItems };

6

package.json
{
"name": "turndown-plugin-gfm",
"description": "Turndown plugin to add GitHub Flavored Markdown extensions.",
"version": "0.0.1",
"version": "0.0.2",
"author": "Dom Christie",

@@ -10,3 +10,3 @@ "devDependencies": {

"standard": "^10.0.3",
"turndown": "0.0.8",
"turndown": "4.0.0-rc.2",
"turndown-attendant": "0.0.2"

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

"scripts": {
"build": "npm run build-cjs && npm run build-es && npm run build-iife",
"build": "npm run build-cjs && npm run build-es && npm run build-iife && npm run build-test",
"build-cjs": "rollup -c config/rollup.config.cjs.js && rollup -c config/rollup.config.browser.cjs.js",

@@ -35,0 +35,0 @@ "build-es": "rollup -c config/rollup.config.es.js && rollup -c config/rollup.config.browser.es.js",

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