Example #1
0
std::string GumboInterface::build_attributes(GumboAttribute * at, bool no_entities, 
                                             bool run_src_updates, bool run_style_updates)
{
    std::string atts = " ";
    std::string name = get_attribute_name(at);
    std::string local_name = at->name;
    atts.append(name);
    std::string attvalue = at->value;

    if (run_src_updates && (local_name == aHREF || local_name == aSRC || 
                            local_name == aPOSTER || local_name == aDATA)) {
        attvalue = update_attribute_value(attvalue);
    }

    if (run_style_updates && (local_name == "style")) {
        attvalue = update_style_urls(attvalue);
    }

    // we handle empty attribute values like so: alt=""
    char quote = '"';
    std::string qs="\"";

    // verify an original value existed since we create our own attributes
    // and if so determine the original quote character used if any

    if (at->original_value.data) {
        if ( (!attvalue.empty())   || 
             (at->original_value.data[0] == '"') || 
             (at->original_value.data[0] == '\'') ) {

          quote = at->original_value.data[0];
          if (quote == '\'') qs = std::string("'");
          if (quote == '"') qs = std::string("\"");
        }
    }

    atts.append("=");
    atts.append(qs);
    if (no_entities) {
        atts.append(attvalue);
    } else {
        atts.append(substitute_xml_entities_into_attributes(quote, attvalue));
    }
    atts.append(qs);
    return atts;
}
Example #2
0
std::string GumboInterface::build_attributes(GumboAttribute * at, bool no_entities, bool runupdates)
{
    std::string atts = " ";
    atts.append(at->name);
    std::string attvalue = at->value;

    if (runupdates && (at->name == HREF || at->name == SRC)) {
        attvalue = update_attribute_value(attvalue);
    }

    // how do we want to handle attributes with empty values
    // <input type="checkbox" checked />  or <input type="checkbox" checked="" /> 
    // So determine original quote character used if it exists
    char quote = '"';
    if (!attvalue.empty()) {
        if (at->original_value.length > 0) {
            quote = at->original_value.data[0];
        }
        std::string qs = "";
        if (quote == '\'') {
          qs = std::string("'");
        } else if (quote == '"') {
          qs = std::string("\"");
        } else {
          quote = '"';
        }
        atts.append("=");
        atts.append(qs);
        if (no_entities) {
            atts.append(attvalue);
        } else {
            atts.append(substitute_xml_entities_into_attributes(quote, attvalue));
        }
        atts.append(qs);
    }
    return atts;
}
Example #3
0
std::string GumboInterface::build_attributes(GumboAttribute * at, bool no_entities, bool runupdates)
{
    std::string atts = " ";
    std::string name = get_attribute_name(at);
    std::string local_name = at->name;
    atts.append(name);
    std::string attvalue = at->value;

    if (runupdates && (local_name == HREF || local_name == SRC)) {
        attvalue = update_attribute_value(attvalue);
    }

    // we handle empty attribute values like so: alt=""
    char quote = '"';
    std::string qs="\"";

    if ( (!attvalue.empty())   || 
         (at->original_value.data[0] == '"') || 
         (at->original_value.data[0] == '\'') ) {

      // determine original quote character used if it exists
      quote = at->original_value.data[0];
      if (quote == '\'') qs = std::string("'");
      if (quote == '"') qs = std::string("\"");
    }

    atts.append("=");
    atts.append(qs);
    if (no_entities) {
        atts.append(attvalue);
    } else {
        atts.append(substitute_xml_entities_into_attributes(quote, attvalue));
    }
    atts.append(qs);
    return atts;
}