Shinmera / plump

Practically Lenient and Unimpressive Markup Parser for Common Lisp
https://shinmera.github.io/plump
zlib License
119 stars 21 forks source link

Use Generic Wild Card Tag Dispatcher #32

Closed charJe closed 3 years ago

charJe commented 3 years ago

A wild card dispatcher has a name * and will match any tag. It is always at the end of a dispatcher list. This allows you to define a default behavior for a "mode"; the default behavior for tags in html-mode is whatever the wild card dispatcher is in *html-tags*.

I defined one for html-mode because it looks like you defined your library to already do xml-mode by default. This causes issues when using non-standard html tags as described in the the html standard and on stack overflow.

On other HTML elements, the slash is an error, but error recovery will cause browsers to ignore it and treat the tag as a regular start tag. This will usually end up with a missing end tag causing subsequent elements to be children instead of siblings.

It would be fine if your library used xml printing as standard, but in your readme:

By default self-closing tags will be printed in "HTML-fashion,"

It works usually, but for non-standard tags it still resorts to xml parsing:

;; before my changes
(let ((plump:*tag-dispatchers* plump:*html-tags*))
  (plump:serialize (plump:parse "<non-standard>")))
;=> <non-standard/>
;; after my changes
(let ((plump:*tag-dispatchers* plump:*html-tags*))
  (plump:serialize (plump:parse "<non-standard>")))
;=> <non-standard></non-standard>
Shinmera commented 3 years ago

Looks good, thanks!