Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ dist
rollup.config.js
babel.config.js
dist/*
package-lock.json
yarn.lock
*.lock
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ renovate.json
examples
CONTRIBUTING.md
CHANGELOG.md
yarn.lock
*.lock
696 changes: 0 additions & 696 deletions package-lock.json

Large diffs are not rendered by default.

30 changes: 5 additions & 25 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,24 @@
import {
export {
REGEXP_HEADER,
REGEXP_H2,
REGEXP_H3,
REGEXP_IMAGE,
REGEXP_LINK,
REGEXP_STRONG,
REGEXP_DEL,
REGEXP_Q,
REGEXP_CODE,
// -----------
REGEXP_BLOCKQUOTE,
REGEXP_HR,
REGEXP_PARAGRAPH,
// -----------
REGEXP_BR,
REGEXP_EMPTY_BLOCKQUOTE,
REGEXP_EM,
} from "./tags";
import {
REGEXP_UL_LIST,
REGEXP_OL_LIST,
REGEXP_EMPTY_UL,
REGEXP_EMPTY_OL,
} from "./list";

} from "./tags/index";
export {
REGEXP_HEADER,
REGEXP_IMAGE,
REGEXP_LINK,
REGEXP_STRONG,
REGEXP_DEL,
REGEXP_Q,
REGEXP_CODE,
REGEXP_UL_LIST,
REGEXP_OL_LIST,
REGEXP_BLOCKQUOTE,
REGEXP_HR,
REGEXP_PARAGRAPH,
REGEXP_EMPTY_UL,
REGEXP_EMPTY_OL,
REGEXP_BR,
REGEXP_EMPTY_BLOCKQUOTE,
REGEXP_EM,
};
} from "./lists/index";

3 changes: 3 additions & 0 deletions src/lists/empty-ol.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const REGEXP_EMPTY_OL = /<\/ol>\s?<ol>/g;

export { REGEXP_EMPTY_OL };
3 changes: 3 additions & 0 deletions src/lists/empty-ul.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const REGEXP_EMPTY_UL = /<\/ul>\s?<ul>/g;

export { REGEXP_EMPTY_UL };
4 changes: 4 additions & 0 deletions src/lists/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { REGEXP_UL_LIST } from "./ul";
export { REGEXP_OL_LIST } from "./ol";
export { REGEXP_EMPTY_UL } from "./empty-ul";
export { REGEXP_EMPTY_OL } from "./empty-ol";
9 changes: 9 additions & 0 deletions src/lists/ol.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import os from "os";

const platform = os.platform();

const newLine = platform === "win32" ? "\r\n" : "\n";

const REGEXP_OL_LIST = new RegExp(`${newLine}[0-9]+\\.(.*)`, "g");

export { REGEXP_OL_LIST };
12 changes: 12 additions & 0 deletions src/lists/ul.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os from "os";

const platform = os.platform();

const newLine = platform === "win32" ? "\r\n" : "\n";

const REGEXP_UL_LIST = new RegExp(
`${newLine}(((\\s{4})?\\*(.*?)${newLine}){1,})`,
"g"
);

export { REGEXP_UL_LIST };
9 changes: 9 additions & 0 deletions src/tags/blockquote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import os from "os";

const platform = os.platform();

const newLine = platform === "win32" ? "\r\n" : "\n";

const REGEXP_BLOCKQUOTE = new RegExp(`${newLine}(&gt;|\\>)(.*)`, "g");

export { REGEXP_BLOCKQUOTE };
9 changes: 9 additions & 0 deletions src/tags/br.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import os from "os";

const platform = os.platform();

const newLine = platform === "win32" ? "\r\n" : "\n";

const REGEXP_BR = new RegExp(`((${newLine}){2,})`, "g");

export { REGEXP_BR };
3 changes: 3 additions & 0 deletions src/tags/code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const REGEXP_CODE = /`(.*?)`/g;

export { REGEXP_CODE };
3 changes: 3 additions & 0 deletions src/tags/del.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const REGEXP_DEL = /\~\~(.*?)\~\~/g;

export { REGEXP_DEL };
3 changes: 3 additions & 0 deletions src/tags/em.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const REGEXP_EM = /(\s|>)(\*|_)(.*?)\2(\s|<)/g;

export { REGEXP_EM };
3 changes: 3 additions & 0 deletions src/tags/empty-blockquote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const REGEXP_EMPTY_BLOCKQUOTE = /<\/blockquote><blockquote>/g;

export { REGEXP_EMPTY_BLOCKQUOTE };
12 changes: 12 additions & 0 deletions src/tags/header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os from "os";

const platform = os.platform();

const newLine = platform === "win32" ? "\r\n" : "\n";

const REGEXP_HEADER = new RegExp(`${newLine}(#+)(.*)`, "g");

const REGEXP_H2 = /^## (.*$)/gim;
const REGEXP_H3 = /^### (.*$)/gim;

export { REGEXP_HEADER, REGEXP_H2, REGEXP_H3 };
9 changes: 9 additions & 0 deletions src/tags/hr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import os from "os";

const platform = os.platform();

const newLine = platform === "win32" ? "\r\n" : "\n";

const REGEXP_HR = new RegExp(`${newLine}-{5,}`, "g");

export { REGEXP_HR };
3 changes: 3 additions & 0 deletions src/tags/image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const REGEXP_IMAGE = /!\[([^\[]+)\]\(([^\)]+)\)/g;

export { REGEXP_IMAGE };
13 changes: 13 additions & 0 deletions src/tags/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export { REGEXP_HEADER, REGEXP_H2, REGEXP_H3 } from "./header";
export { REGEXP_BLOCKQUOTE } from "./blockquote";
export { REGEXP_CODE } from "./code";
export { REGEXP_LINK } from "./link";
export { REGEXP_IMAGE } from "./image";
export { REGEXP_STRONG } from "./strong";
export { REGEXP_DEL } from "./del";
export { REGEXP_EM } from "./em";
export { REGEXP_HR } from "./hr";
export { REGEXP_BR } from "./br";
export { REGEXP_PARAGRAPH } from "./paragraph";
export { REGEXP_Q } from "./quote";
export { REGEXP_EMPTY_BLOCKQUOTE } from "./empty-blockquote";
3 changes: 3 additions & 0 deletions src/tags/link.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const REGEXP_LINK = /\[([^\[]+)\]\(([^\)]+)\)/g;

export { REGEXP_LINK };
9 changes: 9 additions & 0 deletions src/tags/paragraph.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import os from "os";

const platform = os.platform();

const newLine = platform === "win32" ? "\r\n" : "\n";

const REGEXP_PARAGRAPH = new RegExp(`${newLine}(.+?)${newLine}`, "g");

export { REGEXP_PARAGRAPH };
3 changes: 3 additions & 0 deletions src/tags/quote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const REGEXP_Q = /\:\"(.*?)\"\:/g;

export { REGEXP_Q };
3 changes: 3 additions & 0 deletions src/tags/strong.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const REGEXP_STRONG = /(\*\*|__)(.*?)(\*?)\1/g;

export { REGEXP_STRONG };
14 changes: 14 additions & 0 deletions tests/fixtures/edge-cases.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

const EDGE_CASES = {
empty: '',
whitespaceOnly: ' \n \t ',
nestedMarkdown: '**bold with _italic_ inside**',
multiplePatterns: '\n# Header\n\n> blockquote\n\n**bold** and _italic_\n',
specialChars: '!@#$%^&*()[]{}',
unicode: '# Title with émojis 🚀',
longText: 'a'.repeat(1000),
mixedNewlines: '\n\n\nTriple newline',
};

module.exports = { EDGE_CASES };
42 changes: 42 additions & 0 deletions tests/fixtures/header-samples.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict';

const HEADER_SAMPLES = {
valid: [
'\n# Header 1',
'\n## Header 2',
'\n### Header 3',
'\n#### Header 4',
'\n# Combatting Increased Cybersecurity Gaps During The Pandemic',
],
invalid: [
'No header here',
'Just plain text',
'',
],
};

const H2_SAMPLES = {
valid: [
'## Header 2',
'## Another Section',
],
invalid: [
'# Header 1',
'### Header 3',
'plain text',
],
};

const H3_SAMPLES = {
valid: [
'### Header 3',
'### Deep Section',
],
invalid: [
'## Header 2',
'# Header 1',
'plain text',
],
};

module.exports = { HEADER_SAMPLES, H2_SAMPLES, H3_SAMPLES };
52 changes: 52 additions & 0 deletions tests/fixtures/list-samples.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use strict';

const LIST_SAMPLES = {
ul: {
valid: [
'\n* Item 1\n* Item 2\n',
'\n* First item\n',
'\n * Nested item\n',
],
invalid: [
'Item 1\nItem 2',
'1. Ordered item',
'plain text',
],
},
ol: {
valid: [
'\n1. First item',
'\n2. Second item',
'\n10. Tenth item',
],
invalid: [
'* Unordered item',
'plain text',
'',
],
},
emptyUl: {
valid: [
'</ul><ul>',
'</ul> <ul>',
],
invalid: [
'</ol><ol>',
'plain text',
'* item',
],
},
emptyOl: {
valid: [
'</ol><ol>',
'</ol> <ol>',
],
invalid: [
'</ul><ul>',
'plain text',
'1. item',
],
},
};

module.exports = { LIST_SAMPLES };
44 changes: 44 additions & 0 deletions tests/fixtures/markdown-samples.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use strict';

const MARKDOWN_SAMPLES = {
header: '\n# Title\n\nSome paragraph text here.\n\n## Section\n\nMore text.\n',
image: '![alt text](https://example.com/image.png)',
link: 'Check out [this link](https://example.com) for more.',
strong: 'This is **bold text** in a sentence.',
del: 'This is ~~strikethrough~~ text.',
code: 'Use `inline code` like this.',
blockquote: '\n> This is a blockquote.\n',
hr: '\n-----\n',
paragraph: '\nThis is a paragraph.\n',
br: '\nFirst paragraph.\n\nSecond paragraph.\n',
em: ' _italic text_ here',
quote: ':"This is a quote":',
emptyBlockquote: '</blockquote><blockquote>',
ulList: '\n* Item one\n* Item two\n',
olList: '\n1. First item\n2. Second item\n',
};

const FULL_MARKDOWN = `
# Main Title

This is a paragraph with **bold**, _italic_, and \`code\`.

> This is a blockquote

## Section

Here is a [link](https://example.com) and an ![image](https://example.com/img.png).

* Unordered item 1
* Unordered item 2

1. Ordered item 1
2. Ordered item 2

-----

~~strikethrough~~ and :"quoted":

`;

module.exports = { MARKDOWN_SAMPLES, FULL_MARKDOWN };
10 changes: 10 additions & 0 deletions tests/helpers/file-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

const fs = require('fs');
const path = require('path');

function loadMarkdownFile(filePath) {
return fs.readFileSync(path.resolve(filePath), 'utf-8');
}

module.exports = { loadMarkdownFile };
2 changes: 1 addition & 1 deletion tests/image/image.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { REGEXP_IMAGE } = require('../../src/index');
describe('RegEx: REGEXP_IMAGE', () => {

test('should match the expected ...', () => {
let result = REGEXP_IMAGE.test("[alt_text](https://github.com/atherdon/newsletters/blob/master/archive/img/memes/october/4/4.jpg "image_tooltip")");
let result = REGEXP_IMAGE.test('![alt_text](https://github.com/atherdon/newsletters/blob/master/archive/img/memes/october/4/4.jpg)');
expect(result).toBe(true);
});

Expand Down
Loading
Loading