html-validator icon indicating copy to clipboard operation
html-validator copied to clipboard

Possible to add option to validate HTML fragments?

Open samdutton opened this issue 6 years ago • 8 comments
trafficstars

Not sure if this is possible, but I'd love to be able to use this to validate HTML fragments as well as complete documents.

Great module, by the way — thanks!

samdutton avatar Jul 12 '19 10:07 samdutton

I can look into it :-)

Can you give me some example code to make it clear what you want to validate?

zrrrzzt avatar Jul 13 '19 05:07 zrrrzzt

My 2 cents:

  • If you want to verify complete documents that are offline, you can set isLocal to true, and use the localhost url to verify.
  • If you want to verify fragments, I'm not sure if this is within the scope of this package, but you'd basically stuff your fragments inside a valid html template inside the body tag, and try to verify that I think? a few things may be off though (like line number) that you'd need to correct.

p1ho avatar Jul 13 '19 18:07 p1ho

My idea is to wrap the fragments in <html><body></body></html> and use the validator as usual. You would probably need to activate this sort of behaviour with a special flag.

This would work if fragments = parts of html.

zrrrzzt avatar Jul 13 '19 18:07 zrrrzzt

I think the base template has to be a bit more complicated than that. I tested just now with w3c validator. and I think this is the bare minimum you need.

<!doctype html><html lang=""><head><title>fragment</title></head><body>
  <!-- insert fragment -->
</body></html>

p1ho avatar Jul 13 '19 18:07 p1ho

Yeah, that's the minimum for a valid document. I don't think it would require much effort to add this functionality either. I'll look at it tomorrow.

zrrrzzt avatar Jul 13 '19 21:07 zrrrzzt

Can you give me some example code to make it clear what you want to validate?

I've written a Node app to convert SRT captions https://en.wikipedia.org/wiki/SubRip to 'readable' HTML.

I would like to be able to offer the output as a complete document, or as a 'fragment', i.e. just the content.

On Sat, 13 Jul 2019 at 22:24, Geir Gåsodden [email protected] wrote:

Yeah, that's the minimum for a valid document. I don't think it would require much effort to add this functionality either. I'll look at it tomorrow.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/zrrrzzt/html-validator/issues/150?email_source=notifications&email_token=AABSDKTTXVUQ5UW5N34QPXDP7JBYJA5CNFSM4ICGRBR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZ3ZUOY#issuecomment-511154747, or mute the thread https://github.com/notifications/unsubscribe-auth/AABSDKTEMWHOVPQ26LRZTODP7JBYJANCNFSM4ICGRBRQ .

samdutton avatar Jul 14 '19 07:07 samdutton

Just released version 4.1.0

Now you can add fragments as data and set isFragment to true.

Hope this works out for you use case @samdutton

zrrrzzt avatar Jul 14 '19 09:07 zrrrzzt

Wow — that was quick! Thank you.

On Sun, 14 Jul 2019 at 10:58, Geir Gåsodden [email protected] wrote:

Just released version 4.1.0

Now you can add fragments as data and set isFragment to true.

Hope this works out for you use case @samdutton https://github.com/samdutton

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/zrrrzzt/html-validator/issues/150?email_source=notifications&email_token=AABSDKUIZLMKDDW4OXFZMCDP7L2ETA5CNFSM4ICGRBR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZ4CB3I#issuecomment-511189229, or mute the thread https://github.com/notifications/unsubscribe-auth/AABSDKSL26WI6EXN6C6G2NDP7L2ETANCNFSM4ICGRBRQ .

samdutton avatar Jul 14 '19 10:07 samdutton