1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Changed rules to keep in line with actual markdown. Although Tox is marketed somewhat as a Skype-replacement, that doesn't mean we have to break compatibility with the rest of the web.

This commit is contained in:
Andrew Morgan 2016-01-29 15:17:41 -08:00
parent a809897850
commit 4c51be9a6b

View File

@ -187,9 +187,9 @@ QString ChatMessage::detectMarkdown(const QString &str)
// Create regex for certain markdown syntax // Create regex for certain markdown syntax
QRegExp exp("(\\*\\*)([^\\*\\*]{2,})(\\*\\*)" // Bold **text** QRegExp exp("(\\*\\*)([^\\*\\*]{2,})(\\*\\*)" // Bold **text**
"|(\\*)([^\\*]{2,})(\\*)" // Bold *text* "|(\\*)([^\\*]{2,})(\\*)" // Italics *text*
"|(\\_)([^\\_]{2,})(\\_)" // Italics _text_ "|(\\_)([^\\_]{2,})(\\_)" // Italics _text_
"|(\\_\\_)([^\\_\\_]{2,})(\\_\\_)" // Italics __text__ "|(\\_\\_)([^\\_\\_]{2,})(\\_\\_)" // Bold __text__
"|(\\-)([^\\-]{2,})(\\-)" // Underline -text- "|(\\-)([^\\-]{2,})(\\-)" // Underline -text-
"|(\\~)([^\\~]{2,})(\\~)" // Strike ~text~ "|(\\~)([^\\~]{2,})(\\~)" // Strike ~text~
"|(\\~~)([^\\~\\~]{2,})(\\~~)" // Strike ~~text~~ "|(\\~~)([^\\~\\~]{2,})(\\~~)" // Strike ~~text~~
@ -225,12 +225,12 @@ QString ChatMessage::detectMarkdown(const QString &str)
// Match captured string to corresponding md format // Match captured string to corresponding md format
if (exp.cap(1) == "**") // Bold **text** if (exp.cap(1) == "**") // Bold **text**
htmledSnippet = QString(" <b>%1</b> ").arg(snippet.mid(mul,snippet.length()-2*mul)); htmledSnippet = QString(" <b>%1</b> ").arg(snippet.mid(mul,snippet.length()-2*mul));
else if (exp.cap(4) == "*" && snippet.length() > 2) // Bold *text* else if (exp.cap(4) == "*" && snippet.length() > 2) // Italics *text*
htmledSnippet = QString(" <b>%1</b> ").arg(snippet.mid(mul/2,snippet.length()-mul)); htmledSnippet = QString(" <i>%1</i> ").arg(snippet.mid(mul/2,snippet.length()-mul));
else if (exp.cap(7) == "_" && snippet.length() > 2) // Italics _text_ else if (exp.cap(7) == "_" && snippet.length() > 2) // Italics _text_
htmledSnippet = QString(" <i>%1</i> ").arg(snippet.mid(mul/2,snippet.length()-mul)); htmledSnippet = QString(" <i>%1</i> ").arg(snippet.mid(mul/2,snippet.length()-mul));
else if (exp.cap(10) == "__"&& snippet.length() > 4) // Italics __text__ else if (exp.cap(10) == "__"&& snippet.length() > 4) // Bold __text__
htmledSnippet = QString(" <i>%1</i> ").arg(snippet.mid(mul,snippet.length()-2*mul)); htmledSnippet = QString(" <b>%1</b> ").arg(snippet.mid(mul,snippet.length()-2*mul));
else if (exp.cap(13) == "-" && snippet.length() > 2) // Underline -text- else if (exp.cap(13) == "-" && snippet.length() > 2) // Underline -text-
htmledSnippet = QString(" <u>%1</u> ").arg(snippet.mid(mul/2,snippet.length()-mul)); htmledSnippet = QString(" <u>%1</u> ").arg(snippet.mid(mul/2,snippet.length()-mul));
else if (exp.cap(16) == "~" && snippet.length() > 2) // Strikethrough ~text~ else if (exp.cap(16) == "~" && snippet.length() > 2) // Strikethrough ~text~