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

discord-markdown

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

discord-markdown - npm Package Compare versions

Comparing version 2.1.2 to 2.2.0

62

index.js

@@ -20,9 +20,9 @@ const markdown = require('simple-markdown');

if (Object.prototype.hasOwnProperty.call(attributes, attr) && attributes[attr])
attributeString += ' ' + attr + '="' + attributes[attr] + '"';
attributeString += ` ${markdown.sanitizeText(attr)}="${markdown.sanitizeText(attributes[attr])}"`;
}
let unclosedTag = '<' + tagName + attributeString + '>';
let unclosedTag = `<${tagName}${attributeString}>`;
if (isClosed)
return unclosedTag + content + '</' + tagName + '>';
return unclosedTag + content + `</${tagName}>`;
return unclosedTag;

@@ -33,3 +33,36 @@ }

const rules = {
blockQuote: Object.assign({}, markdown.defaultRules.blockQuote, {
match: function(source, state, prevSource) {
return !/^$|\n *$/.test(prevSource) || state.inQuote ? null : /^( *>>> ([\s\S]*))|^( *> [^\n]+(\n *> [^\n]+)*\n?)/.exec(source);
},
parse: function(capture, parse, state) {
const all = capture[0];
const isBlock = Boolean(/^ *>>> ?/.exec(all));
const removeSyntaxRegex = isBlock ? /^ *>>> ?/ : /^ *> ?/gm;
const content = all.replace(removeSyntaxRegex, '');
state.inQuote = true
if (!isBlock)
state.inline = true;
const parsed = parse(content, state);
state.inQuote = state.inQuote || false;
state.inline = state.inline || false;
return {
content: parsed,
type: 'blockQuote'
}
}
}),
codeBlock: Object.assign({ }, markdown.defaultRules.codeBlock, {
match: markdown.inlineRegex(/^```(([a-z0-9-]+?)\n+)?\n*([^]+?)\n*```/i),
parse: function(capture, parse, state) {
return {
lang: (capture[2] || '').trim(),
content: capture[3] || '',
inQuote: state.inQuote || false
};
},
html: (node, output, state) => {

@@ -49,5 +82,2 @@ let code;

}),
fence: Object.assign({ }, markdown.defaultRules.fence, {
match: markdown.inlineRegex(/^ *(`{3,}) *(\S+)? *\n([\s\S]+?)\s*\1 *(?:\n *)*/)
}),
newline: markdown.defaultRules.newline,

@@ -86,4 +116,4 @@ escape: markdown.defaultRules.escape,

u: markdown.defaultRules.u,
del: Object.assign({ }, markdown.defaultRules.del, {
match: markdown.inlineRegex(/^~~(\s*?(?:\\[\s\S]|~(?!~)|[^\s\\~]|\s+(?!~~))+?\s*?)~~/),
strike: Object.assign({ }, markdown.defaultRules.del, {
match: markdown.inlineRegex(/^~~([\s\S]+?)~~(?!_)/),
}),

@@ -100,8 +130,9 @@ inlineCode: markdown.defaultRules.inlineCode,

}),
specialCaseArms: {
order: markdown.defaultRules.escape.order - 0.5,
match: source => /^¯\\_\(ツ\)_\/¯/.exec(source),
parse: function(capture, parse, state) {
emoticon: {
order: markdown.defaultRules.text.order,
match: source => /^(¯\\_\(ツ\)_\/¯)/.exec(source),
parse: function(capture) {
return {
content: parse(capture[0].replace(/^¯\\_\(ツ\)_\/¯/, '¯\\\\\\_(ツ)_/¯'), state)
type: 'text',
content: capture[1]
};

@@ -118,3 +149,3 @@ },

order: 0,
match: source => /^\|\|((?:.|\n)+?)\|\|/.exec(source),
match: source => /^\|\|([\s\S]+?)\|\|/.exec(source),
parse: function(capture, parse, state) {

@@ -181,3 +212,3 @@ return {

order: markdown.defaultRules.strong.order,
match: source => /^<(a?):(\w+):([0-9]*)>/.exec(source),
match: source => /^<(a?):(\w+):(\d+)>/.exec(source),
parse: function(capture) {

@@ -274,2 +305,3 @@ return {

inline: true,
inQuote: false,
escapeHTML: options.escapeHTML,

@@ -276,0 +308,0 @@ cssModuleNames: options.cssModuleNames || null

{
"name": "discord-markdown",
"version": "2.1.2",
"version": "2.2.0",
"description": "A markdown parser for Discord messages",

@@ -24,9 +24,9 @@ "keywords": [

"dependencies": {
"highlight.js": "^9.13.1",
"simple-markdown": "^0.4.2"
"highlight.js": "^9.15.9",
"simple-markdown": "^0.5.1"
},
"devDependencies": {
"eslint": "^5.10.0",
"jest": "^23.6.0"
"eslint": "^6.1.0",
"jest": "^24.8.0"
}
}

@@ -38,7 +38,2 @@ const markdown = require('../index');

test('blockquotes shouldn\'t do anything', () => {
expect(markdown.toHTML('> blah'))
.toBe('&gt; blah');
});
test('Codeblocks should work with ini', () => {

@@ -45,0 +40,0 @@ expect(markdown.toHTML('```ini\n[01] asdasd\n```'))

@@ -51,5 +51,5 @@ const markdown = require('../index');

test('Fence normal codeblocks', () => {
test('Fence normal code blocks', () => {
expect(markdown.toHTML('text\n```\ncode\nblock\n```\nmore text'))
.toBe('text<br><pre><code class="hljs">code\nblock</code></pre>more text');
.toBe('text<br><pre><code class="hljs">code\nblock</code></pre><br>more text');
});

@@ -62,2 +62,7 @@

test('Fenced code blocks on one line', () => {
expect(markdown.toHTML('`test`\n\n```test```'))
.toBe('<code>test</code><br><br><pre><code class="hljs">test</code></pre>');
});
test('Escaped marks', () => {

@@ -75,3 +80,13 @@ expect(markdown.toHTML('Code: \\`1 + 1` = 2`'))

// apparently discord special-cased this exact thing, so that in this character sequence the \ doesn't escape
test('Block quotes', () => {
expect(markdown.toHTML('> text > here'))
.toBe('<blockquote>text &gt; here</blockquote>');
expect(markdown.toHTML('>text'))
.toBe('&gt;text');
expect(markdown.toHTML('outside\n>>> inside\ntext\n> here\ndoes not end'))
.toBe('outside<br><blockquote>inside<br>text<br>&gt; here<br>does not end</blockquote>');
expect(markdown.toHTML('>>> test\n```js\ncode```'))
.toBe('<blockquote>test<br><pre><code class="hljs js">code</code></pre></blockquote>');
});
test('don\'t drop arms', () => {

@@ -78,0 +93,0 @@ expect(markdown.toHTML('¯\\_(ツ)_/¯'))

Sorry, the diff of this file is not supported yet

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