Skip to content

Commit

Permalink
feat: clear format when the span colored with real black or white
Browse files Browse the repository at this point in the history
  • Loading branch information
heycalmdown committed Nov 24, 2018
1 parent 979a041 commit e50e0d8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
14 changes: 14 additions & 0 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,17 @@ export function fragment(section: Section): Section {
section.body = $.html();
return section;
}

export function unsetBlackOrWhiteFont(section: Section): Section {
const $ = cheerio.load(section.body);
const spans = $('span');
spans.map((_i, el) => {
const span = $(el);
const color = span.css('color');
if (color === 'rgb(255,255,255)' || color === 'rgb(0,0,0)') {
span.css('color', '');
}
});
section.body = $.html();
return section;
}
5 changes: 3 additions & 2 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as querystring from 'querystring';
import * as _ from 'lodash';

import { Section, host, splitPinnedPages } from '../util';
import { attached, backgroundImage, mermaid, gliffy, link, code, fragment, emoticon } from '../plugin';
import { attached, backgroundImage, mermaid, gliffy, link, code, fragment, emoticon, unsetBlackOrWhiteFont } from '../plugin';

const context = process.env.CONTEXT;
const username = process.env.USERNAME;
Expand Down Expand Up @@ -64,7 +64,8 @@ router.get('/page/:id', (req, res, next) => {
mermaid,
link,
code,
fragment
fragment,
unsetBlackOrWhiteFont
];
return middlewares.reduce((section, middleware) => middleware(section), section);
}
Expand Down
23 changes: 21 additions & 2 deletions src/spec/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { convertImageSrcSet, sanitizeImageSrc, setHost, splitPinnedPages, parseParams } from '../util';
import { fragment } from '../plugin';
import { fragment, unsetBlackOrWhiteFont } from '../plugin';

function html(inner) {
return { body: '<html><head></head><body>' + inner + '</body></html>' };
Expand Down Expand Up @@ -66,5 +66,24 @@ describe('miniseminar', () => {
'<ul><li class="fragment"><strong>ha</strong>ha<ul><li class="fragment">he<strong>he</strong></li></ul></li></ul>'
));
});
})
});
});

describe('trouble shooting', () => {
it('should clear format if the span colored with real black', () => {
const body = '<span style="color: rgb(0,0,0);">abc</span>';
expect(unsetBlackOrWhiteFont({ body })).toEqual(html('<span style="">abc</span>'));
});
it('should clear format if the span colored with real white', () => {
const body = '<span style="color: rgb(255,255,255);">abc</span>';
expect(unsetBlackOrWhiteFont({ body })).toEqual(html('<span style="">abc</span>'));
});
it('should not clear format if the span colored with real white or real black', () => {
const body = '<span style="color: rgb(255,0,0);">abc</span>';
expect(unsetBlackOrWhiteFont({ body })).toEqual(html('<span style="color: rgb(255,0,0);">abc</span>'));
});
it('should clear format if the span colored with real white having children', () => {
const body = '<span style="color: rgb(255,255,255);">abc <a href="https://google.com">google</a></span>';
expect(unsetBlackOrWhiteFont({ body })).toEqual(html('<span style="">abc <a href="https://google.com">google</a></span>'));
});
});

0 comments on commit e50e0d8

Please sign in to comment.