pytidylib icon indicating copy to clipboard operation
pytidylib copied to clipboard

`tidy_fragment` expects whole document

Open Garrett-R opened this issue 5 years ago • 2 comments

Observe the following output from the terminal:

In [22]: from tidylib import tidy_fragment 

In [27]: doc, errors = tidy_fragment('<strong><div>yup</div></strong>')                                                                                                      

In [28]: print(errors)                                                                                                                                                       
line 1 column 1 - Warning: missing <!DOCTYPE> declaration
line 1 column 1 - Warning: inserting implicit <body>
line 1 column 1 - Warning: missing </strong> before <div>
line 1 column 14 - Warning: inserting implicit <strong>
line 1 column 23 - Warning: discarding unexpected </strong>
line 1 column 1 - Warning: inserting missing 'title' element
line 1 column 1 - Warning: trimming empty <strong>

I believe it should not require inserting an implicit <body> given that it's just a "fragment".

Garrett-R avatar Aug 18 '20 16:08 Garrett-R

tidy works on documents; the fragment function was my idea. If I remember correctly it uses an implicit body and then pulls the content back out of the body. The warnings are from tidy itself and are generally of low criticality.

countergram avatar Aug 19 '20 01:08 countergram

I just tested again after having updated the underlying libtidy and now it works as expected:

In [1]: from tidylib import tidy_fragment                                                                                                                                    

In [2]: doc, errors = tidy_fragment('<strong><div>yup</div></strong>')                                                                                                       

In [3]: print(errors)                                                                                                                                                        
line 1 column 1 - Warning: missing </strong> before <div>
line 1 column 14 - Warning: inserting implicit <strong>
line 1 column 23 - Warning: discarding unexpected </strong>
line 1 column 1 - Warning: trimming empty <strong>

(note it's no longer complaining about missing <!DOCTYPE> declaration)

Sorry about that, and thanks again for your help!

Garrett-R avatar Aug 19 '20 15:08 Garrett-R