Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
42ecef4
importing literals correctly
atherdon Jul 17, 2022
6dab911
uypdate
atherdon Jul 17, 2022
872ca67
updates in literals
atherdon Jul 17, 2022
46f6f06
updates
atherdon Jul 17, 2022
aebf337
123
atherdon Jul 17, 2022
058ee48
reorganization
atherdon Jul 17, 2022
235d14e
updates
atherdon Jul 17, 2022
368b442
update
atherdon Jul 17, 2022
09fc032
update
atherdon Jul 17, 2022
c4cf768
update
atherdon Jul 17, 2022
bbd1523
parser react
atherdon Jul 19, 2022
e54a681
update
atherdon Jul 19, 2022
4d17598
replacer
atherdon Jul 19, 2022
2a8cc3e
updating react replacer
atherdon Jul 20, 2022
52cd735
replacer
atherdon Jul 20, 2022
e58089c
updates
atherdon Jul 20, 2022
2f12ae4
upd
atherdon Jul 22, 2022
e826a0d
replacemd
atherdon Jul 22, 2022
029b061
update
atherdon Jul 22, 2022
da87622
u[date
atherdon Jul 22, 2022
d4a98c3
Merge branch 'main' into react-callbacks
atherdon Jul 23, 2022
6d7c172
uncomment pre-commit
vadim9999 Jul 24, 2022
faa06eb
move all functions and clean from parserMDReact folder
vadim9999 Jul 24, 2022
52b2031
running in dev mode & setting up vs code debugger & enable sourcemaps
vadim9999 Jul 25, 2022
7114999
pass PARSE env
vadim9999 Jul 25, 2022
7d02340
remove unnecessary scripts from package.json
vadim9999 Jul 27, 2022
82fe141
describe scripts and debugging
vadim9999 Jul 27, 2022
89854a5
Merge branch 'main' of github.com-vadim9999:LLazyEmail/markdown-to-em…
vadim9999 Jul 27, 2022
bb88618
fix lint errors
vadim9999 Jul 27, 2022
c48ab20
check husky
vadim9999 Jul 27, 2022
1b2cf16
fix launch script for debugging
vadim9999 Jul 27, 2022
0c8d274
fix problem with printMessage
vadim9999 Jul 27, 2022
42ac746
rename from Replace to Replacer.class.js and refactor it
vadim9999 Jul 28, 2022
54d7ca5
refactor map
vadim9999 Jul 28, 2022
b2def1c
refactor map and fix paths
vadim9999 Jul 28, 2022
943be28
add option to launch.json
vadim9999 Jul 28, 2022
689cbc7
split on commonReplaceReact and refactor
vadim9999 Jul 28, 2022
4a5078f
remove unnecessary previewText from Replacer.class.js
vadim9999 Jul 28, 2022
8d410e9
make it more readable and fix lint erros of callbacks.js
vadim9999 Jul 29, 2022
195f4a2
fix lint errors lists.js
vadim9999 Jul 29, 2022
b8912de
fix lint errors in simple.js
vadim9999 Jul 29, 2022
c387337
remove unused
vadim9999 Jul 29, 2022
1e348dc
fix
vadim9999 Jul 29, 2022
135dbd6
correct Readme
vadim9999 Jul 29, 2022
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
26 changes: 26 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch via NPM parseFull",
"request": "launch",
"runtimeArgs": [
"run-script",
"dev:parseFull"
],
"runtimeExecutable": "npm",
"skipFiles": [
"<node_internals>/**"
],
"type": "node"
},
{
"name": "Launch via NPM parseReactFull",
"request": "launch",
"runtimeArgs": [
"run-script",
"dev:parseReactFull"
],
"runtimeExecutable": "npm",
"skipFiles": [
"<node_internals>/**"
],
"type": "node"
},
{
"type": "node",
"request": "launch",
Expand Down
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,26 @@ Maintainer notes:
- **Replacer for React DOM right now is broken. I'm moving it out into https://github.com/LLazyEmail/react-plain-template-example**
- **React version isn't working now. Probably we'll skip few releases and make it work as it should be.**

# How to run this module

There are two modes development and production.
In development mode all changes that was made automatically rebuilds and creates a file html or js. Development mode has two variants:

`npm run dev:parseFull` - runs parsing from Markdown to html.

`npm run dev:parseReactFull` - runs parsing from Markdown to React DOM tree.

In production mode builds an optimized module. Production mode has two options:

`npm run prod:parseFull` and `prod:parseReactFull`.

# Debugging the module

In VS Code needs to open a tab "Run and Debug", then in select input choose `Launch via NPM parseFull` - for html and `Launch via NPM parseReactFull`, the process will start automatically (builds and create a file). Put a breakpoint in line you need then save a file.

# Markdown to email template generator

This simple and light tool generates email template from markdown. The command is `npm run parse`.
This simple and light tool generates email template from markdown. The command is `npm run dev:parseFull`.
The path to markdown file must be `./source/source.md`, and output directory is `generated/newEmail.html`.

We tried to create our own wheel, then we failed. Arthur get bored trying to fix it and make it work properly.
Expand Down
19 changes: 8 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,14 @@
"description": "Translate 'Markdown' Syntax into HTML For Email Newsletters",
"main": "index.js",
"scripts": {
"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",
"parsed": "cross-env PARSE=full node ./src/index",
"emptyT": "npm run build && cross-env PARSE=plainEmpty node ./dist/bundle",
"defaultT": "npm run build && cross-env PARSE=plainTemplate node ./dist/bundle",
"build": "cross-env NODE_ENV=production rollup -c",
"dev:parseFull": "cross-env PARSE=full rollup -c -w",
"dev:parseReactFull": "cross-env PARSE=reactFull rollup -c -w",
"prod:parseFull": "npm run build && cross-env PARSE=full node ./dist/bundle",
"prod:parseReactFull": "npm run build && cross-env PARSE=reactFull node ./dist/bundle",
"test:react": "npm run checkFolders && jest ./src/parserMDReact/tests",
"lint:fix": "eslint -c ./.eslintrc.js ./src --fix --ignore-pattern \"./package.json\" ",
"lint": "eslint -c ./.eslintrc.js ./src --quiet --ignore-pattern \"./package.json\" ",
"build:small": "npm run checkFolders && node ./src/index.js",
"checkFolders": "node ./checkFolders",
"test": "npm run checkFolders && jest ./src/tests",
"test:typography": "jest --all --testPathPattern=./src/tests/typography",
Expand All @@ -34,8 +29,9 @@
"@babel/eslint-parser": "7.18.9",
"@babel/preset-env": "7.18.9",
"@rollup/plugin-babel": "5.3.1",
"@rollup/plugin-commonjs": "22.0.0",
"@rollup/plugin-commonjs": "22.0.1",
"@rollup/plugin-node-resolve": "13.3.0",
"@rollup/plugin-run": "2.1.0",
"babel-preset-react-app": "^10.0.1",
"eslint": "8.20.0",
"eslint-config-airbnb-base": "15.0.0",
Expand All @@ -50,6 +46,7 @@
"prettier": "2.7.0",
"rollup": "2.75.6",
"rollup-plugin-node-polyfills": "0.2.1",
"source-map-support": "0.5.21",
"winston": "^3.8.0"
},
"dependencies": {
Expand Down
8 changes: 8 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ 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';
import run from '@rollup/plugin-run';

const dev = process.env.NODE_ENV !== 'production';

export default {
input: 'src/index.js',
output: {
file: 'dist/bundle.js',
format: 'cjs',
sourcemap: true,
},
plugins: [
resolve({
Expand All @@ -25,5 +29,9 @@ export default {
babelHelpers: 'bundled',
}),
nodePolyfills(),
dev &&
run({
execArgv: ['-r', 'source-map-support/register'],
}),
],
};
44 changes: 0 additions & 44 deletions src/callbacksReact/helpers.js

This file was deleted.

9 changes: 6 additions & 3 deletions src/callbacksReact/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Callbacks from './methods/all';
import * as simple from './methods/simple';
import * as callbacks from './methods/callbacks';
import * as lists from './methods/lists';
import _header from './methods/header';

import { newLine } from './helpers';
const Callbacks = { ...simple, ...lists, _header, ...callbacks };

export { Callbacks, newLine };
export { Callbacks };
43 changes: 0 additions & 43 deletions src/callbacksReact/methods/all.js

This file was deleted.

122 changes: 51 additions & 71 deletions src/callbacksReact/methods/callbacks.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
// HELPER FROM MAIN CALLBACKS
// TODO undisable because there is a lot of errors
/* eslint-disable */
import {
// replaceReactWrapper,
newLine } from '../helpers';
import { newLine } from '../../domain/helper-methods';

import { commonReplaceReact } from '../../domain/replace-wrapper3.0';

/// function is not working as planned

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

if (/^<\/?(ul|ol|li|h|p|bl)/i.test(trimmed)) {
Expand All @@ -22,57 +19,43 @@ export function _paragraph(text, line) {
const config = {
params,
name: 'paragraph',
debug: true,
// debug: true,
};

// try {
// const replaced = commonReplace(config);

// return replaced;
// } catch (error) {
// catchErrorTraceOutput(error);
// }

// const result = newLine + replaceReactWrapper('paragraph', config) + newLine;
// console.log(config);
const replaced = commonReplaceReact(config);
const result = newLine + replaced + newLine;

return result;
}
/// !end function is not working as planned

export function _image(text, alt, srcWithTooltip) {
// const src = srcWithTooltip.trim().replace(/\"image_tooltip\"/, '');

// const params = {
// src: src.trim(),
// altText: alt,
// };
function _image(text, alt, srcWithTooltip) {
const src = srcWithTooltip.trim().replace(/\"image_tooltip\"/, '');

// const config = {
// params,
// name: 'image',
// debug: true,
// };
const params = {
src: src.trim(),
altText: alt,
};

this.warnings.images++;
const config = {
params,
name: 'image',
debug: true,
};

// try {
// const replaced = commonReplace(config);
this.warnings.images += 1;

// return replaced;
// } catch (error) {
// catchErrorTraceOutput(error);
// }
const replaced = commonReplaceReact(config);

// const result = replaceReactWrapper('image', config);
return result;
return replaced;
}

export function _br(text, newLines) {
function _br(text, newLines) {
const arrNewLines = newLines.match(new RegExp(newLine, 'g'));

// @TODO well, it's not good. can be improved with lodash
// @TODO I REALLY HATE THIS LINE
// TODO well, it's not good. can be improved with lodash
// I REALLY HATE THIS LINE
const result = arrNewLines.reduce(
(acc, current, index) => (index > 0 ? `${acc}<br/>${current}` : current),
'',
Expand All @@ -81,38 +64,35 @@ export function _br(text, newLines) {
return result;
}

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

const regex2 = /[\[\]]/g;

const [content, href, src] = text
.match(regex)
.map((match) => match.replace(/[\[\]]/g, ''));

// const params = {
// src: src.trim(),
// href: href.trim(),
// content: content.trim(),
// };

// const config = {
// params,
// name: 'sponsor',
// debug: true,
// };

// try {
// const replaced = commonReplace(config);

// return replaced;
// } catch (error) {
// catchErrorTraceOutput(error);
// }

// @TODO nope, not good
this.errors.sponsorshipTop
? (this.errors.sponsorshipBottom = true)
: (this.errors.sponsorshipTop = true);

// return replaceReactWrapper('sponsor', config, 'body');
.map((match) => match.replace(regex2, ''));

const params = {
src: src.trim(),
href: href.trim(),
content: content.trim(),
};

const config = {
params,
name: 'sponsor',
debug: true,
};
const replaced = commonReplaceReact(config);
return replaced;

// TODO upgrade a way to handle errors in state object
// eslint-disable-next-line no-unused-expressions
// this.errors.sponsorshipTop
// ? (this.errors.sponsorshipBottom = true)
// : (this.errors.sponsorshipTop = true);
}

// export { _paragraph, _image, _sponsorship, _br, newLine };
export { _paragraph, _image, _sponsorship, _br };
Loading