예제 #1
0
void WMLHandler::popState()
{
    if (!m_stateStack.isEmpty())
        m_state = m_stateStack.pop();
}
예제 #2
0
파일: tools.cpp 프로젝트: perihelion/basket
QString Tools::htmlToText(const QString &html)
{
	QString text = htmlToParagraph(html);
	text.remove("\n");
	text.replace("</h1>", "\n");
	text.replace("</h2>", "\n");
	text.replace("</h3>", "\n");
	text.replace("</h4>", "\n");
	text.replace("</h5>", "\n");
	text.replace("</h6>", "\n");
	text.replace("</li>", "\n");
	text.replace("</dt>", "\n");
	text.replace("</dd>", "\n");
	text.replace("<dd>",  "   ");
	text.replace("</div>","\n");
	text.replace("</blockquote>","\n");
	text.replace("</caption>","\n");
	text.replace("</tr>", "\n");
	text.replace("</th>", "  ");
	text.replace("</td>", "  ");
	text.replace("<br>",  "\n");
	text.replace("<br />","\n");
	// FIXME: Format <table> tags better, if possible
	// TODO: Replace &eacute; and co. by theire equivalent!

	// To manage tags:
	int pos = 0;
	int pos2;
	QString tag, tag3;
	// To manage lists:
	int deep = 0;            // The deep of the current line in imbriqued lists
	Q3ValueStack<bool> ul;    // true if current list is a <ul> one, false if it's an <ol> one
	Q3ValueStack<int>  lines; // The line number if it is an <ol> list
	// We're removing every other tags, or replace them in the case of li:
	while ( (pos = text.find("<"), pos) != -1 ) {
		// What is the current tag?
		tag  = text.mid(pos + 1, 2);
		tag3 = text.mid(pos + 1, 3);
		// Lists work:
		if (tag == "ul") {
			deep++;
			ul.push(true);
			lines.push(-1);
		} else if (tag == "ol") {
			deep++;
			ul.push(false);
			lines.push(0);
		} else if (tag3 == "/ul" || tag3 == "/ol") {
			deep--;
			ul.pop();
			lines.pop();
		}
		// Where the tag closes?
		pos2 = text.find(">");
		if (pos2 != -1) {
			// Remove the tag:
			text.remove(pos, pos2 - pos + 1);
			// And replace li with "* ", "x. "... without forbidding to indent that:
			if (tag == "li") {
				// How many spaces before the line (indentation):
				QString spaces = "";
				for (int i = 1; i < deep; i++)
					spaces += "  ";
				// The bullet or number of the line:
				QString bullet = "* ";
				if (ul.top() == false) {
					lines.push(lines.pop() + 1);
					bullet = QString::number(lines.top()) + ". ";
				}
				// Insertion:
				text.insert(pos, spaces + bullet);
			}
			if ( (tag3 == "/ul" || tag3 == "/ol") && deep == 0 )
				text.insert(pos, "\n"); // Empty line before and after a set of lists
		}
		++pos;
	}

	text.replace("&gt;",   ">");
	text.replace("&lt;",   "<");
	text.replace("&quot;", "\"");
	text.replace("&nbsp;", " ");
	text.replace("&amp;",  "&"); // CONVERT IN LAST!!

	return text;
}
예제 #3
0
void WMLHandler::pushState()
{
    m_stateStack.push(m_state);
}