j4w8n/htmlfy

Removes characters when HTML string doesn't start or end with `<` or `>`

Closed this issue · 5 comments

The following fails:

import { prettify } from 'htmlfy'
expect(prettify('foobar')).toBe('foobar')

because:

prettify('foobar') // returns 'ooba'

Thanks for reporting this! I hadn't thought of or tested that use-case. Unsure if it's covered in the original package and I removed the logic, or if it's always been a bug.

I'll take a look.

@christian-bromann I figured out what I was doing wrong and have that resolved in a local fix.

However, that lead me to wondering how to handle plain text in general. If you feed it a sentence or sentences on a single line, everything is returned as-is. But if you throw any new lines in, it goes wonky.

e.g.
foobar is my favorite color. Do you like it? returns the same back to you.
But if you add a line return after the first sentence, the new line is removed and leaves no space between sentences.

foobar is my favorite color.
Do you like it?

becomes foobar is my favorite color.Do you like it?

Clearly I need to preserve the space, but how would you expect newlines to be handled? Minified or no?

Clearly I need to preserve the space, but how would you expect newlines to be handled? Minified or no?

I would suggest to verify via RegExp if given string contains either a <tag /> or at least one of these combined <tag> and </tag> and if not, return the same text.

Fixed in v0.1.1

Awesome, thanks!