mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 05:49:53 +08:00
support font family style in markdown highlighting
Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
parent
88633d22da
commit
eb5b6a6276
@ -1,6 +1,9 @@
|
|||||||
# This is the default markdown styles used for Peg-Markdown-Highlight
|
# This is the default markdown styles used for Peg-Markdown-Highlight
|
||||||
# Created by Le Tan (tamlokveer@gmail.com)
|
# Created by Le Tan (tamlokveer@gmail.com)
|
||||||
|
|
||||||
|
editor
|
||||||
|
font-family: Georgia, Palatino, Arial, serif
|
||||||
|
|
||||||
H1
|
H1
|
||||||
foreground: 111111
|
foreground: 111111
|
||||||
font-style: bold
|
font-style: bold
|
||||||
@ -59,6 +62,7 @@ foreground: b58900
|
|||||||
|
|
||||||
CODE
|
CODE
|
||||||
foreground: af5f00
|
foreground: af5f00
|
||||||
|
font-family: Consolas, Monaco, Andale Mono, monospace
|
||||||
|
|
||||||
EMPH
|
EMPH
|
||||||
font-style: italic
|
font-style: italic
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
#include "vstyleparser.h"
|
#include "vstyleparser.h"
|
||||||
|
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
|
#include <QFontDatabase>
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QBrush>
|
#include <QBrush>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
VStyleParser::VStyleParser()
|
VStyleParser::VStyleParser()
|
||||||
{
|
{
|
||||||
@ -69,7 +71,13 @@ QTextCharFormat VStyleParser::QTextCharFormatFromAttrs(pmh_style_attribute *attr
|
|||||||
}
|
}
|
||||||
|
|
||||||
case pmh_attr_type_font_family:
|
case pmh_attr_type_font_family:
|
||||||
// TODO
|
{
|
||||||
|
QString familyList(attrs->value->font_family);
|
||||||
|
QString finalFamily = filterAvailableFontFamily(familyList);
|
||||||
|
if (!finalFamily.isEmpty()) {
|
||||||
|
format.setFontFamily(finalFamily);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case pmh_attr_type_font_style:
|
case pmh_attr_type_font_style:
|
||||||
@ -172,3 +180,25 @@ QPalette VStyleParser::fetchMarkdownEditorStyles(const QPalette &basePalette) co
|
|||||||
|
|
||||||
return palette;
|
return palette;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @familyList is a comma separated string
|
||||||
|
QString VStyleParser::filterAvailableFontFamily(const QString &familyList) const
|
||||||
|
{
|
||||||
|
QStringList families = familyList.split(',', QString::SkipEmptyParts);
|
||||||
|
QStringList availFamilies = QFontDatabase().families();
|
||||||
|
|
||||||
|
qDebug() << "family:" << familyList;
|
||||||
|
for (int i = 0; i < families.size(); ++i) {
|
||||||
|
QString family = families[i].trimmed().toLower();
|
||||||
|
for (int j = 0; j < availFamilies.size(); ++j) {
|
||||||
|
QString availFamily = availFamilies[j];
|
||||||
|
availFamily.remove(QRegExp("\\[.*\\]"));
|
||||||
|
if (family == availFamily.trimmed().toLower()) {
|
||||||
|
qDebug() << "matched family:" << availFamilies[j];
|
||||||
|
return availFamilies[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
#include <QString>
|
||||||
#include "hgmarkdownhighlighter.h"
|
#include "hgmarkdownhighlighter.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -28,6 +29,7 @@ private:
|
|||||||
QBrush QBrushFromPmhAttr(pmh_attr_argb_color *attr) const;
|
QBrush QBrushFromPmhAttr(pmh_attr_argb_color *attr) const;
|
||||||
QTextCharFormat QTextCharFormatFromAttrs(pmh_style_attribute *attrs,
|
QTextCharFormat QTextCharFormatFromAttrs(pmh_style_attribute *attrs,
|
||||||
const QFont &baseFont) const;
|
const QFont &baseFont) const;
|
||||||
|
QString filterAvailableFontFamily(const QString &familyList) const;
|
||||||
pmh_style_collection *markdownStyles;
|
pmh_style_collection *markdownStyles;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user