Get the inner text content of node. */
| 305 | |
| 306 | /** Get the inner text content of node. */ |
| 307 | QString innerText(GumboNode *node) |
| 308 | { |
| 309 | if (node->type == GUMBO_NODE_TEXT) { |
| 310 | return QString(node->v.text.text); |
| 311 | } |
| 312 | else if (node->type == GUMBO_NODE_ELEMENT && |
| 313 | node->v.element.tag != GUMBO_TAG_SCRIPT && |
| 314 | node->v.element.tag != GUMBO_TAG_STYLE) |
| 315 | { |
| 316 | QString contents = ""; |
| 317 | GumboVector *children = &node->v.element.children; |
| 318 | for (unsigned int i = 0; i < children->length; ++i) { |
| 319 | GumboNode * pNode = (GumboNode *)children->data[i]; |
| 320 | std::string pTagName = get_tag_name(pNode); |
| 321 | bool is_inline = nonbreaking_inline.find("|" + pTagName + "|") != std::string::npos; |
| 322 | bool is_special_handling = special_handling.find("|" + pTagName + "|") != std::string::npos; |
| 323 | const QString text = innerText(pNode); |
| 324 | if (i != 0 && !text.isEmpty()) { |
| 325 | if (!is_inline && !is_special_handling) { |
| 326 | contents.append("\n"); |
| 327 | } |
| 328 | } |
| 329 | contents.append(text); |
| 330 | } |
| 331 | return contents; |
| 332 | } |
| 333 | else |
| 334 | { |
| 335 | return QString(""); |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | /** 以QTextDocument.toPlainText标准实现这个函数 */ |
| 340 | QString plainText(GumboNode *node) |
no test coverage detected