Writing valid XHTML posts on WordPress
WordPress contains a nice WYSIWYG HTML editor, but it doesn’t fit with XHTML specifications.
I found out a cool method to generate valid XHTML code on WordPress; all what you need is Nvu and Vim.
First, use Nvu to edit your HTML text, and set you markup output to XHTML transitional:
Tools - Preferences - Advanced - Markup: XHTML1 and Transitional.
Keep writing and decorating: Nvu is powerful doesn’t screw your code up!
Once you made a valid document, you have to convert it to WordPress format. First, backup the original HTML file (who knows?) and edit the copy with Vim. During all the process, you need to have the escape mode activated, just press <ESC>.
Put the cursor on the line that contains only <body> tag and type (sensitive case)
dgg
It will remove the lines from ‘body’ tag to the beginning.
The same, go to the line containing </body> and get rid of the end of the document:
dG
As Nvu wraps lines, we will convert the newlines into spaces:
:%s/\n/\ /g
Now, we will convert the XHTML breaklines (<br />) to carriage returns (and not newlines):
:%s/<br\ \/>\ /\r/g
:%s/<br\ \/>/\r/g
Next, convert the lines that contain more than one newline to spaces, otherwise, WordPress will put incorrect <p> tags
:%s/\n\{2\}/\r\ \r\ /g
Optionally, you can add a carriage return to some tags that are displayed by blocks by default such as <blockquote> :
:%s/\([^\^]\)\(<blockquote>\)/\1\r\2/g
But </blockquote> must be the last term at the end of the line:
:%s/\(<\/blockquote>\)\([^\$]\)/\1\r\2/g
Now you can check that your post is a valid XHTML, exactly the same for this blog!

February 4th, 2006 at 8:42 pm
[…] Az hogy a farokba lehet hogy nem létezik bloggoló extension-je az NVU-nak? Ez lehetne a legállatabb blog kliens a föld kerekén… egy technorati search elég hozzá hogy lássuk: vannak emberek, akik ezt használják blogposzt íráshoz, de ez a kimásolós-bepasztálós módszer szerintem béna. Színtiszta XUL az egész, mibe kerülne ehhez is csinálni egy extension-t - de ez még semmi - rájöttem hogy összességében alig van extension az NVU-hoz - és semmi sincs, ami értelmesebbé is tenné. Amúgy rosszul emlékszem, hogy ez valaha mozilla projekt volt? Vajon mi történhetett. És július óta frissítés sincs, hm… […]