dy / xhtm

XHTM − eXtended Hyperscript Tagged Markup
MIT License
25 stars 2 forks source link

Solitary less than (<) character in content throws syntax error #20

Closed aral closed 1 year ago

aral commented 1 year ago
import xhtm from 'xhtm'
import vhtml from 'vhtml' 

const html = xhtm.bind(vhtml)
const markup = html`<p>this < that</p>`

console.log(markup)

Error

file:///var/home/aral/sandbox/xhtm/node_modules/xhtm/htm.js:100
const err = (msg) => { throw SyntaxError(msg) }
                             ^
SyntaxError: Unclosed ``.
    at err (file:///var/home/aral/sandbox/xhtm/node_modules/xhtm/htm.js:100:30)
    at Function.htm (file:///var/home/aral/sandbox/xhtm/node_modules/xhtm/htm.js:95:14)
    at file:///var/home/aral/sandbox/xhtm/index.js:6:20
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)

Node.js v19.6.0

Suggested workaround

While <p>this < that</p> is not valid HTML, it is quite common to expect people to author HTML like this without thinking of escaping the less-than character during author time.

xhtm could escape solitary less-than characters in text content. i.e.,

const escapeSolitaryLessThan = str => String(str).replace(/<(\s)/g, '&lt;$1')

Thoughts? :)

dy commented 1 year ago

Fixed - works properly now in 1.5.15