Debian Codegraph @

vendor/wikimedia/parsoid/bin/normalize.test.js

raw
1 #!/usr/bin/env node
2
3 'use strict';
4
5 require('../core-upgrade.js');
6
7 var DOMNormalizer = require('../lib/html2wt/DOMNormalizer.js').DOMNormalizer;
8 var ContentUtils = require('../lib/utils/ContentUtils.js').ContentUtils;
9 var Promise = require('../lib/utils/promise.js');
10 var ScriptUtils = require('../tools/ScriptUtils.js').ScriptUtils;
11 var MockEnv = require('../tests/MockEnv.js').MockEnv;
12
13 var yargs = require('yargs');
14 var fs = require('pn/fs');
15
16 var opts = yargs
17 .usage("Usage: $0 [options] [html-file]\n\nProvide either inline html OR 1 file")
18 .options({
19 help: {
20 description: 'Show this message',
21 'boolean': true,
22 'default': false,
23 },
24 enableSelserMode: {
25 description: [
26 'Run in selser mode (but dom-diff markers are not loaded).',
27 'This just forces more normalization code to run.',
28 'So, this is "fake selser" mode till we are able to load diff markers from attributes'
29 ].join(' '),
30 'boolean': true,
31 'default': false,
32 },
33 html: {
34 description: 'html',
35 'boolean': false,
36 'default': '',
37 },
38 });
39
40 Promise.async(function *() {
41 var argv = opts.argv;
42 var html = argv.html;
43 if (!html && argv._[0]) {
44 html = yield fs.readFile(argv._[0], 'utf8');
45 }
46
47 if (ScriptUtils.booleanOption(argv.help) || !html) {
48 opts.showHelp();
49 return;
50 }
51
52 const env = new MockEnv({}, null);
53
54 var mockState = {
55 env,
56 selserMode: argv.enableSelserMode
57 };
58
59 const domBody = ContentUtils.ppToDOM(env, html, { markNew: true });
60 const normalizedBody = (new DOMNormalizer(mockState).normalize(domBody));
61
62 ContentUtils.dumpDOM(normalizedBody, 'Normalized DOM', { env: mockState.env, storeDiffMark: true });
63
64 process.exit(0);
65 })().done();