Optimizing simple xHTML parser
Although optional, you can keep your #includes organized (alphabetically, for instance) so that it's easier to locate an individual one or to determine if you've already included a particular one.
You've included &lt;sstream&gt;, but I don't see any use of stringstreams.  If you're not utilizing this library, then remove it.
Avoid using namespace X in global scope as it will expose it to the entire program or file, which can break code in cases such as name-clashing (using the same name for something in which something doesn't belong to the namespace).  It could also make it difficult for readers to tell what is part of a particular namespace (I cannot tell what belongs to v8, so I'm having a bit more trouble reviewing this).  If you insist on keeping a using, then keep it local, such as in a function.
For this enum:

enum Tags {
    Closing = 0,
    Paragraph,
    Heading
};


You don't need to explicitly set it to 0.  This is already the default starting value for enums.
You don't need a char* here:

int tagDetect(char *ptr){


Looking at the calling code, you're passing in an std::string.  You should just pass this object by itself.  Also, because it's not being modified, pass it by const&amp; to avoid a needless copy and any accidental modification:

int tagDetect(std::string const&amp; str){


In C++ in general, you should avoid passing raw pointers to functions as you cannot keep track of ownership with them (C++11 smart pointers helps with that for when points are necessary).  But in this case, you shouldn't need to deal with pointers.

With this change, you will need to modify the function code (I'll use different names for clarity):

This is accessing the first character:

if (*ptr == 'p')


so use front():

if (str.front() == 'p')


This is accessing the second one:

*(ptr + 1)


so you can use indices to make it more clear (while they are technically the same thing; yours is doing pointer arithmetic):

str[1]

I'd keep these on separate lines for readability:

int tagID, lastTag, id = 0, lastAppended = 0, clearStartPos;


They aren't entirely related to each other, and there could be some maintenance issues since some are declared and the others initialized.

int tagID;
int lastTag;
int id = 0;
int lastAppended = 0;
int clearStartPos;


You should also have these declared/initialized as close to their scope as possible.  This will help determine if any variable is no longer used (keeping around unused variables will clutter the code).  But if you cannot put them any closer, then do have each one on separate lines.