+namespace {
+/**
+ * Tidy up a HTML chunk coming from the clipboard.
+ * This is needed since different applications put different kinds of HTML
+ * on the clipboard:
+ * - With or without the <?xml> tag
+ * - With or without the <!DOCTYPE> tag
+ * - With or without the <html> tag
+ * - With or without the <body> tag
+ * - With or without the <p> tag
+ * Since we are going to write a HTML file for external converters we need
+ * to ensure that it is a well formed HTML file, including all the mentioned tags.
+ */
+QString tidyHtml(QString input)
+{
+ // Misuse QTextDocument to cleanup the HTML.
+ // As a side effect, all visual markup like <tt> is converted to CSS,
+ // which is ignored by gnuhtml2latex.
+ // While this may be seen as a bug by some people it is actually a
+ // good thing, since we do import structure, but ignore all visual
+ // clutter.
+ QTextDocument converter;
+ converter.setHtml(input);
+ return converter.toHtml("utf-8");
+}
+}
+
+
+docstring const GuiClipboard::getAsText(TextType type) const