mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
editor: support prepend_dot_in_relative_path config
This commit is contained in:
parent
369ccb34e8
commit
64960cc3c5
@ -545,3 +545,6 @@ ParseAndPaste=P
|
|||||||
[markdown]
|
[markdown]
|
||||||
; Enable WaveDrom
|
; Enable WaveDrom
|
||||||
enable_wavedrom=false
|
enable_wavedrom=false
|
||||||
|
|
||||||
|
; Prepend a dot in relative path of images and attachments
|
||||||
|
prepend_dot_in_relative_path=false
|
||||||
|
@ -1885,3 +1885,18 @@ QString VUtils::escapeHtml(QString p_text)
|
|||||||
p_text.replace(">", ">").replace("<", "<").replace("&", "&");
|
p_text.replace(">", ">").replace("<", "<").replace("&", "&");
|
||||||
return p_text;
|
return p_text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString VUtils::encodeSpacesInPath(const QString &p_path)
|
||||||
|
{
|
||||||
|
QString tmp(p_path);
|
||||||
|
tmp.replace(' ', "%20");
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VUtils::prependDotIfRelative(QString &p_path)
|
||||||
|
{
|
||||||
|
if (QFileInfo(p_path).isRelative()
|
||||||
|
&& !p_path.startsWith("../") && !p_path.startsWith("./")) {
|
||||||
|
p_path.prepend("./");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -394,6 +394,10 @@ public:
|
|||||||
|
|
||||||
static QString escapeHtml(QString p_text);
|
static QString escapeHtml(QString p_text);
|
||||||
|
|
||||||
|
static QString encodeSpacesInPath(const QString &p_path);
|
||||||
|
|
||||||
|
static void prependDotIfRelative(QString &p_path);
|
||||||
|
|
||||||
// Regular expression for image link.
|
// Regular expression for image link.
|
||||||
// 
|
// 
|
||||||
// Captured texts (need to be trimmed):
|
// Captured texts (need to be trimmed):
|
||||||
|
@ -377,6 +377,8 @@ void VConfigManager::initMarkdownConfigs()
|
|||||||
{
|
{
|
||||||
const QString section("markdown");
|
const QString section("markdown");
|
||||||
m_enableWavedrom = getConfigFromSettings(section, "enable_wavedrom").toBool();
|
m_enableWavedrom = getConfigFromSettings(section, "enable_wavedrom").toBool();
|
||||||
|
|
||||||
|
m_prependDotInRelativePath = getConfigFromSettings(section, "prepend_dot_in_relative_path").toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VConfigManager::initSettings()
|
void VConfigManager::initSettings()
|
||||||
|
@ -625,6 +625,9 @@ public:
|
|||||||
QString getImageBrowsePath() const;
|
QString getImageBrowsePath() const;
|
||||||
void setImageBrowsePath(const QString &p_path);
|
void setImageBrowsePath(const QString &p_path);
|
||||||
|
|
||||||
|
bool getPrependDotInRelativePath() const;
|
||||||
|
void setPrependDotInRelativePath(bool p_enabled);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initEditorConfigs();
|
void initEditorConfigs();
|
||||||
|
|
||||||
@ -1106,6 +1109,9 @@ private:
|
|||||||
// Editor font family to override the value set by the style.
|
// Editor font family to override the value set by the style.
|
||||||
QString m_editorFontFamily;
|
QString m_editorFontFamily;
|
||||||
|
|
||||||
|
// Whether prepend a dot in the relative path of images and attachments.
|
||||||
|
bool m_prependDotInRelativePath;
|
||||||
|
|
||||||
// The name of the config file in each directory.
|
// The name of the config file in each directory.
|
||||||
static const QString c_dirConfigFile;
|
static const QString c_dirConfigFile;
|
||||||
|
|
||||||
@ -2877,4 +2883,19 @@ inline void VConfigManager::setImageBrowsePath(const QString &p_path)
|
|||||||
{
|
{
|
||||||
setConfigToSessionSettings("global", "image_browse_path", p_path);
|
setConfigToSessionSettings("global", "image_browse_path", p_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool VConfigManager::getPrependDotInRelativePath() const
|
||||||
|
{
|
||||||
|
return m_prependDotInRelativePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void VConfigManager::setPrependDotInRelativePath(bool p_enabled)
|
||||||
|
{
|
||||||
|
if (m_prependDotInRelativePath == p_enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_prependDotInRelativePath = p_enabled;
|
||||||
|
setConfigToSettings("markdown", "prepend_dot_in_relative_path", m_prependDotInRelativePath);
|
||||||
|
}
|
||||||
#endif // VCONFIGMANAGER_H
|
#endif // VCONFIGMANAGER_H
|
||||||
|
@ -114,6 +114,11 @@ void VMdEditOperations::insertImageFromQImage(const QString &p_title,
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString url = QDir::fromNativeSeparators(QString("%1/%2").arg(p_folderInLink).arg(fileName));
|
QString url = QDir::fromNativeSeparators(QString("%1/%2").arg(p_folderInLink).arg(fileName));
|
||||||
|
url = VUtils::encodeSpacesInPath(url);
|
||||||
|
if (g_config->getPrependDotInRelativePath()) {
|
||||||
|
VUtils::prependDotIfRelative(url);
|
||||||
|
}
|
||||||
|
|
||||||
insertText(imageLink(p_title, url, p_width, p_height));
|
insertText(imageLink(p_title, url, p_width, p_height));
|
||||||
|
|
||||||
qDebug() << "insert image" << p_title << filePath;
|
qDebug() << "insert image" << p_title << filePath;
|
||||||
@ -195,6 +200,11 @@ void VMdEditOperations::insertImageFromPath(const QString &p_title,
|
|||||||
}
|
}
|
||||||
|
|
||||||
p_urlInLink = QDir::fromNativeSeparators(QString("%1/%2").arg(p_folderInLink).arg(fileName));
|
p_urlInLink = QDir::fromNativeSeparators(QString("%1/%2").arg(p_folderInLink).arg(fileName));
|
||||||
|
p_urlInLink = VUtils::encodeSpacesInPath(p_urlInLink);
|
||||||
|
if (g_config->getPrependDotInRelativePath()) {
|
||||||
|
VUtils::prependDotIfRelative(p_urlInLink);
|
||||||
|
}
|
||||||
|
|
||||||
p_destImagePath = filePath;
|
p_destImagePath = filePath;
|
||||||
|
|
||||||
if (p_insertText) {
|
if (p_insertText) {
|
||||||
|
@ -1947,6 +1947,9 @@ bool VMdEditor::processUrlFromMimeData(const QMimeData *p_source)
|
|||||||
QDir dir(m_file->fetchBasePath());
|
QDir dir(m_file->fetchBasePath());
|
||||||
ut = dir.relativeFilePath(url.toLocalFile());
|
ut = dir.relativeFilePath(url.toLocalFile());
|
||||||
ut = QUrl(ut).toString(QUrl::EncodeSpaces);
|
ut = QUrl(ut).toString(QUrl::EncodeSpaces);
|
||||||
|
if (g_config->getPrependDotInRelativePath()) {
|
||||||
|
VUtils::prependDotIfRelative(ut);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ut = url.isLocalFile() ? url.toString(QUrl::EncodeSpaces)
|
ut = url.isLocalFile() ? url.toString(QUrl::EncodeSpaces)
|
||||||
: url.toString();
|
: url.toString();
|
||||||
@ -2005,6 +2008,9 @@ bool VMdEditor::processUrlFromMimeData(const QMimeData *p_source)
|
|||||||
QDir dir(m_file->fetchBasePath());
|
QDir dir(m_file->fetchBasePath());
|
||||||
ut = dir.relativeFilePath(url.toLocalFile());
|
ut = dir.relativeFilePath(url.toLocalFile());
|
||||||
ut = QUrl(ut).toString(QUrl::EncodeSpaces);
|
ut = QUrl(ut).toString(QUrl::EncodeSpaces);
|
||||||
|
if (g_config->getPrependDotInRelativePath()) {
|
||||||
|
VUtils::prependDotIfRelative(ut);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ut = url.isLocalFile() ? url.toString(QUrl::EncodeSpaces)
|
ut = url.isLocalFile() ? url.toString(QUrl::EncodeSpaces)
|
||||||
: url.toString();
|
: url.toString();
|
||||||
@ -2214,6 +2220,9 @@ void VMdEditor::handleLinkToAttachmentAction(QAction *p_act)
|
|||||||
QDir dir(note->fetchBasePath());
|
QDir dir(note->fetchBasePath());
|
||||||
QString ut = dir.relativeFilePath(filePath);
|
QString ut = dir.relativeFilePath(filePath);
|
||||||
ut = QUrl(ut).toString(QUrl::EncodeSpaces);
|
ut = QUrl(ut).toString(QUrl::EncodeSpaces);
|
||||||
|
if (g_config->getPrependDotInRelativePath()) {
|
||||||
|
VUtils::prependDotIfRelative(ut);
|
||||||
|
}
|
||||||
|
|
||||||
VInsertLinkDialog ld(QObject::tr("Insert Link"),
|
VInsertLinkDialog ld(QObject::tr("Insert Link"),
|
||||||
"",
|
"",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user