Skip to content

Commit

Permalink
Merge pull request #67 from posthtml/fix-lowercasing
Browse files Browse the repository at this point in the history
  • Loading branch information
cossssmin authored Jan 9, 2024
2 parents 31c50b6 + d263587 commit 4f2643f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const intersectKeys = require('./intersect-keys.js');

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

function processContent(options, content, attribute, attributeValue) {
Expand Down
12 changes: 12 additions & 0 deletions test/fixtures/text.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html>
<head>
<title>Hello there!</title>
</head>
<body>
<p class="foo">Plain text</p>
<p replace-with-lorem>
Text should be replaced with "Lorem".
</p>
<div ceil>1.2</div>
</body>
</html>
11 changes: 0 additions & 11 deletions test/fixtures/txt.html

This file was deleted.

8 changes: 6 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ const plugin = require('..')
const getFixture = file => readFileSync(join(__dirname, 'fixtures', file), 'utf8')

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

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

t.truthy((/<p>Lorem<\/p>/).exec(html))
t.truthy((/<div>2<\/div>/).exec(html))
})

test('Attr', async t => {
Expand Down

0 comments on commit 4f2643f

Please sign in to comment.