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

marked-terminal

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

marked-terminal - npm Package Compare versions

Comparing version 1.7.0 to 2.0.0

105

index.js

@@ -34,2 +34,3 @@ "use strict";

listitem: chalk.reset,
list: list,
table: chalk.reset,

@@ -49,3 +50,3 @@ paragraph: chalk.reset,

reflowText: false,
tab: 3,
tab: 4,
tableOptions: {}

@@ -82,7 +83,10 @@ };

Renderer.prototype.code = function(code, lang, escaped) {
return '\n' + indentify(highlight(code, lang, this.o, this.highlightOptions), this.tab) + '\n\n';
return section(indentify(
this.tab,
highlight(code, lang, this.o, this.highlightOptions)
));
};
Renderer.prototype.blockquote = function(quote) {
return '\n' + this.o.blockquote(indentify(quote.trim(), this.tab)) + '\n\n';
return section(this.o.blockquote(indentify(this.tab, quote.trim())));
};

@@ -103,22 +107,19 @@

}
if (level === 1) {
return this.o.firstHeading(text) + '\n';
}
return this.o.heading(text) + '\n';
return section(level === 1 ? this.o.firstHeading(text) : this.o.heading(text));
};
Renderer.prototype.hr = function() {
return this.o.hr(hr('-', this.o.reflowText && this.o.width)) + '\n';
return section(this.o.hr(hr('-', this.o.reflowText && this.o.width)));
};
Renderer.prototype.list = function(body, ordered) {
body = indentLines(this.o.listitem(body), this.tab);
if (!ordered) return body;
return changeToOrdered(body);
body = this.o.list(body, ordered, this.tab);
return section(fixNestedLists(indentLines(this.tab, body), this.tab));
};
Renderer.prototype.listitem = function(text) {
var isNested = ~text.indexOf('\n');
var transform = compose(this.o.listitem, this.transform);
var isNested = text.indexOf('\n') !== -1;
if (isNested) text = text.trim();
return '\n * ' + this.transform(text);
return '\n' + transform(text);
};

@@ -132,3 +133,3 @@

}
return text + '\n\n';
return section(text);
};

@@ -144,3 +145,3 @@

});
return this.o.table(table.toString()) + '\n\n';
return section(this.o.table(table.toString()));
};

@@ -242,14 +243,67 @@

function indentLines (text, tab) {
return text.replace(/\n/g, '\n' + tab) + '\n\n';
function indentLines (indent, text) {
return text.replace(/(^|\n)(.+)/g, '$1' + indent + '$2');
}
function changeToOrdered(text) {
var i = 1;
return text.split('\n').reduce(function (acc, line) {
if (!line) return '\n' + acc;
return acc + line.replace(/(\s*)\*/, '$1' + (i++) + '.') + '\n';
});
function indentify(indent, text) {
if (!text) return text;
return indent + text.split('\n').join('\n' + indent);
}
var BULLET_POINT_REGEX = '\\*';
var NUMBERED_POINT_REGEX = '\\d+\\.';
var POINT_REGEX = '(?:' + [BULLET_POINT_REGEX, NUMBERED_POINT_REGEX].join('|') + ')';
// Prevents nested lists from joining their parent list's last line
function fixNestedLists (body, indent) {
var regex = new RegExp('' +
'(\\S(?: | )?)' + // Last char of current point, plus one or two spaces
// to allow trailing spaces
'((?:' + indent + ')+)' + // Indentation of sub point
'(' + POINT_REGEX + '(?:.*)+)$', 'm'); // Body of subpoint
return body.replace(regex, '$1\n' + indent + '$2$3');
}
var isPointedLine = function (line, indent) {
return line.match('^(?:' + indent + ')*' + POINT_REGEX);
}
var BULLET_POINT = '* ';
function bulletPointLine (indent, line) {
return isPointedLine(line, indent) ? line : BULLET_POINT + line;
}
function bulletPointLines (lines, indent) {
var transform = bulletPointLine.bind(null, indent);
return lines.split('\n')
.filter(identity)
.map(transform)
.join('\n');
}
var numberedPoint = function (n) {
return n + '. ';
};
function numberedLine (indent, line, num) {
return isPointedLine(line, indent) ? line : (numberedPoint(num+1) + line);
}
function numberedLines (lines, indent) {
var transform = numberedLine.bind(null, indent);
return lines.split('\n')
.filter(identity)
.map(transform)
.join('\n');
}
function list(body, ordered, indent) {
body = body.trim();
body = ordered ? numberedLines(body, indent) : bulletPointLines(body, indent);
return body;
}
function section (text) {
return text + '\n\n';
}
function highlight(code, lang, opts, hightlightOpts) {

@@ -289,7 +343,2 @@ if (!chalk.enabled) return code;

function indentify(text, tab) {
if (!text) return text;
return tab + text.split('\n').join('\n' + tab);
}
function generateTableRow(text, escape) {

@@ -296,0 +345,0 @@ if (!text) return [];

{
"name": "marked-terminal",
"version": "1.7.0",
"version": "2.0.0",
"description": "A custom render for marked to output to the Terminal",

@@ -22,3 +22,3 @@ "main": "index.js",

"peerDependencies": {
"marked": "^0.3.3"
"marked": "^0.3.6"
},

@@ -25,0 +25,0 @@ "dependencies": {

@@ -93,2 +93,5 @@ marked-terminal

// Formats the bulletpoints and numbers for lists
list: function (body, ordered) {/* ... */},
// Reflow and print-out width

@@ -95,0 +98,0 @@ width: 80, // only applicable when reflow is true

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