Re: Using tidy for editing html

Charlie Reitzel <[email protected]> Sat, 17 Jun 2006 11:36:22 -0400
Newsgroups gmane.comp.web.html-tidy.devel
Message-ID <[email protected]>
I second Björn's comments.  Note, in my TidyUI, I avoided the whole issue 
by simply handling the input as text.  But, to do WYSIWYG, you would need 
some type of DOM.  If it was me, I would simply use the internal API (or, 
as you suggest, extend the C++ bindings, but using internal interfaces).

You will want to be careful to avoid conflicts.  The whole point of the 
"public" interface is to avoid name conflicts.  You could limit the 
exposure of internal Tidy calls to the implementation file (i.e. the 
heretofore non-existent tidyx.cpp).  Does that make sense?

tidyx.h
namespace Tidy
{
class Document
{
public:
         ...
         // New, update method
         bool AddAttr( Node* tnod, ctmbstr attrName, ctmbstr attrValue );
         bool AddAttr( Node* tnod, TidyAttrId attrId, ctmbstr attrValue );
         ...
};
}

tidyx.cpp

#include "tidyx.h"
#include <lexer.h>      // Don't expose lexer.h everywhere you include 
<tidyx.h>

namespace Tidy {
...
bool Document::AddAttr( Node* tnod, ctmbstr attrName, ctmbstr attrValue )
{
   if ( IsValidAttrName(attrName) )
   {
     // Keep internal Tidy types private to tidyx.cpp
     TidyDocImpl* doc = tidyDocToImpl( _tdoc );
     ::Node* nod = tidyNodeToImpl( (TidyNode)tnod );
     AttVal* attVal = AddAttribute( doc, nod, attrName, attrValue );
     return ( NULL != attVal );
   }
   return false;
}
bool Document::AddAttr( Node* tnod, TidyAttrId attrId, ctmbstr attrValue )
{
   // Keep internal Tidy types private to tidyx.cpp
   TidyDocImpl* doc = tidyDocToImpl( _tdoc );
   ::Node* nod = tidyNodeToImpl( (TidyNode)tnod );
   AttVal* attVal =  AddAttributeById( doc, nod, attrId, attrValue );
   return ( NULL != attVal );
}
...
}

At 06:45 PM 6/16/2006 +0200, Bjoern Hoehrmann wrote:
>* Vincent Finn wrote:
> >I am using the C++ binding and it only seems to have read
> >functionality. Is that an oversight or is there a design
> >reason for it?
>
>That's correct, Tidy does not expose such functionality. Also note that
>the read functionality is not complete, you cannot access the content of
>text nodes, for example.
>
> >Essentially I want to know is there any inherent restriction in
> >the design that would make adding functions like NewNode,
> >CloneNode and RemoveNode to the C++ classes a bad idea?
>
>Well, Tidy is not really designed to enable this, so you would need some
>hacks to make Tidy expose this in a good manner. It seems the current
>developers are neither very interested in this and not committed to
>maintaining such functionality. It should be possible, but you are
>generally better off with simply converting Tidy's internal DOM to some
>other DOM structure.
>--
>Björn Höhrmann · mailto:[email protected] · http://bjoern.hoehrmann.de
>Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
>68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
>
>
>_______________________________________________
>Tidy-develop mailing list
>[email protected]
>https://lists.sourceforge.net/lists/listinfo/tidy-develop