Check for Html Tag and Attribute style

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Check for Html Tag and Attribute style

Post by evstevemd »

Hi,
I have editor where I want to check if it's html tag then present tags autocomplete and if its attribute do the same with list of attributes. I haven't found any reliable way to find if text at cursor is at attribute or a tag. Below is what I currently have. But it gives me problems as wxSTC_H_DEFAULT is called in many other places (PHP Code for example inside <?php for example) which makes it unreliable.

Is there simple and reliable way to check for HTML tags and attribute that am missing?

Sorry for old post, I could not type well in mobile phone

checking for Tag

Code: Select all

bool Editor::IsStyleHtmlTag()
{
    int style = GetStyleAt(GetCurrentPos());
    switch(style)
    {
        case  wxSTC_H_ATTRIBUTE :
        case  wxSTC_H_ATTRIBUTEUNKNOWN :
        case  wxSTC_H_DOUBLESTRING :
        case  wxSTC_H_SINGLESTRING :
        case  wxSTC_H_TAG :
        case  wxSTC_H_TAGUNKNOWN :
        case wxSTC_H_OTHER:
        case  wxSTC_H_DEFAULT :
            return !IsStyleHtmlAttribute();
    }
    return false;
}
Checking for attribute

Code: Select all

bool Editor::IsStyleHtmlAttribute()
{
    wxString allowed = "htm_html_xhtml_php";
    if(!allowed.Contains(GetFileName().GetExt()))
        return false;

    int style = GetStyleAt(GetCurrentPos());
    switch(style)
    {
        case  wxSTC_H_ATTRIBUTE :
        case  wxSTC_H_ATTRIBUTEUNKNOWN :
        case  wxSTC_H_DOUBLESTRING :
        case  wxSTC_H_SINGLESTRING :
        {
            return true;
        }
        case  wxSTC_H_TAG :
        case  wxSTC_H_TAGUNKNOWN :
        case wxSTC_H_OTHER:
        case  wxSTC_H_DEFAULT :
        {
            wxString oldWordChars = GetWordChars();
            SetWordChars(oldWordChars+"<>?");
            int start = WordStartPosition(GetCurrentPos(), true);
            int end = WordEndPosition(GetCurrentPos(), true);
            wxString current = GetTextRange(start, end);
            //restore word chars
            SetWordChars(oldWordChars);
            int currentWordStart = WordStartPosition(GetCurrentPos(), true);

            if((!current.Contains("<?") && !current.Contains("<") && !current.Contains(">")) || current.IsEmpty())
                return true;
            else if(current.Contains(">") && GetTextRange(start, start+1)!="<")
                return true;
        }
    }
    return false;
}
TIA
S.
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Post Reply