Skip to content

Commit

Permalink
Merge pull request #6 from herablog/feature-tags
Browse files Browse the repository at this point in the history
v0.0.7.
  • Loading branch information
herablog committed Mar 24, 2016
2 parents 43833a1 + 8145b3e commit e6fdb0e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
25 changes: 20 additions & 5 deletions lib/plugins/disallowed-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ Object.defineProperty(exports, "__esModule", {
});

exports.default = function () {
var _this3 = this;
var _this4 = this;

return {
removeDisallowedTags: function removeDisallowedTags() {
removeTags.bind(_this3)();
return _this3;
removeTags.bind(_this4)();
return _this4;
},
replaceDisallowedTags: function replaceDisallowedTags() {
replaceInlineTags.bind(_this3)();
return _this3;
replaceInlineTags.bind(_this4)();
replaceBlockTags.bind(_this4)();
return _this4;
}
};
};
Expand All @@ -41,4 +42,18 @@ function replaceInlineTags() {
$conainer.append($newEl);
$el.replaceWith($conainer.html());
});
}

function replaceBlockTags() {
var _this3 = this;

var selectors = ['fieldset', 'legend', 'marquee'];
this.$(this.$(selectors.join(',')).get().reverse()).each(function (i, el) {
var $el = _this3.$(el);
var $conainer = _this3.$('<div>');
var $newEl = _this3.$('<div>');
$newEl.html($el.html());
$conainer.append($newEl);
$el.replaceWith($conainer.html());
});
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "html-to-amp",
"version": "0.0.6",
"version": "0.0.7",
"description": "Transform the normal html to the amp html.",
"main": "index.js",
"scripts": {
Expand Down
17 changes: 17 additions & 0 deletions src/plugins/disallowed-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ function replaceInlineTags() {
});
}

function replaceBlockTags() {
const selectors = [
'fieldset',
'legend',
'marquee'
];
this.$(this.$(selectors.join(',')).get().reverse()).each((i, el) => {
const $el = this.$(el);
const $conainer = this.$('<div>');
const $newEl = this.$('<div>');
$newEl.html($el.html());
$conainer.append($newEl);
$el.replaceWith($conainer.html());
});
}

export default function () {
return {
removeDisallowedTags: () => {
Expand All @@ -42,6 +58,7 @@ export default function () {
},
replaceDisallowedTags: () => {
replaceInlineTags.bind(this)();
replaceBlockTags.bind(this)();
return this;
}
};
Expand Down
9 changes: 8 additions & 1 deletion tests/plugins/disallowed-tags-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ import { expect } from 'chai';
import ampBuilder from '../../src/amp-builder';

describe('disallowed-tags', () => {
it('replaces inline disallowed-tags.', () => {
it('replaces disallowed inline tags.', () => {
const html = '<font color="red"><font size="3">aaa</font></font>';
const fixture = '<span><span>aaa</span></span>';
const builder = ampBuilder(html);
const result = builder.replaceDisallowedTags().html();
expect(result).to.equal(fixture);
});
it('replaces disallowed block tags.', () => {
const html = '<fieldset><legend><marquee><span>aaa</span></marquee></legend></fieldset>';
const fixture = '<div><div><div><span>aaa</span></div></div></div>';
const builder = ampBuilder(html);
const result = builder.replaceDisallowedTags().html();
expect(result).to.equal(fixture);
});
it('removes disallowed-tags.', () => {
const html = '<style>p { color: red; }</style>';
const fixture = '';
Expand Down

0 comments on commit e6fdb0e

Please sign in to comment.