diff --git a/src/chatlog/chatmessage.cpp b/src/chatlog/chatmessage.cpp
index 27b73acb0..6b9e08e79 100644
--- a/src/chatlog/chatmessage.cpp
+++ b/src/chatlog/chatmessage.cpp
@@ -55,7 +55,8 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString &sender, const QSt
text = detectQuotes(detectAnchors(text), type);
//markdown
- text = detectMarkdown(text);
+ if (Settings::getInstance().getMarkdownPreference() != 0)
+ text = detectMarkdown(text);
switch(type)
{
@@ -183,13 +184,13 @@ QString ChatMessage::detectMarkdown(const QString &str)
QString out;
// Create regex for certain markdown syntax
- QRegExp exp("(\\*\\*)([^\\*\\*]*)(\\*\\*)" // Bold **text**
- "|(\\*)([^\\*]*)(\\*)" // Italics *text*
- "|(\\_)([^\\_]*)(\\_)" // Italics _text_
- "|(\\_\\_)([^\\_\\_]*)(\\_\\_)" // Italics __text__
- "|(\\-)([^\\-]*)(\\-)" // Underline -text-
- "|(\\~)([^\\~]*)(\\~)" // Strike ~text~
- "|(\\~~)([^\\~\\~]*)(\\~~)" // Strike ~~text~~
+ QRegExp exp("(\\*\\*)([^\\*\\*]{2,})(\\*\\*)" // Bold **text**
+ "|(\\*)([^\\*]{2,})(\\*)" // Italics *text*
+ "|(\\_)([^\\_]{2,})(\\_)" // Italics _text_
+ "|(\\_\\_)([^\\_\\_]{2,})(\\_\\_)" // Italics __text__
+ "|(\\-)([^\\-]{2,})(\\-)" // Underline -text-
+ "|(\\~)([^\\~]{2,})(\\~)" // Strike ~text~
+ "|(\\~~)([^\\~\\~]{2,})(\\~~)" // Strike ~~text~~
);
// Support for multi-line text
@@ -205,21 +206,34 @@ QString ChatMessage::detectMarkdown(const QString &str)
QString htmledSnippet;
+ // Check for surrounding spaces and/or beginning/end of line
+ if (!((snipCheck.startsWith(' ') || offset == 0) && (snipCheck.endsWith(' ') || offset + snipCheck.trimmed().length() == out.length())))
+ {
+ offset += snippet.length();
+ continue;
+ }
+
+ int mul = 0; // Determines how many characters to strip from markdown text
+
+ // Set mul depending on markdownPreference
+ if (Settings::getInstance().getMarkdownPreference() == 2)
+ mul = 2;
+
// Match captured string to corresponding md format
if (exp.cap(1) == "**") // Bold **text**
- htmledSnippet = QString("%1").arg(snippet.mid(2,snippet.length()-4));
+ htmledSnippet = QString("%1").arg(snippet.mid(mul,snippet.length()-2*mul));
else if (exp.cap(4) == "*" && snippet.length() > 2) // Italics *text*
- htmledSnippet = QString("%1").arg(snippet.mid(1,snippet.length()-2));
+ htmledSnippet = QString("%1").arg(snippet.mid(mul/2,snippet.length()-mul));
else if (exp.cap(7) == "_" && snippet.length() > 2) // Italics _text_
- htmledSnippet = QString("%1").arg(snippet.mid(1,snippet.length()-2));
+ htmledSnippet = QString("%1").arg(snippet.mid(mul/2,snippet.length()-mul));
else if (exp.cap(10) == "__"&& snippet.length() > 4) // Italics __text__
- htmledSnippet = QString("%1").arg(snippet.mid(2,snippet.length()-4));
+ htmledSnippet = QString("%1").arg(snippet.mid(mul,snippet.length()-2*mul));
else if (exp.cap(13) == "-" && snippet.length() > 2) // Underline -text-
- htmledSnippet = QString("%1").arg(snippet.mid(1,snippet.length()-2));
+ htmledSnippet = QString("%1").arg(snippet.mid(mul/2,snippet.length()-mul));
else if (exp.cap(16) == "~" && snippet.length() > 2) // Strikethrough ~text~
- htmledSnippet = QString("%1").arg(snippet.mid(1,snippet.length()-2));
+ htmledSnippet = QString("%1").arg(snippet.mid(mul/2,snippet.length()-mul));
else if (exp.cap(19) == "~~" && snippet.length() > 4) // Strikethrough ~~text~~
- htmledSnippet = QString("%1").arg(snippet.mid(2,snippet.length()-4));
+ htmledSnippet = QString("%1").arg(snippet.mid(mul,snippet.length()-2*mul));
else
htmledSnippet = snippet;
out.replace(offset, exp.cap().length(), htmledSnippet);
diff --git a/src/chatlog/createChatMessage b/src/chatlog/createChatMessage
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/persistence/settings.cpp b/src/persistence/settings.cpp
index 0839e4303..72a7a1ecf 100644
--- a/src/persistence/settings.cpp
+++ b/src/persistence/settings.cpp
@@ -177,6 +177,7 @@ void Settings::loadGlobal()
separateWindow = s.value("separateWindow", false).toBool();
dontGroupWindows = s.value("dontGroupWindows", true).toBool();
groupchatPosition = s.value("groupchatPosition", true).toBool();
+ markdownPreference = s.value("markdownPreference", 1).toInt();
s.endGroup();
s.beginGroup("Advanced");
@@ -242,7 +243,7 @@ void Settings::loadGlobal()
camVideoFPS = s.value("camVideoFPS", 0).toUInt();
s.endGroup();
- // Read the embedded DHT bootsrap nodes list if needed
+ // Read the embedded DHT bootstrap nodes list if needed
if (dhtServerList.isEmpty())
{
QSettings rcs(":/conf/settings.ini", QSettings::IniFormat);
@@ -395,6 +396,7 @@ void Settings::saveGlobal()
s.setValue("groupchatPosition", groupchatPosition);
s.setValue("autoSaveEnabled", autoSaveEnabled);
s.setValue("globalAutoAcceptDir", globalAutoAcceptDir);
+ s.setValue("markdownPreference", markdownPreference);
s.endGroup();
s.beginGroup("Advanced");
@@ -1028,6 +1030,23 @@ void Settings::setDateFormat(const QString &format)
dateFormat = format;
}
+int Settings::getMarkdownPreference() const
+{
+ QMutexLocker locker{&bigLock};
+ return markdownPreference;
+}
+
+void Settings::setMarkdownPreference(int newValue)
+{
+ QMutexLocker locker{&bigLock};
+ if (newValue < 0)
+ newValue = 1;
+ else if (newValue > 2)
+ newValue = 2;
+
+ markdownPreference = newValue;
+}
+
QByteArray Settings::getWindowGeometry() const
{
QMutexLocker locker{&bigLock};
diff --git a/src/persistence/settings.h b/src/persistence/settings.h
index 59b8cc87b..32709a20c 100644
--- a/src/persistence/settings.h
+++ b/src/persistence/settings.h
@@ -175,6 +175,9 @@ public:
int getThemeColor() const;
void setThemeColor(const int& value);
+ int getMarkdownPreference() const;
+ void setMarkdownPreference(int newValue);
+
bool isCurstomEmojiFont() const;
void setCurstomEmojiFont(bool value);
@@ -367,6 +370,7 @@ private:
// ChatView
int firstColumnHandlePos;
int secondColumnHandlePosFromRight;
+ int markdownPreference;
QString timestampFormat;
QString dateFormat;
bool statusChangeNotificationEnabled;
diff --git a/src/widget/form/settings/generalform.cpp b/src/widget/form/settings/generalform.cpp
index 851c3057b..fdf7252bf 100644
--- a/src/widget/form/settings/generalform.cpp
+++ b/src/widget/form/settings/generalform.cpp
@@ -82,6 +82,9 @@ static QStringList langs = {"Български",
"Türkçe",
"Українська",
"简体中文"};
+static QStringList mdPrefs = {"None",
+ "Show Characters",
+ "No Characters"};
static QStringList timeFormats = {"hh:mm AP", "hh:mm", "hh:mm:ss AP", "hh:mm:ss"};
// http://doc.qt.io/qt-4.8/qdate.html#fromString
@@ -103,6 +106,10 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) :
bodyUI->transComboBox->insertItem(i, langs[i]);
bodyUI->transComboBox->setCurrentIndex(locales.indexOf(Settings::getInstance().getTranslation()));
+ for (int i = 0; i < mdPrefs.size(); i++)
+ bodyUI->markdownComboBox->insertItem(i, mdPrefs[i]);
+
+ bodyUI->markdownComboBox->setCurrentIndex(Settings::getInstance().getMarkdownPreference());
bodyUI->cbAutorun->setChecked(Settings::getInstance().getAutorun());
bool showSystemTray = Settings::getInstance().getShowSystemTray();
@@ -201,6 +208,7 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) :
connect(bodyUI->showWindow, &QCheckBox::stateChanged, this, &GeneralForm::onShowWindowChanged);
connect(bodyUI->showInFront, &QCheckBox::stateChanged, this, &GeneralForm::onSetShowInFront);
connect(bodyUI->notifySound, &QCheckBox::stateChanged, this, &GeneralForm::onSetNotifySound);
+ connect(bodyUI->markdownComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onMarkdownUpdated()));
connect(bodyUI->groupAlwaysNotify, &QCheckBox::stateChanged, this, &GeneralForm::onSetGroupAlwaysNotify);
connect(bodyUI->autoacceptFiles, &QCheckBox::stateChanged, this, &GeneralForm::onAutoAcceptFileChange);
connect(bodyUI->autoSaveFilesDir, SIGNAL(clicked()), this, SLOT(onAutoSaveDirChange()));
@@ -361,6 +369,11 @@ void GeneralForm::onUseEmoticonsChange()
bodyUI->smileyPackBrowser->setEnabled(bodyUI->useEmoticons->isChecked());
}
+void GeneralForm::onMarkdownUpdated()
+{
+ Settings::getInstance().setMarkdownPreference(bodyUI->markdownComboBox->currentIndex());
+}
+
void GeneralForm::onSetStatusChange()
{
Settings::getInstance().setStatusChangeNotificationEnabled(bodyUI->statusChanges->isChecked());
diff --git a/src/widget/form/settings/generalform.h b/src/widget/form/settings/generalform.h
index 1657eb06c..1c141e51f 100644
--- a/src/widget/form/settings/generalform.h
+++ b/src/widget/form/settings/generalform.h
@@ -53,6 +53,7 @@ private slots:
void onStyleSelected(QString style);
void onTimestampSelected(int index);
void onDateFormatSelected(int index);
+ void onMarkdownUpdated();
void onSetStatusChange();
void onAutoAwayChanged();
void onUseEmoticonsChange();
diff --git a/src/widget/form/settings/generalsettings.ui b/src/widget/form/settings/generalsettings.ui
index cc1e3ab96..41e7418a5 100644
--- a/src/widget/form/settings/generalsettings.ui
+++ b/src/widget/form/settings/generalsettings.ui
@@ -6,7 +6,7 @@
0
0
- 671
+ 1312
1098
@@ -14,7 +14,16 @@
Form
-
+
+ 9
+
+
+ 9
+
+
+ 9
+
+
9
-
@@ -30,8 +39,8 @@
0
0
- 631
- 1141
+ 1280
+ 2394
@@ -227,6 +236,9 @@ instead of closing itself.
Set to 0 to disable
+
+ true
+
min
@@ -236,9 +248,6 @@ instead of closing itself.
2147483647
-
- true
-
@@ -350,6 +359,46 @@ instead of closing itself.
+ -
+
+
-
+
+
+ The translation may not load until qTox restarts.
+
+
+ Markdown:
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ Select Markdown preference
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+
+
-
@@ -432,6 +481,13 @@ will be sent to them when they appear online to you.
+ -
+
+
+
+
+
+