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: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
src/parserMDReact/tests/_generated/
src/parserMDReact/tests/_generated/
src/constants/regexp/tests
6 changes: 4 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true,
"jest": true
Expand All @@ -27,6 +26,9 @@
"import/no-unresolved": 0,
"import/no-dynamic-require": 0,
"global-require": 0,
"no-param-reassign": 0
"no-param-reassign": 0,
"import/prefer-default-export": 0,
"import/no-extraneous-dependencies": 0,
"func-names": 0
}
}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ package/callbacks/dist/*
package/callbacks/node_modules/*


yarn.lock
yarn.lock

dist
11 changes: 11 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"presets": [
[
"@babel/preset-env",
{
"modules": false
}
]
],
"ignore": ["src/tests", "tests", "src/parserMDReact/tests"]
}
6 changes: 0 additions & 6 deletions checkFolders.js

This file was deleted.

40 changes: 22 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
"description": "Translate 'Markdown' Syntax into HTML For Email Newsletters",
"main": "index.js",
"scripts": {
"parse": "npm run checkFolders && cross-env PARSE=full node ./src/parser",
"parseNoAdv": "npm run checkFolders && cross-env PARSE=noAdv node ./src/parser",
"parse:full": "npm run checkFolders && cross-env PARSE=full node ./src/parser",
"parseReact": "npm run checkFolders && cross-env PARSE=reactContentOnly node ./src/parser",
"parseReact:full": "npm run checkFolders && cross-env PARSE=reactFull node ./src/parser",
"emptyT": "npm run checkFolders && cross-env PARSE=plainEmpty node ./src/parser",
"defaultT": "npm run checkFolders && cross-env PARSE=plainTemplate node ./src/parser",
"build": "rollup -c",
"parse": "npm run build && cross-env PARSE=full node ./dist/bundle",
"parseNoAdv": "npm run build && cross-env PARSE=noAdv node ./dist/bundle",
"parse:full": "npm run build && cross-env PARSE=full node ./dist/bundle",
"parseReact": "npm run build && cross-env PARSE=reactContentOnly node ./dist/bundle",
"parseReact:full": "npm run build && cross-env PARSE=reactFull node ./dist/bundle",
"emptyT": "npm run build && cross-env PARSE=plainEmpty node ./dist/bundle",
"defaultT": "npm run build && cross-env PARSE=plainTemplate node ./dist/bundle",
"test:react": "npm run checkFolders && jest ./src/parserMDReact/tests",
"lint:fix": "eslint ./src --fix --ignore-pattern \"./package.json\" ",
"lint": "eslint ./src --ignore-pattern \"./package.json\" ",
Expand All @@ -26,30 +27,33 @@
"author": "hirdbluebird, atherdon, vadim9999",
"license": "ISC",
"devDependencies": {
"@babel/cli": "7.17.10",
"@babel/core": "7.17.9",
"@babel/eslint-parser": "7.17.0",
"@babel/preset-env": "7.17.10",
"@rollup/plugin-babel": "5.3.1",
"@rollup/plugin-commonjs": "22.0.0",
"@rollup/plugin-node-resolve": "13.3.0",
"eslint": "8.13.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-json": "3.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-require-path-exists": "1.1.9",
"husky": "7.0.0",
"jest": "27.5.1",
"lint-staged": "12.4.1",
"prettier": "^2.6.2"
"prettier": "2.6.2",
"rollup": "2.72.0",
"rollup-plugin-node-polyfills": "0.2.1"
},
"dependencies": {
"atherdon-callbacks": "^1.10.0",
"atherdon-newsletter-html-replacer": "^0.4.0",
"atherdon-newsletter-js-layouts": "^1.5.1",
"atherdon-newsletter-react": "^1.0.11",
"atherdon-newsletter-react-replacer": "^0.4.0",
"atherdon-old-newsletter-js-outertemplate": "^2.4.0",
"cross-env": "^7.0.3",
"markup-generator": "^0.4.0",
"path-exists": "^5.0.0"
"chalk": "5.0.1",
"cross-env": "7.0.3",
"lodash": "4.17.21",
"path-exists": "5.0.0",
"write": "2.0.0"
},
"lint-staged": {
"src/**/*.{js,ts}": [
Expand Down
29 changes: 29 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// rollup.config.js
import resolve from '@rollup/plugin-node-resolve';
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import nodePolyfills from 'rollup-plugin-node-polyfills';

export default {
input: 'src/parser.js',
output: {
file: 'dist/bundle.js',
format: 'cjs',
},
plugins: [
resolve({
preferBuiltins: true,
// fixes problem when naviagtor undefined
exportConditions: ['node'],
}),
commonjs(),
babel({
// exclude: [
// 'node_modules/lodash/lodash.js',
// // "/src/data/__tests__"
// ],
babelHelpers: 'bundled',
}),
nodePolyfills(),
],
};
30 changes: 30 additions & 0 deletions src/callbacks/callbacksHtml/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// import {generateNewString} from '';

// import body from '../../templates/OuterTemplate/layouts/body';
// import misc from '../../templates/OuterTemplate/layouts/misc';
// import NewPlainJSLayouts from '../../templates/OuterTemplate';

// console.log(layouts);

// console.log(NewPlainJSLayouts);
// TODO needs to be checked and replace on correct
const newLine = '\n';

// eslint-disable-next-line no-unused-vars
function replaceWrapper(name, config, folder = 'typography') {
// TODO later we can get rid of it completely.
// right now it's only for back campatibility purposes
// const configCopy = Object.assign(config, {
// // TODO I am not sure is it correct structure
// layouts: { body, misc },
// folder,
// });
// console.log(configCopy);
// return generateNewString(name, configCopy);
}

export {
newLine,
replaceWrapper,
// replaceReactWrapper
};
43 changes: 43 additions & 0 deletions src/callbacks/callbacksHtml/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {
strong,
link,
blockquote,
mem,
header,
italic,
del,
q,
code,
hr,
empty,
} from './methods/simple';

import { ulList, olList } from './methods/lists';

import { image, paragraphWrapper, sponsorship, br } from './methods/callbacks';

import { separator } from './methods/custom';

export default {
strong,
link,
blockquote,
mem,
header,
italic,
del,
q,
code,
hr,
empty,

ulList,
olList,

image,
paragraphWrapper,
sponsorship,
br,

separator,
};
84 changes: 84 additions & 0 deletions src/callbacks/callbacksHtml/methods/callbacks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { replaceWrapper, newLine } from '../helpers';

/// function is not working as planned

function paragraphWrapper(text, line) {
const trimmed = line.trim();

// TODO move out this regex into constants file.
if (/^<\/?(ul|ol|li|h|p|bl)/i.test(trimmed)) {
return newLine + line + newLine;
}

const config = {
content: trimmed,
};

const replaced = replaceWrapper('paragraph', config);

return newLine + replaced + newLine;
}
/// !end function is not working as planned

function image(text, alt, srcWithTooltip) {
// eslint-disable-next-line no-useless-escape
const src = srcWithTooltip.trim().replace(/\"image_tooltip\"/, '');

const config = {
src: src.trim(),
altText: alt,
};

// i dont think it will work well
// eslint-disable-next-line no-plusplus
this.warnings.images++;

const replaced = replaceWrapper('image', config);

return replaced;
}

function br(text, newLines) {
// TODO move out this regex into constants file.

const regex = new RegExp(newLine, 'g');
const arrNewLines = newLines.match(regex);

// @TODO well, it's not good. can be improved with lodash
const result = arrNewLines.reduce(
(acc, current, index) => (index > 0 ? `${acc}<br/>${current}` : current),
'',
);

return result;
}

function sponsorship(text) {
// TODO move out this regex into constants file.
const regex = /\[(.*?)\]/g;

const [content, href, src] = text
.match(regex)
// eslint-disable-next-line no-useless-escape
.map((match) => match.replace(/[\[\]]/g, '')); // TODO move out this regex into constants file.

const config = {
src: src.trim(),
href: href.trim(),
content: content.trim(),

folder: 'body',
};

// @TODO nope, not good
// eslint-disable-next-line no-unused-expressions
this.errors.sponsorshipTop
? (this.errors.sponsorshipBottom = true)
: (this.errors.sponsorshipTop = true);

const replaced = replaceWrapper('sponsor', config);

return replaced;
}

export { paragraphWrapper, image, sponsorship, br };
24 changes: 24 additions & 0 deletions src/callbacks/callbacksHtml/methods/custom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { replaceWrapper, newLine } from '../helpers';

function mem(text, src, href, altText) {
const config = {
src: src.trim(),
altText: altText.trim(),
href: href.trim(),
};

const replaced = replaceWrapper('image', config);

return replaced;
}

function separator() {
const config = {};

const replaced = replaceWrapper('separator', config);

const result = newLine + replaced + newLine;
return result;
}

export { mem, separator };
Loading