Skip to content

Commit

Permalink
Merge pull request #27 from voxmedia/mc-remove-internal-exports
Browse files Browse the repository at this point in the history
Remove private exports
  • Loading branch information
Michele Cynowicz authored Sep 23, 2020
2 parents 784dc81 + 81b97b1 commit 615da97
Show file tree
Hide file tree
Showing 51 changed files with 147 additions and 383 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.grunt
.vscode
build
lib-cov
coverage
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ convert(delta, formats, { blockTag: 'FIGURE', inlineTag: 'INS' });

## Changelog

- `6.0.0` Remove the `toInternalHtml` method. Also remove the private formats and internal-specific outputs that used to support `toInternalHtml`.
- `5.5.0` Add support for data params in doc component
- `5.4.1` Update dev dependencies to address security vulnerabilities
- `5.4.0` Update jsdom and lodash dependencies
Expand Down
5 changes: 0 additions & 5 deletions browser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var toHtml = require('./lib/export/to_html');
var toInlineHtml = require('./lib/export/to_inline_html');
var toInternalHtml = require('./lib/export/to_internal_html');
var toPublicHtml = require('./lib/export/to_public_html');
var toPlaintext = require('./lib/export/to_plaintext');

Expand All @@ -13,10 +12,6 @@ module.exports = {
options = Object.assign({}, options, { document: document });
return toInlineHtml(delta, formats, options);
},
toInternalHtml: function(delta, formats, options) {
options = Object.assign({}, options, { document: document });
return toInternalHtml(delta, formats, options);
},
toPublicHtml: function(delta, formats, options) {
options = Object.assign({}, options, { document: document });
return toPublicHtml(delta, formats, options);
Expand Down
5 changes: 0 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var JSDOM = require('jsdom').JSDOM;
var toHtml = require('./lib/export/to_html');
var toInlineHtml = require('./lib/export/to_inline_html');
var toInternalHtml = require('./lib/export/to_internal_html');
var toPublicHtml = require('./lib/export/to_public_html');
var toPlaintext = require('./lib/export/to_plaintext');

Expand All @@ -14,10 +13,6 @@ module.exports = {
options = Object.assign({}, options, { document: new JSDOM().window.document });
return toInlineHtml(delta, formats, options);
},
toInternalHtml: function(delta, formats, options) {
options = Object.assign({}, options, { document: new JSDOM().window.document });
return toInternalHtml(delta, formats, options);
},
toPublicHtml: function(delta, formats, options) {
options = Object.assign({}, options, { document: new JSDOM().window.document });
return toPublicHtml(delta, formats, options);
Expand Down
9 changes: 0 additions & 9 deletions lib/export/to_internal_html.js

This file was deleted.

4 changes: 2 additions & 2 deletions lib/export/to_public_html.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var pick = require('lodash').pick;
var toHtml = require('./to_html');
var publicFormats = require('../formats').public;
var formatOptions = require('../formats').options;
var publicFormats = require('../formats');
var formatOptions = require('../formats/format_options');

module.exports = function toPublicHtml(delta, formats, options) {
formats = formats ? pick(publicFormats, formats) : publicFormats;
Expand Down
4 changes: 1 addition & 3 deletions lib/formats/actionbox.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports.public = {
module.exports = {
add: function(node, value, dom) {
dom(node.parentNode).switchTag('ASIDE');

Expand All @@ -17,5 +17,3 @@ exports.public = {
return div;
}
};

exports.private = require('./object')('actionbox');
7 changes: 1 addition & 6 deletions lib/formats/ad_placement.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
exports.private = {
type: 'line',
attribute: 'data-ad-placement-anchor'
};

exports.public = {
module.exports = {
type: 'line',
add: function(node, value) {
// add the attribute to the top-most wrapper div
Expand Down
38 changes: 2 additions & 36 deletions lib/formats/autolink.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,6 @@
var addLink = require('./link').public.add;
var addLink = require('./link').add;

exports.private = {
add: function(node, value, dom) {
if (node.nodeType !== Node.ELEMENT_NODE) {
var span = node.ownerDocument.createElement('span');
dom(node).wrap(span);
node = span;
}
node.setAttribute('data-autolink-id', value.id);
node.setAttribute('data-autolink-href', value.href);
if (value.disabled) {
node.setAttribute('data-autolink-disabled', '');
} else {
node.removeAttribute('data-autolink-disabled');
}
return node;
},
remove: function(node) {
node.removeAttribute('data-autolink-id');
node.removeAttribute('data-autolink-href');
node.removeAttribute('data-autolink-disabled');
return node;
},
value: function(node) {
return {
id: node.getAttribute('data-autolink-id'),
href: node.getAttribute('data-autolink-href'),
disabled: node.hasAttribute('data-autolink-disabled')
};
},
match: function(node) {
return node.hasAttribute('data-autolink-id');
}
};

exports.public = {
module.exports = {
add: function(node, value, dom) {
if (!value.disabled) {
node = addLink(node, value.href, dom);
Expand Down
5 changes: 1 addition & 4 deletions lib/formats/blockquote.js
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
var blockquote = { type: 'line', parentTag: 'BLOCKQUOTE' };

exports.public = blockquote;
exports.private = Object.assign({}, blockquote, { exclusive: true, inherit: true });
module.exports = { type: 'line', parentTag: 'BLOCKQUOTE' };
5 changes: 1 addition & 4 deletions lib/formats/bold.js
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
var bold = { tag: 'STRONG' };

exports.public = bold;
exports.private = Object.assign({}, bold, { prepare: 'bold' });
module.exports = { tag: 'STRONG' };
21 changes: 1 addition & 20 deletions lib/formats/br.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,8 @@
exports.private = {
type: 'line',
reverseMerge: true,
add: function(node) {
node.classList.add('soft-break');
return node;
},
remove: function(node) {
node.classList.remove('soft-break');
return node;
},
value: function(node) {
return node.classList.contains('soft-break');
},
match: function(node) {
return node.classList.contains('soft-break');
}
};

// All lines that end with a line-break will end with a <br> tag. `to_unison_html`
// post-processing will strip out extra <p> tags b/t lines after the fact.
//
// Ex. <p>Hello<br></p><p>world!</p> => <p>Hello<br>world!</p>
exports.public = {
module.exports = {
type: 'line',
add: function(node) {
var br = node.ownerDocument.createElement('br');
Expand Down
5 changes: 1 addition & 4 deletions lib/formats/bullet.js
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
var bullet = { type: 'line', parentTag: 'UL', tag: 'LI' };

exports.public = bullet;
exports.private = Object.assign({}, bullet, { exclusive: true, inherit: true });
module.exports = { type: 'line', parentTag: 'UL', tag: 'LI' };
4 changes: 1 addition & 3 deletions lib/formats/credits.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports.public = {
module.exports = {
add: function(node, value, dom) {
dom(node.parentNode).switchTag('ASIDE');
var div = node.ownerDocument.createElement('div');
Expand All @@ -9,5 +9,3 @@ exports.public = {
return div;
}
};

exports.private = require('./object')('credits');
4 changes: 1 addition & 3 deletions lib/formats/del.js
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
exports.private = exports.public = {
tag: 'DEL'
};
module.exports = { tag: 'DEL' };
4 changes: 1 addition & 3 deletions lib/formats/doc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports.public = {
module.exports = {
add: function(node, value, dom) {
dom(node.parentNode).switchTag('div');

Expand All @@ -15,5 +15,3 @@ exports.public = {
return div;
}
};

exports.private = require('./object')('doc');
21 changes: 1 addition & 20 deletions lib/formats/dropcap.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
exports.private = {
type: 'line',
splitAffinity: 'left',
add: function(node, value) {
node.setAttribute('data-dropcap', value.toString());
return node;
},
remove: function(node) {
node.removeAttribute('data-dropcap');
return node;
},
value: function(node) {
return node.dataset.dropcap === 'true';
},
match: function(node) {
return node.tagName === 'P' && node.hasAttribute('data-dropcap');
}
};

exports.public = {
module.exports = {
type: 'line',
add: function(node, value) {
if (value) {
Expand Down
21 changes: 1 addition & 20 deletions lib/formats/endmark.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
exports.private = {
type: 'line',
splitAffinity: 'right',
add: function(node, value) {
node.setAttribute('data-endmark', value.toString());
return node;
},
remove: function(node) {
node.removeAttribute('data-endmark');
return node;
},
value: function(node) {
return node.dataset.endmark === 'true';
},
match: function(node) {
return node.tagName === 'P' && node.hasAttribute('data-endmark');
}
};

exports.public = {
module.exports = {
type: 'line',
add: function(node, value) {
if (value) {
Expand Down
5 changes: 1 addition & 4 deletions lib/formats/fifthheader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
var fifthheader = { type: 'line', tag: 'H5' };

exports.public = fifthheader;
exports.private = Object.assign({}, fifthheader, { exclusive: true });
module.exports = { type: 'line', tag: 'H5' };
5 changes: 1 addition & 4 deletions lib/formats/firstheader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
var firstheader = { type: 'line', tag: 'H1' };

exports.public = firstheader;
exports.private = Object.assign({}, firstheader, { exclusive: true });
module.exports = { type: 'line', tag: 'H1' };
56 changes: 56 additions & 0 deletions lib/formats/format_options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module.exports = {
blockTag: 'P',
formatOrder: [
// inline: wrapper tag
'bold',
'italic',
'mark',
'small',
'strike',
'superscript',
'subscript',
'autolink',
'link', // links come last so that they can merge sibling nodes

// objects
'actionbox',
'credits',
'doc',
'hr',
'html',
'image',
'oembed',
'pullquote',
'ratingcard',
'newsletter',
'readmore',
'video',
'toh_project_details',
'toh_tools',
'pym',

// line: wrapper tag
'position',
'grouping',
'blockquote',

// line: wrapper tag + switch tag
'bullet',
'list',

// line: switch tag
'firstheader',
'secondheader',
'thirdheader',
'fourthheader',
'fifthheader',

// line: add classes / attributes
'dropcap',
'leadgraf',
'endmark',
'ad_placement',
'br',
'id'
]
};
5 changes: 1 addition & 4 deletions lib/formats/fourthheader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
var fourthheader = { type: 'line', tag: 'H4' };

exports.public = fourthheader;
exports.private = Object.assign({}, fourthheader, { exclusive: true });
module.exports = { type: 'line', tag: 'H4' };
7 changes: 1 addition & 6 deletions lib/formats/grouping.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
exports.private = {
type: 'line',
attribute: 'data-grouping'
};

exports.public = {
module.exports = {
type: 'line',
add: function(node, value, dom) {
// Create the image grid container with appropriate classes
Expand Down
4 changes: 1 addition & 3 deletions lib/formats/hr.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
exports.public = {
module.exports = {
add: function(node, value, dom) {
var hr = dom(node.parentNode).switchTag('hr').get();
hr.classList.add('p-entry-hr');
return hr;
}
};

exports.private = require('./object')('hr');
4 changes: 1 addition & 3 deletions lib/formats/html.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports.public = {
module.exports = {
add: function(node, value, dom) {
var temp = node.ownerDocument.createElement('div');
temp.innerHTML = value.value;
Expand All @@ -19,5 +19,3 @@ exports.public = {
return frag;
}
};

exports.private = require('./object')('html');
7 changes: 1 addition & 6 deletions lib/formats/id.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
exports.private = {
type: 'line',
attribute: 'id'
};

exports.public = {
module.exports = {
type: 'line',
add: function(node, value) {
if (!node.id) {
Expand Down
4 changes: 1 addition & 3 deletions lib/formats/image.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports.public = {
module.exports = {
add: function(node, value, dom) {
var doc = node.ownerDocument;
dom(node.parentNode).switchTag('figure');
Expand Down Expand Up @@ -29,5 +29,3 @@ exports.public = {
return frag;
}
};

exports.private = require('./object')('image');
Loading

0 comments on commit 615da97

Please sign in to comment.