htmlArea

A directory of browser-based WYSIWYG editors

  MAIN
INDEX
SEARCH
POSTS
WHO'S
ONLINE
LOG
IN

Home: htmlArea 2: htmlArea 2 & 3 archive (read only): htmlArea v2.0 - Add-Ons:
ASP: From HTML to XHTML - better code with version 2.*


The htmlArea 2 & 3 editors have been discontinued.

We've made these forums available as a read-only reference and knowledge-base for people using or developing editors based on htmlArea 2 or 3.

Anyone who is interested in taking over version 2 or 3 is free to do so. All we ask is that you choose a new name that doesn't have "htmlarea" in it to avoid confusion with this site. We'll even give you a link in the directory to make it easier for people to find you. If you are developing or hosting an htmlArea based-editor under a new name, please submit it to our directory.

 


eisa
User

Jul 16, 2004, 5:06 AM

Post #1 of 3 (3973 views)
Shortcut
ASP: From HTML to XHTML - better code with version 2.* Can't Post

As you all know HTMLArea 2.* doesn't produce very good HTML. Yesterday another person asked a question in another forum (http://forums.devarticles.com) if it was a solution for making HTMLArea 2.* to produce better code (XHTML). HTMLArea 3.0 can of course produce XHTML, but since there isn't so many functions for that version this could be a solution.

The solution is here:
http://www.dmxzone.com/showDetail.asp?TypeId=28&NewsId=6635&LinkFile=page7.htm

Just use that code/function on the input, and the HTML will be saved as XHTML (all code will be lower-case, all tags will be closed and quotes " will be added).

Ex. SQL_query = "UPDATE Articles SET ArticleText = '" & Replace(Convert2Xhtml(Cstr(rsArticles("ArticleText")),"'","''")

Just so you know, the code inside HTMLArea will still look ugly (because of it's nature), but the output will be OK.

http://www.savio.no/htmlarea/example.asp | Webdesign


(This post was edited by eisa on Jul 16, 2004, 5:23 AM)


eisa
User

Jul 16, 2004, 5:18 AM

Post #2 of 3 (3969 views)
Shortcut
Re: [eisa] ASP: From HTML to XHTML - better code with version 2.* [In reply to] Can't Post

By the way, it's also possible to download the code. It's also some code there which is supposed to update your code in the database. This code didn't work for me, so here is my solution (also using GetRows for better performance). Also one small difference when adding empty ALT if not present in the IMG tag:

<%@LANGUAGE="VBSCRIPT"%>
<% Server.ScriptTimeout = 6000 %>
<% Response.Buffer = false %>
<script language="JavaScript" type="text/javascript" runat="server">
function convert2Xhtml(theHtml) {
var html;
html = theHtml;

// Make xhtml compatible
html = html.replace(/<.*>?>/g,function(m,p,s){return m.replace(/\s(\w+=)([#\w,;]+)/g,function(m,p,s){return ' ' + p.toLowerCase() + '"' + s + '"';});});
html = html.replace(/<(\/?\w+)([^>]*>)/g,function(m,p,s){return '<' + p.toLowerCase() + s;});
html = html.replace(/<(meta|base|basefont|param|link|img|br|hr|area|input)([^>]*)>/g,function(m,p,s){return m.indexOf(' />') == -1 ? '<' + p + s + ' />' : m;});

// Add empty ALT if not present in the IMG tag
html = html.replace(/<(img)([^>]*)\/>/g,function(m,p,s){return m.indexOf('alt=') == -1 ? '<' + p + s + ' alt=" " />' : m;});

return html;
}
</script>

<html>
<head>
<title>Convert To XHTML</title>
</head>
<body>
<%
'Convert News to XHTML
'Convert Articles
if request.queryString("action") = "articles" then
Dim rsConvertArticles

set rsConvertArticles = Server.CreateObject("ADODB.Recordset")
rsConvertArticles.ActiveConnection = "--your connectionstring here--"
rsConvertArticles.Source = "SELECT ArticleID, Ingress, ArticleText FROM Articles"
rsConvertArticles.CursorType = 0
rsConvertArticles.CursorLocation = 2
rsConvertArticles.LockType = 1
rsConvertArticles.Open()
arrRows = rsConvertArticles.GetRows()
rsConvertArticles.Close()
Set rsConvertArticles = Nothing

intCols = uBound(arrRows,1) 'check columns, starting on 0
intRows = uBound(arrRows,2) 'check rows, starting on 0
For cRows = 0 to intRows


DataSource = "--your connectionstring her--"
Set MyConn = Server.CreateObject("ADODB.Connection")
MyConn.Open DataSource


SQL_query = "UPDATE Articles SET Ingress = '" & Replace(Convert2Xhtml(Cstr(arrRows(1,cRows))),"'","''") & "', ArticleText = '" & Replace(Convert2Xhtml(Cstr(arrRows(2,cRows))),"'","''") & "' WHERE ArticleID = " & arrRows(0,cRows)
MyConn.Execute(SQL_query)


MyConn.Close
Set MyConn = nothing
Next
Response.Write "Number of changed articles: " & cRows
end if%>
<h1>Convert 2 XHTML</h1>
<a href="convert2Xhtml.asp?action=articles">Convert Articles</a> <br />
</body>
</html>


http://www.savio.no/htmlarea/example.asp | Webdesign


(This post was edited by eisa on Jul 16, 2004, 6:04 AM)


smugpie
New User

Sep 1, 2004, 6:48 AM

Post #3 of 3 (3708 views)
Shortcut
Re: [eisa] ASP: From HTML to XHTML - better code with version 2.* [In reply to] Can't Post

Thanks for posting this bit of code, very useful.

We use htmlarea 2.03 in our content management system, and hope to use the Convert2Xhtml function to make everything XHTML compliant before writing the code away in our db. The javascript is really good as far as it goes, but doesn't deal with maximising attributes within tags, ie. converting <td nowrap> to <td nowrap="nowrap">

Has anyone written a regular expression to deal with this situation? If so, it would be fantastic if you could share it with us.

Thanks

Andrew

 
 
 


Search for (options)