11

I would like to find a tool to convert old static HTML documents with things such as

<table border="1" cellspacing="0" cellpadding="0">
<td width="284" valign="top">
<font color="#0000FF">

(and other similar) to HTML5-compliant format where those attributes must be set by CSS.

The main goal is to remove usage of obsolete features and replace them with appropriate alternative.

Inline CSS would suffice. For example,
<font color="#0000FF"> should be replaced with <span style="color:#0000FF">

Also I don't care about platform, even online service would suit.

  • 2
    On a more serious note, I'm not sure what to do with this question. It's clear enough what you want, it's also clear to me you aren't going to get it. There isn't something that just magically takes bad code and writes good code. Do you have a more specific list of things you need converted? Do you have a list of the kinds of formatting used? Is layout involved? (from your sample I'm guessing it is). How much of that would you expect to be preserved? I want to answer "impossible" as it stands, but maybe with more criteria there is something that could help. Voting to close pending more data. – Caleb Feb 21 '14 at 19:01
  • 1
    I agree with @Caleb there is no magic bullet here... and more importantly you will rarely want to convert the outputted HTML... you'll want to convert the source (e.g. ASP/JSP/PHP) code that generates the HTML. I think your best bet would be a series of well planned (and carefully inspected) global Search & Replace calls. – scunliffe Feb 21 '14 at 22:13
  • @scunliffe OP states the source is old static html pages, so that's a non-concern. (I won't even get into the sites that use tidy as a live output filter on all their dynamic pages. Ug) – Caleb Feb 21 '14 at 22:18
  • 1
    It is not about bad code but about valid HTML4/XHTML that needs to be upgraded. Nothing exceptional, there is complete list of features and their modern counterparts on the link. – user Feb 21 '14 at 22:24
  • 1
    Yes, there is such a 'tool'; a paid web developer (although we don't take kindly to being called tools and don't find such behaviour funny, either). – Agi Hammerthief Apr 10 '14 at 18:57
8

The HTML Tidy utility can clean up some of the basics for you. It will cover the basic inline style elements like <font>, but it won't handle more complicated things like when tables that have been used for half-layout half-style.

In particular you probably want the clean flag: (from man tidy)

-clean, -c
    replace FONT, NOBR and CENTER tags by CSS (clean: yes)

In other news, the tool is good for catching parsing and semantic errors and converting between doc types for basic static pages. It's worth running the output of code you have generated to see errors you are making os you can configure it not to just fix problems but also point them out to you.

There are a couple places where you can use the tool online.

As for converting tables and other junk that has been used for layout and styling rather that semantic use. I think you are just out of luck. You just can't fix stupid.

0

I, as well, am looking for a converting tool... Need to convert "good HTML4" and XHTML1.X. But need to know and to sure of all steps of the conversion. Tidy is not perfect and the imperfections are into a back-box, an inacessible C source code...

There are a perfect specification for the problem: now (since 2014-10-28) HTML5 is a standard (!) and section 11.2, "Non-conforming features" express exactly what we must to do.

Are there a "standard, reliable and white-box" tools, to work with these specifications? I think the answer is YES, and the tools are simple and well-knowed.

White-box reliable solution

As I mentioned, "good HTML4" and XHTML1.X: both can be loaded in a DOM Document. So, the DOM-based tools are:

  1. DOM load method or a "prepare and load" tool for generic HTML.

  2. Convert (with DOM or XSLT) all "layout tags" into style="..." attributes. This kind of conversion is termed "to inline style", used for HTML-emails, etc. See ex. CssToInlineStyles. All the CSS can be unified and re-compiled in this process.

  3. Convert tags and attributes, as the section 11.2 specify: XSLTv1+ can do the task.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.