markdown-it: support emoji

This commit is contained in:
Le Tan 2018-05-10 20:08:10 +08:00
parent f2c26d8353
commit 3eb3db874e
11 changed files with 52 additions and 6 deletions

View File

@ -198,6 +198,7 @@ In VNote, almost everything is configurable, such as background color, font, and
- [markdown-it-sup](https://github.com/markdown-it/markdown-it-sup) (MIT License)
- [markdown-it-front-matter](https://github.com/craigdmckenna/markdown-it-front-matter) (MIT License)
- [markdown-it-imsize](https://github.com/tatsy/markdown-it-imsize) (Unknown) (Thanks @Kinka for help)
- [markdown-it-emoji](https://github.com/markdown-it/markdown-it-emoji) (MIT License)
- [mermaid 7.0.0](https://github.com/knsv/mermaid) (MIT License)
- [MathJax](https://www.mathjax.org/) (Apache-2.0)
- [showdown](https://github.com/showdownjs/showdown) (Unknown)

View File

@ -197,6 +197,7 @@ VNote中几乎一切都是可以定制的例如背景颜色、字体以及
- [markdown-it-sup](https://github.com/markdown-it/markdown-it-sup) (MIT License)
- [markdown-it-front-matter](https://github.com/craigdmckenna/markdown-it-front-matter) (MIT License)
- [markdown-it-imsize](https://github.com/tatsy/markdown-it-imsize) (Unknown) (Thanks @Kinka for help)
- [markdown-it-emoji](https://github.com/markdown-it/markdown-it-emoji) (MIT License)
- [mermaid 7.0.0](https://github.com/knsv/mermaid) (MIT License)
- [MathJax](https://www.mathjax.org/) (Apache-2.0)
- [showdown](https://github.com/showdownjs/showdown) (Unknown)

View File

@ -11,6 +11,7 @@ struct MarkdownitOption
true,
false,
false,
false,
false)
{
}
@ -20,13 +21,15 @@ struct MarkdownitOption
bool p_linkify,
bool p_sub,
bool p_sup,
bool p_metadata)
bool p_metadata,
bool p_emoji)
: m_html(p_html),
m_breaks(p_breaks),
m_linkify(p_linkify),
m_sub(p_sub),
m_sup(p_sup),
m_metadata(p_metadata)
m_metadata(p_metadata),
m_emoji(p_emoji)
{
}
@ -57,6 +60,10 @@ struct MarkdownitOption
conf << "metadata";
}
if (m_emoji) {
conf << "emoji";
}
return conf;
}
@ -67,7 +74,8 @@ struct MarkdownitOption
testOption(p_conf, "linkify"),
testOption(p_conf, "sub"),
testOption(p_conf, "sup"),
testOption(p_conf, "metadata"));
testOption(p_conf, "metadata"),
testOption(p_conf, "emoji"));
}
bool operator==(const MarkdownitOption &p_opt) const
@ -77,7 +85,8 @@ struct MarkdownitOption
&& m_linkify == p_opt.m_linkify
&& m_sub == p_opt.m_sub
&& m_sup == p_opt.m_sup
&& m_metadata == p_opt.m_metadata;
&& m_metadata == p_opt.m_metadata
&& m_emoji == p_opt.m_emoji;
}
// Eanble HTML tags in source.
@ -98,6 +107,9 @@ struct MarkdownitOption
// Enable metadata in YML format.
bool m_metadata;
// Enable emoji and emoticon.
bool m_emoji;
private:
static bool testOption(const QStringList &p_conf, const QString &p_opt)
{

View File

@ -94,6 +94,10 @@ if (VMarkdownitOption.metadata) {
mdit = mdit.use(window.markdownitFrontMatter, function(text){});
}
if (VMarkdownitOption.emoji) {
mdit = mdit.use(window.markdownitEmoji);
}
mdit = mdit.use(window.markdownitFootnote);
mdit = mdit.use(window["markdown-it-imsize.js"]);

View File

@ -31,3 +31,7 @@ Craig McKenna
# [markdown-it-imsize](https://github.com/tatsy/markdown-it-imsize)
v2.0.1
Tatsuya Yatagawa
# [markdown-it-emoji](https://github.com/markdown-it/markdown-it-emoji)
v1.4.0
Vitaly Puzrin

File diff suppressed because one or more lines are too long

View File

@ -673,20 +673,26 @@ QString VUtils::generateHtmlTemplate(const QString &p_template,
extraFile += "<script src=\"qrc" + VNote::c_markdownitFrontMatterExtraFile + "\"></script>\n";
}
if (opt.m_emoji) {
extraFile += "<script src=\"qrc" + VNote::c_markdownitEmojiExtraFile + "\"></script>\n";
}
QString optJs = QString("<script>var VMarkdownitOption = {"
"html: %1,\n"
"breaks: %2,\n"
"linkify: %3,\n"
"sub: %4,\n"
"sup: %5,\n"
"metadata: %6 };\n"
"metadata: %6,\n"
"emoji: %7 };\n"
"</script>\n")
.arg(opt.m_html ? QStringLiteral("true") : QStringLiteral("false"))
.arg(opt.m_breaks ? QStringLiteral("true") : QStringLiteral("false"))
.arg(opt.m_linkify ? QStringLiteral("true") : QStringLiteral("false"))
.arg(opt.m_sub ? QStringLiteral("true") : QStringLiteral("false"))
.arg(opt.m_sup ? QStringLiteral("true") : QStringLiteral("false"))
.arg(opt.m_metadata ? QStringLiteral("true") : QStringLiteral("false"));
.arg(opt.m_metadata ? QStringLiteral("true") : QStringLiteral("false"))
.arg(opt.m_emoji ? QStringLiteral("true") : QStringLiteral("false"));
extraFile += optJs;
break;
}

View File

@ -1617,12 +1617,24 @@ void VMainWindow::initMarkdownitOptionMenu(QMenu *p_menu)
g_config->setMarkdownitOption(opt);
});
QAction *emojiAct = new QAction(tr("Emoji"), this);
emojiAct->setToolTip(tr("Enable emoji and emoticon"));
emojiAct->setCheckable(true);
emojiAct->setChecked(opt.m_emoji);
connect(emojiAct, &QAction::triggered,
this, [this](bool p_checked) {
MarkdownitOption opt = g_config->getMarkdownitOption();
opt.m_emoji = p_checked;
g_config->setMarkdownitOption(opt);
});
optMenu->addAction(htmlAct);
optMenu->addAction(breaksAct);
optMenu->addAction(linkifyAct);
optMenu->addAction(supAct);
optMenu->addAction(subAct);
optMenu->addAction(metadataAct);
optMenu->addAction(emojiAct);
}
void VMainWindow::initRenderBackgroundMenu(QMenu *menu)

View File

@ -41,6 +41,7 @@ const QString VNote::c_markdownitSupExtraFile = ":/utils/markdown-it/markdown-it
const QString VNote::c_markdownitFootnoteExtraFile = ":/utils/markdown-it/markdown-it-footnote.min.js";
const QString VNote::c_markdownitFrontMatterExtraFile = ":/utils/markdown-it/markdown-it-front-matter.js";
const QString VNote::c_markdownitImsizeExtraFile = ":/utils/markdown-it/markdown-it-imsize.min.js";
const QString VNote::c_markdownitEmojiExtraFile = ":/utils/markdown-it/markdown-it-emoji.min.js";
const QString VNote::c_showdownJsFile = ":/resources/showdown.js";
const QString VNote::c_showdownExtraFile = ":/utils/showdown/showdown.min.js";

View File

@ -52,6 +52,7 @@ public:
static const QString c_markdownitFootnoteExtraFile;
static const QString c_markdownitFrontMatterExtraFile;
static const QString c_markdownitImsizeExtraFile;
static const QString c_markdownitEmojiExtraFile;
// Showdown
static const QString c_showdownJsFile;

View File

@ -215,5 +215,6 @@
<file>utils/dom-to-image/dom-to-image.js</file>
<file>utils/markdown-it/markdown-it-front-matter.js</file>
<file>utils/markdown-it/markdown-it-imsize.min.js</file>
<file>utils/markdown-it/markdown-it-emoji.min.js</file>
</qresource>
</RCC>