示例#1
0
docstring const GuiClipboard::getAsText(TextType type) const
{
	// text data from other applications
	if ((type == AnyTextType || type == LyXOrPlainTextType) && hasTextContents(LyXTextType))
		type = LyXTextType;
	if (type == AnyTextType && hasTextContents(LaTeXTextType))
		type = LaTeXTextType;
	if (type == AnyTextType && hasTextContents(HtmlTextType))
		type = HtmlTextType;
	QString str;
	switch (type) {
	case LyXTextType:
		// must not convert to docstring, since file can contain
		// mixed encodings (use getAsLyX() instead)
		break;
	case AnyTextType:
	case LyXOrPlainTextType:
	case PlainTextType:
		str = qApp->clipboard()->text(QClipboard::Clipboard)
				.normalized(QString::NormalizationForm_C);
		break;
	case LaTeXTextType: {
		QMimeData const * source =
			qApp->clipboard()->mimeData(QClipboard::Clipboard);
		if (source) {
			// First try LaTeX, then TeX (we do not distinguish
			// for clipboard purposes)
			if (source->hasFormat(latexMimeType())) {
				str = source->data(latexMimeType());
				str = str.normalized(QString::NormalizationForm_C);
			} else if (source->hasFormat(texMimeType())) {
				str = source->data(texMimeType());
				str = str.normalized(QString::NormalizationForm_C);
			}
		}
		break;
	}
	case HtmlTextType: {
		QString subtype = "html";
		str = qApp->clipboard()->text(subtype, QClipboard::Clipboard)
				.normalized(QString::NormalizationForm_C);
		str = tidyHtml(str);
		break;
	}
	}
	LYXERR(Debug::ACTION, "GuiClipboard::getAsText(" << type << "): `" << str << "'");
	if (str.isNull())
		return docstring();

	return internalLineEnding(str);
}
示例#2
0
文件: util.cpp 项目: msjoberg/pumpa
QString addTextMarkup(QString text, bool useMarkdown) {
  QString oldText = text;

#ifdef DEBUG_MARKUP
  qDebug() << "\n[DEBUG] MARKUP\n" << text;
#endif

#ifdef NO_TIDY
  text = removeHtml(text);
# ifdef DEBUG_MARKUP
  qDebug() << "\n[DEBUG] MARKUP (clean inline HTML)\n" << text;
# endif
#endif

  if (useMarkdown) {
    // apply markdown
    text = markDown(text);
  } else {
    // linkify plain URLs
    text = linkifyUrls(text, useMarkdown);

#ifdef DEBUG_MARKUP
    qDebug() << "\n[DEBUG] MARKUP (linkify plain URLs)\n" << text;
#endif

    // This is a bit of a hack: if the text doesn't certain tags we
    // replace newlines with breaks.

    QRegExp rx("<p>|<ul>", Qt::CaseInsensitive);
    if (rx.indexIn(text) == -1)
      text.replace("\n", "<br/>");
  }

#ifdef DEBUG_MARKUP
  qDebug() << "\n[DEBUG] MARKUP (apply"
           << (useMarkdown?"Markdown)":"text conversion)") << "\n" << text;
#endif

#ifndef NO_TIDY
  bool tidyOk = false;
  text = tidyHtml(text, tidyOk);
#endif

#ifdef DEBUG_MARKUP
  qDebug() << "\n[DEBUG] MARKUP (libtidy)\n" << text;
#endif

  return text;
}