mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
export: fix wkhtmltopdf table-of-contents in Chinese
This commit is contained in:
parent
54576543e9
commit
ff7cf0f24e
@ -17,6 +17,7 @@
|
|||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
#include <utils/webutils.h>
|
#include <utils/webutils.h>
|
||||||
#include <utils/processutils.h>
|
#include <utils/processutils.h>
|
||||||
|
#include <utils/htmlutils.h>
|
||||||
#include <core/file.h>
|
#include <core/file.h>
|
||||||
|
|
||||||
using namespace vnotex;
|
using namespace vnotex;
|
||||||
@ -348,7 +349,7 @@ void WebViewExporter::prepareWkhtmltopdfArguments(const ExportPdfOption &p_pdfOp
|
|||||||
if (p_pdfOption.m_addTableOfContents) {
|
if (p_pdfOption.m_addTableOfContents) {
|
||||||
m_wkhtmltopdfArgs << "toc";
|
m_wkhtmltopdfArgs << "toc";
|
||||||
m_wkhtmltopdfArgs << "--toc-text-size-shrink" << "1.0";
|
m_wkhtmltopdfArgs << "--toc-text-size-shrink" << "1.0";
|
||||||
m_wkhtmltopdfArgs << "--toc-header-text" << tr("Table of Contents");
|
m_wkhtmltopdfArgs << "--toc-header-text" << HtmlUtils::unicodeEncode(tr("Table of Contents"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,3 +16,17 @@ QString HtmlUtils::escapeHtml(QString p_text)
|
|||||||
p_text.replace(">", ">").replace("<", "<").replace("&", "&");
|
p_text.replace(">", ">").replace("<", "<").replace("&", "&");
|
||||||
return p_text;
|
return p_text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString HtmlUtils::unicodeEncode(const QString &p_text)
|
||||||
|
{
|
||||||
|
QString encodedStr;
|
||||||
|
for (const auto ch : p_text) {
|
||||||
|
if (ch.unicode() > 255) {
|
||||||
|
encodedStr += QString("&#%1;").arg(static_cast<int>(ch.unicode()));
|
||||||
|
} else {
|
||||||
|
encodedStr += ch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return encodedStr;
|
||||||
|
}
|
||||||
|
@ -13,6 +13,8 @@ namespace vnotex
|
|||||||
static bool hasOnlyImgTag(const QString &p_html);
|
static bool hasOnlyImgTag(const QString &p_html);
|
||||||
|
|
||||||
static QString escapeHtml(QString p_text);
|
static QString escapeHtml(QString p_text);
|
||||||
|
|
||||||
|
static QString unicodeEncode(const QString &p_text);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,51 +300,6 @@ QToolBar *ToolBarHelper::setupSettingsToolBar(MainWindow *p_win, QToolBar *p_too
|
|||||||
return tb;
|
return tb;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolBarHelper::setupConfigurationMenu(QMenu *p_menu)
|
|
||||||
{
|
|
||||||
auto menu = p_menu->addMenu(MainWindow::tr("Configuration"));
|
|
||||||
|
|
||||||
menu->addAction(MainWindow::tr("Edit User Configuration File"),
|
|
||||||
menu,
|
|
||||||
[]() {
|
|
||||||
auto file = ConfigMgr::getInst().getConfigFilePath(ConfigMgr::Source::User);
|
|
||||||
auto paras = QSharedPointer<FileOpenParameters>::create();
|
|
||||||
paras->m_sessionEnabled = false;
|
|
||||||
emit VNoteX::getInst().openFileRequested(file, paras);
|
|
||||||
});
|
|
||||||
|
|
||||||
menu->addAction(MainWindow::tr("Open User Configuration Folder"),
|
|
||||||
menu,
|
|
||||||
[]() {
|
|
||||||
auto folderPath = ConfigMgr::getInst().getUserFolder();
|
|
||||||
WidgetUtils::openUrlByDesktop(QUrl::fromLocalFile(folderPath));
|
|
||||||
});
|
|
||||||
|
|
||||||
menu->addAction(MainWindow::tr("Open Default Configuration Folder"),
|
|
||||||
menu,
|
|
||||||
[]() {
|
|
||||||
auto folderPath = ConfigMgr::getInst().getAppFolder();
|
|
||||||
WidgetUtils::openUrlByDesktop(QUrl::fromLocalFile(folderPath));
|
|
||||||
});
|
|
||||||
|
|
||||||
menu->addSeparator();
|
|
||||||
|
|
||||||
auto act = menu->addAction(MainWindow::tr("Edit Markdown User Styles"),
|
|
||||||
menu,
|
|
||||||
[]() {
|
|
||||||
const auto file = ConfigMgr::getInst().getUserMarkdownUserStyleFile();
|
|
||||||
auto paras = QSharedPointer<FileOpenParameters>::create();
|
|
||||||
paras->m_sessionEnabled = false;
|
|
||||||
paras->m_hooks[FileOpenParameters::PostSave] = []() {
|
|
||||||
qDebug() << "post save";
|
|
||||||
const auto &markdownConfig = ConfigMgr::getInst().getEditorConfig().getMarkdownEditorConfig();
|
|
||||||
HtmlTemplateHelper::updateMarkdownViewerTemplate(markdownConfig, true);
|
|
||||||
};
|
|
||||||
emit VNoteX::getInst().openFileRequested(file, paras);
|
|
||||||
});
|
|
||||||
act->setStatusTip(MainWindow::tr("Edit the user styles of Markdown editor read mode"));
|
|
||||||
}
|
|
||||||
|
|
||||||
static const QString c_fgPalette = QStringLiteral("widgets#toolbar#icon#fg");
|
static const QString c_fgPalette = QStringLiteral("widgets#toolbar#icon#fg");
|
||||||
static const QString c_disabledPalette = QStringLiteral("widgets#toolbar#icon#disabled#fg");
|
static const QString c_disabledPalette = QStringLiteral("widgets#toolbar#icon#disabled#fg");
|
||||||
static const QString c_dangerousPalette = QStringLiteral("widgets#toolbar#icon#danger#fg");
|
static const QString c_dangerousPalette = QStringLiteral("widgets#toolbar#icon#danger#fg");
|
||||||
@ -543,7 +498,47 @@ void ToolBarHelper::setupSettingsButton(MainWindow *p_win, QToolBar *p_toolBar)
|
|||||||
|
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
|
|
||||||
setupConfigurationMenu(menu);
|
menu->addAction(MainWindow::tr("Edit User Configuration File"),
|
||||||
|
menu,
|
||||||
|
[]() {
|
||||||
|
auto file = ConfigMgr::getInst().getConfigFilePath(ConfigMgr::Source::User);
|
||||||
|
auto paras = QSharedPointer<FileOpenParameters>::create();
|
||||||
|
paras->m_sessionEnabled = false;
|
||||||
|
emit VNoteX::getInst().openFileRequested(file, paras);
|
||||||
|
});
|
||||||
|
|
||||||
|
menu->addAction(MainWindow::tr("Open User Configuration Folder"),
|
||||||
|
menu,
|
||||||
|
[]() {
|
||||||
|
auto folderPath = ConfigMgr::getInst().getUserFolder();
|
||||||
|
WidgetUtils::openUrlByDesktop(QUrl::fromLocalFile(folderPath));
|
||||||
|
});
|
||||||
|
|
||||||
|
menu->addAction(MainWindow::tr("Open Default Configuration Folder"),
|
||||||
|
menu,
|
||||||
|
[]() {
|
||||||
|
auto folderPath = ConfigMgr::getInst().getAppFolder();
|
||||||
|
WidgetUtils::openUrlByDesktop(QUrl::fromLocalFile(folderPath));
|
||||||
|
});
|
||||||
|
|
||||||
|
menu->addSeparator();
|
||||||
|
|
||||||
|
{
|
||||||
|
auto act = menu->addAction(MainWindow::tr("Edit Markdown User Styles"),
|
||||||
|
menu,
|
||||||
|
[]() {
|
||||||
|
const auto file = ConfigMgr::getInst().getUserMarkdownUserStyleFile();
|
||||||
|
auto paras = QSharedPointer<FileOpenParameters>::create();
|
||||||
|
paras->m_sessionEnabled = false;
|
||||||
|
paras->m_hooks[FileOpenParameters::PostSave] = []() {
|
||||||
|
qDebug() << "post save";
|
||||||
|
const auto &markdownConfig = ConfigMgr::getInst().getEditorConfig().getMarkdownEditorConfig();
|
||||||
|
HtmlTemplateHelper::updateMarkdownViewerTemplate(markdownConfig, true);
|
||||||
|
};
|
||||||
|
emit VNoteX::getInst().openFileRequested(file, paras);
|
||||||
|
});
|
||||||
|
act->setStatusTip(MainWindow::tr("Edit the user styles of Markdown editor read mode"));
|
||||||
|
}
|
||||||
|
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
|
|
||||||
@ -552,27 +547,12 @@ void ToolBarHelper::setupSettingsButton(MainWindow *p_win, QToolBar *p_toolBar)
|
|||||||
[p_win]() {
|
[p_win]() {
|
||||||
p_win->resetStateAndGeometry();
|
p_win->resetStateAndGeometry();
|
||||||
});
|
});
|
||||||
|
|
||||||
menu->addSeparator();
|
|
||||||
|
|
||||||
menu->addAction(MainWindow::tr("Restart"),
|
|
||||||
menu,
|
|
||||||
[p_win]() {
|
|
||||||
p_win->restart();
|
|
||||||
});
|
|
||||||
|
|
||||||
auto quitAct = menu->addAction(MainWindow::tr("Quit"),
|
|
||||||
menu,
|
|
||||||
[p_win]() {
|
|
||||||
p_win->quitApp();
|
|
||||||
});
|
|
||||||
quitAct->setMenuRole(QAction::QuitRole);
|
|
||||||
WidgetUtils::addActionShortcut(quitAct,
|
|
||||||
coreConfig.getShortcut(CoreConfig::Shortcut::Quit));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolBarHelper::setupMenuButton(MainWindow *p_win, QToolBar *p_toolBar)
|
void ToolBarHelper::setupMenuButton(MainWindow *p_win, QToolBar *p_toolBar)
|
||||||
{
|
{
|
||||||
|
const auto &coreConfig = ConfigMgr::getInst().getCoreConfig();
|
||||||
|
|
||||||
auto act = p_toolBar->addAction(generateIcon("menu.svg"), MainWindow::tr("Menu"));
|
auto act = p_toolBar->addAction(generateIcon("menu.svg"), MainWindow::tr("Menu"));
|
||||||
auto btn = dynamic_cast<QToolButton *>(p_toolBar->widgetForAction(act));
|
auto btn = dynamic_cast<QToolButton *>(p_toolBar->widgetForAction(act));
|
||||||
Q_ASSERT(btn);
|
Q_ASSERT(btn);
|
||||||
@ -637,13 +617,6 @@ void ToolBarHelper::setupMenuButton(MainWindow *p_win, QToolBar *p_toolBar)
|
|||||||
|
|
||||||
helpMenu->addSeparator();
|
helpMenu->addSeparator();
|
||||||
|
|
||||||
helpMenu->addAction(MainWindow::tr("Check for Updates"),
|
|
||||||
helpMenu,
|
|
||||||
[p_win]() {
|
|
||||||
Updater updater(p_win);
|
|
||||||
updater.exec();
|
|
||||||
});
|
|
||||||
|
|
||||||
helpMenu->addAction(MainWindow::tr("Contributors"),
|
helpMenu->addAction(MainWindow::tr("Contributors"),
|
||||||
helpMenu,
|
helpMenu,
|
||||||
[]() {
|
[]() {
|
||||||
@ -664,4 +637,29 @@ void ToolBarHelper::setupMenuButton(MainWindow *p_win, QToolBar *p_toolBar)
|
|||||||
MainWindow::connect(aboutQtAct, &QAction::triggered,
|
MainWindow::connect(aboutQtAct, &QAction::triggered,
|
||||||
qApp, &QApplication::aboutQt);
|
qApp, &QApplication::aboutQt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
menu->addSeparator();
|
||||||
|
|
||||||
|
menu->addAction(MainWindow::tr("Check for Updates"),
|
||||||
|
menu,
|
||||||
|
[p_win]() {
|
||||||
|
Updater updater(p_win);
|
||||||
|
updater.exec();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
menu->addAction(MainWindow::tr("Restart"),
|
||||||
|
menu,
|
||||||
|
[p_win]() {
|
||||||
|
p_win->restart();
|
||||||
|
});
|
||||||
|
|
||||||
|
auto quitAct = menu->addAction(MainWindow::tr("Quit"),
|
||||||
|
menu,
|
||||||
|
[p_win]() {
|
||||||
|
p_win->quitApp();
|
||||||
|
});
|
||||||
|
quitAct->setMenuRole(QAction::QuitRole);
|
||||||
|
WidgetUtils::addActionShortcut(quitAct,
|
||||||
|
coreConfig.getShortcut(CoreConfig::Shortcut::Quit));
|
||||||
}
|
}
|
||||||
|
@ -37,8 +37,6 @@ namespace vnotex
|
|||||||
|
|
||||||
static void updateQuickAccessMenu(QMenu *p_menu);
|
static void updateQuickAccessMenu(QMenu *p_menu);
|
||||||
|
|
||||||
static void setupConfigurationMenu(QMenu *p_menu);
|
|
||||||
|
|
||||||
static void setupExpandButton(MainWindow *p_win, QToolBar *p_toolBar);
|
static void setupExpandButton(MainWindow *p_win, QToolBar *p_toolBar);
|
||||||
|
|
||||||
static void setupSettingsButton(MainWindow *p_win, QToolBar *p_toolBar);
|
static void setupSettingsButton(MainWindow *p_win, QToolBar *p_toolBar);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user