prismicio-community / php-kit

Community maintained development kit for Prismic and the PHP language
https://prismic.io
Other
109 stars 83 forks source link

Rewrite StructuredText::asHtmlText #37

Closed tremby closed 10 years ago

tremby commented 10 years ago

This rewrite uses DOMDocument rather than manually editing the HTML string.

We drill down to the right text node based on the required offset of the span, split it in the necessary places and wrap it in the new node. We then don't need to worry about the new tags causing offset changes, since the DOM model doesn't count the tags as text.

It should be much more reliable; it's certainly much easier to read and understand, in my opinion.

This patch also closes a couple of potential issues and one definite issue: we skip over spans which are invalid (either improperly nested or which end before they start).

There are commented out throw new \Exception lines where warnings could be emitted. I don't want to throw exceptions because I still want some rendered HTML.

tremby commented 10 years ago

I forgot about the tests. I'll take a look tomorrow.

dohzya commented 10 years ago

I fixed the test (it was only a s/[]/array() :-) )

Really nice work, thank you a lot