@zipify/wysiwyg 1.2.6 → 1.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +2 -2
- package/dist/wysiwyg.mjs +1 -1
- package/lib/cli/commands/Command.js +27 -0
- package/lib/cli/commands/ToJsonCommand.js +39 -0
- package/lib/cli/commands/index.js +1 -0
- package/lib/cli/index.js +1 -0
- package/lib/entry-cli.js +6 -21
- package/lib/extensions/FontFamily.js +1 -1
- package/package.json +1 -1
package/dist/wysiwyg.mjs
CHANGED
|
@@ -23002,7 +23002,7 @@ const FontFamily = Mark.create({
|
|
|
23002
23002
|
},
|
|
23003
23003
|
parseHTML() {
|
|
23004
23004
|
const getAttrs = (input) => {
|
|
23005
|
-
const parsed = input.replace(/"/g, "");
|
|
23005
|
+
const parsed = input.replace(/["']/g, "");
|
|
23006
23006
|
const isExists = this.options.fonts.some((font) => font.name === parsed);
|
|
23007
23007
|
const value = isExists ? parsed : unref(this.options.defaultPreset).common.font_family;
|
|
23008
23008
|
return { value };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export class Command {
|
|
2
|
+
name;
|
|
3
|
+
argument;
|
|
4
|
+
options = [];
|
|
5
|
+
doCommand() {}
|
|
6
|
+
|
|
7
|
+
install(program) {
|
|
8
|
+
let building = program.command(this.name);
|
|
9
|
+
|
|
10
|
+
if (this.argument) {
|
|
11
|
+
building = building.argument(this.argument);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (this.options.length) {
|
|
15
|
+
for (const option of this.options) {
|
|
16
|
+
building = building.option(option.flags, option.description, option.default);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
building.action(this.doCommand.bind(this));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
output(data) {
|
|
24
|
+
// eslint-disable-next-line no-console
|
|
25
|
+
console.log(data);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import { ContentSerializer } from '../ContentSerializer';
|
|
3
|
+
import { Command } from './Command';
|
|
4
|
+
|
|
5
|
+
export class ToJsonCommand extends Command {
|
|
6
|
+
name = 'to-json';
|
|
7
|
+
argument = '<html>';
|
|
8
|
+
|
|
9
|
+
options = [
|
|
10
|
+
{
|
|
11
|
+
flags: '--config <path>',
|
|
12
|
+
description: 'Generator config',
|
|
13
|
+
// Relative to dist folder
|
|
14
|
+
default: resolve(__dirname, '../bin/zp.config.json')
|
|
15
|
+
}
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
doCommand(html, { config }) {
|
|
19
|
+
const configPath = resolve(process.cwd(), config);
|
|
20
|
+
const serializer = ContentSerializer.build(require(configPath).editor);
|
|
21
|
+
const json = serializer.toJSON(this.#formatInputHtml(html));
|
|
22
|
+
|
|
23
|
+
this.output(this.#formatOutputJson(json));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
#formatInputHtml(html) {
|
|
27
|
+
return html.replace(/\\(["'])/g, '$1');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
#formatOutputJson(object) {
|
|
31
|
+
const skipNullValue = (_, value) => value === null ? undefined : value;
|
|
32
|
+
const json = JSON.stringify(object, skipNullValue, 2);
|
|
33
|
+
|
|
34
|
+
return json
|
|
35
|
+
.replace(/\\'/g, '\'')
|
|
36
|
+
.replace(/^[\t ]*"[^:\n\r]+(?<!\\)":/gm, (match) => match.replace(/"/g, ''))
|
|
37
|
+
.replace(/: "(.+)"([,\n])/g, ': \'$1\'$2');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ToJsonCommand } from './ToJsonCommand';
|
package/lib/cli/index.js
CHANGED
package/lib/entry-cli.js
CHANGED
|
@@ -1,29 +1,14 @@
|
|
|
1
|
-
import { resolve } from 'path';
|
|
2
1
|
import { Command } from 'commander';
|
|
3
|
-
import {
|
|
2
|
+
import { ToJsonCommand } from './cli';
|
|
4
3
|
|
|
5
4
|
const program = new Command();
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
const commands = [
|
|
7
|
+
ToJsonCommand
|
|
8
|
+
];
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
.replace(/^[\t ]*"[^:\n\r]+(?<!\\)":/gm, (match) => match.replace(/"/g, ''))
|
|
14
|
-
.replace(/: "(.+)"([,\n])/g, ': \'$1\'$2');
|
|
10
|
+
for (const CommandClass of commands) {
|
|
11
|
+
new CommandClass().install(program);
|
|
15
12
|
}
|
|
16
13
|
|
|
17
|
-
program.command('to-json')
|
|
18
|
-
.argument('<html>')
|
|
19
|
-
.option('--config <path>', 'generator config', resolve(__dirname, '../bin/zp.config.json'))
|
|
20
|
-
.action((html, { config }) => {
|
|
21
|
-
const configPath = resolve(process.cwd(), config);
|
|
22
|
-
const serializer = ContentSerializer.build(require(configPath).editor);
|
|
23
|
-
const json = rubifyJSON(serializer.toJSON(html.replace(/\\"/g, '"')));
|
|
24
|
-
|
|
25
|
-
// eslint-disable-next-line no-console
|
|
26
|
-
console.log(json);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
14
|
program.parse();
|
|
@@ -62,7 +62,7 @@ export const FontFamily = Mark.create({
|
|
|
62
62
|
|
|
63
63
|
parseHTML() {
|
|
64
64
|
const getAttrs = (input) => {
|
|
65
|
-
const parsed = input.replace(/"/g, '');
|
|
65
|
+
const parsed = input.replace(/["']/g, '');
|
|
66
66
|
const isExists = this.options.fonts.some((font) => font.name === parsed);
|
|
67
67
|
const value = isExists ? parsed : unref(this.options.defaultPreset).common.font_family;
|
|
68
68
|
|