Skip to content

Commit 4f2643f

Browse files
authored
Merge pull request #67 from posthtml/fix-lowercasing
2 parents 31c50b6 + d263587 commit 4f2643f

4 files changed

Lines changed: 19 additions & 14 deletions

File tree

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const intersectKeys = require('./intersect-keys.js');
22

33
function lowercaseEntities(string) {
4-
return string.replace(/&[A-Z]+;/g, match => match.toLowerCase());
4+
return String(string).replace(/&[A-Z]+;/g, match => match.toLowerCase());
55
}
66

77
function processContent(options, content, attribute, attributeValue) {

test/fixtures/text.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<html>
2+
<head>
3+
<title>Hello there!</title>
4+
</head>
5+
<body>
6+
<p class="foo">Plain text</p>
7+
<p replace-with-lorem>
8+
Text should be replaced with "Lorem".
9+
</p>
10+
<div ceil>1.2</div>
11+
</body>
12+
</html>

test/fixtures/txt.html

Lines changed: 0 additions & 11 deletions
This file was deleted.

test/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ const plugin = require('..')
77
const getFixture = file => readFileSync(join(__dirname, 'fixtures', file), 'utf8')
88

99
test('Text', async t => {
10-
const fixture = getFixture('txt.html')
11-
const plugins = [plugin({txt: () => 'Lorem'})]
10+
const fixture = getFixture('text.html')
11+
const plugins = [plugin({
12+
'replace-with-lorem': () => 'Lorem',
13+
ceil: content => Math.ceil(Number.parseFloat(content)),
14+
})]
1215

1316
const {html} = await posthtml(plugins).process(fixture)
1417

1518
t.truthy((/<p>Lorem<\/p>/).exec(html))
19+
t.truthy((/<div>2<\/div>/).exec(html))
1620
})
1721

1822
test('Attr', async t => {

0 commit comments

Comments
 (0)