shakaran
shakaran

Reputation: 11122

How automatically fix html5 validation warnings?

I commonly write a lot html code and when I write I try to follow the specification for a valid and semantic web, normally following the HTML5 specification. For validate the HTML code I use the official W3C Markup validator service.

Also, I have to modify another HTML code from other coworkers, collaborators or even contribute in another external projects.

In my code normally I have a lot errors, but it is more heavy when you have to rewrite the code from others. Also this is a manual operation that cost a lot time only for get "green" status in a validator.

Some changes seems easy like a missing "/" in a <img> tag or a missing title or alt attribute are very frequent. I would know if there are some program or way of automatize certain changes for perform this changes (and don't reinvent the wheel) as a batch and avoid manual time cost with modifications. I mean, not only a check syntax validator (I think that IDEs like Eclipse do exactly that), I am searching more a writing analysis tool that modify the code warnings and fix too, not only warning you about them.

Upvotes: 1

Views: 2358

Answers (1)

FelipeAls
FelipeAls

Reputation: 22181

There's no machine or algorithm that can decide if a missing alt attribute needs to remain empty (alt="" because it's a decorative image) or what text should be put as a value.
You need to analyse many bits of context, know which information is being sent to users and how it'll have to be coded in this particular context.
From WebAIM :
Creating Accessible Images - Creating Effective Alternative (alt)Text
Appropriate Use of Alternative Text


But to detect that img is lacking alt attribute is a job where computers are very useful and reliable (it's so tedious and easy to implement). Can be done with:

  • extensions like Web Developer Toolbar,
  • services like http://tanaguru.com , "diagnostic" user stylesheets (something like img:not([alt]) { border: 5px solid red }
  • regular expression in whatever language or text editor with negative lookahead

Getting rid of / is as simple as replacing /> by > (is it an error in HTML5?)


Why would you've to rewrite HTML code written from your colleagues?

  • Train them to know what is a correct code and what is an error and to be careful when they're coding...
  • They shouldn't commit code that results in HTML validation errors.
  • Create and maintain front-end developer’s style guide

Upvotes: 1

Related Questions