mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 05:49:53 +08:00
code block highlight via Pygment
This commit is contained in:
parent
d8e7583179
commit
b020629b9f
@ -1019,11 +1019,12 @@ VNoteManagementTab::VNoteManagementTab(QWidget *p_parent)
|
||||
m_singleClickOpen = new QCheckBox(tr("Single click to open a note in current tab"), this);
|
||||
m_singleClickOpen->setToolTip(tr("Single click a note in the notes list to open it in current tab, "
|
||||
"double click to open it in a new tab"));
|
||||
m_singleClickOpen->setVisible(false);
|
||||
|
||||
QFormLayout *noteLayout = new QFormLayout();
|
||||
noteLayout->addRow(imageFolderLayout);
|
||||
noteLayout->addRow(attachmentFolderLayout);
|
||||
noteLayout->addRow(m_singleClickOpen);
|
||||
// noteLayout->addRow(m_singleClickOpen);
|
||||
m_noteBox->setLayout(noteLayout);
|
||||
|
||||
// External File.
|
||||
|
@ -146,39 +146,83 @@ font-family: YaHei Consolas Hybrid, Consolas, Monaco, Andale Mono, Monospace, Co
|
||||
# [VNote] Codeblock sylte from HighlightJS (bold, italic, underlined, strikeout, color)
|
||||
# The last occurence of the same attribute takes effect
|
||||
# Could specify multiple attribute in one line
|
||||
hljs-comment: af8787
|
||||
hljs-quote: af8787
|
||||
hljs-doctag: ccb24c
|
||||
hljs-keyword: ccb24c
|
||||
hljs-formula: ccb24c
|
||||
hljs-section: e37c84
|
||||
hljs-name: e37c84
|
||||
hljs-selector-tag: e37c84
|
||||
hljs-deletion: e37c84
|
||||
hljs-subst: e37c84
|
||||
hljs-literal: 56b6c2
|
||||
hljs-string: f06292
|
||||
hljs-regexp: f06292
|
||||
hljs-addition: f06292
|
||||
hljs-attribute: f06292
|
||||
hljs-meta-string: f06292
|
||||
hljs-built_in: 80cbc4
|
||||
hljs-attr: ce93db
|
||||
hljs-variable: ce93db
|
||||
hljs-template-variable: ce93db
|
||||
hljs-type: ce93db
|
||||
hljs-selector-class: ce93db
|
||||
hljs-selector-attr: ce93db
|
||||
hljs-selector-pseudo: ce93db
|
||||
hljs-number: ce93db
|
||||
hljs-symbol: 84c0f2
|
||||
hljs-link: underlined, 84c0f2
|
||||
hljs-bullet: 84c0f2
|
||||
hljs-meta: 84c0f2
|
||||
hljs-selector-id: 84c0f2
|
||||
hljs-title: bold, 84c0f2
|
||||
hljs-emphasis: italic
|
||||
hljs-strong: bold
|
||||
hll: 404040
|
||||
c: 999999
|
||||
err: a61717
|
||||
esc: d0d0d0
|
||||
g: d0d0d0
|
||||
k: bold, 6ab825
|
||||
l: d0d0d0
|
||||
n: d0d0d0
|
||||
o: d0d0d0
|
||||
x: d0d0d0
|
||||
p: d0d0d0
|
||||
ch: italic, 999999
|
||||
cm: italic, 999999
|
||||
cp: bold, cd2828
|
||||
cpf: italic, 999999
|
||||
c1: italic, 999999
|
||||
cs: bold, e50808
|
||||
gd: d22323
|
||||
ge: italic, d0d0d0
|
||||
gr: d22323
|
||||
gh: bold, ffffff
|
||||
gi: 589819
|
||||
go: cccccc
|
||||
gp: aaaaaa
|
||||
gs: bold, d0d0d0
|
||||
gu: underlined, ffffff
|
||||
gt: d22323
|
||||
kc: bold, 6ab825
|
||||
kd: bold, 6ab825
|
||||
kn: bold, 6ab825
|
||||
kp: 6ab825
|
||||
kr: bold, 6ab825
|
||||
kt: bold, 6ab825
|
||||
ld: d0d0d0
|
||||
m: 3677a9
|
||||
s: ed9d13
|
||||
na: bbbbbb
|
||||
nb: 24909d
|
||||
nc: underlined, 447fcf
|
||||
no: 40ffff
|
||||
nd: ffa500
|
||||
ni: d0d0d0
|
||||
ne: bbbbbb
|
||||
nf: 447fcf
|
||||
nl: d0d0d0
|
||||
nn: underlined, 447fcf
|
||||
nx: d0d0d0
|
||||
py: d0d0d0
|
||||
nt: bold, 6ab825
|
||||
nv: 40ffff
|
||||
ow: bold, 6ab825
|
||||
w: 666666
|
||||
mb: 3677a9
|
||||
mf: 3677a9
|
||||
mh: 3677a9
|
||||
mi: 3677a9
|
||||
mo: 3677a9
|
||||
sa: ed9d13
|
||||
sb: ed9d13
|
||||
sc: ed9d13
|
||||
dl: ed9d13
|
||||
sd: ed9d13
|
||||
s2: ed9d13
|
||||
se: ed9d13
|
||||
sh: ed9d13
|
||||
si: ed9d13
|
||||
sx: ffa500
|
||||
sr: ed9d13
|
||||
s1: ed9d13
|
||||
ss: ed9d13
|
||||
bp: 24909d
|
||||
fm: 447fcf
|
||||
vc: 40ffff
|
||||
vg: 40ffff
|
||||
vi: 40ffff
|
||||
vm: 40ffff
|
||||
il: 3677a9
|
||||
|
||||
BLOCKQUOTE
|
||||
foreground: ccb24c
|
||||
|
@ -144,40 +144,83 @@ font-family: YaHei Consolas Hybrid, Consolas, Monaco, Andale Mono, Monospace, Co
|
||||
# [VNote] Codeblock sylte from HighlightJS (bold, italic, underlined, strikeout, color)
|
||||
# The last occurence of the same attribute takes effect
|
||||
# Could specify multiple attribute in one line
|
||||
hljs-comment: 6e7686
|
||||
hljs-quote: 6e7686
|
||||
hljs-doctag: c678dd
|
||||
hljs-keyword: c678dd
|
||||
hljs-formula: c678dd
|
||||
hljs-section: e06c75
|
||||
hljs-name: e06c75
|
||||
hljs-selector-tag: e06c75
|
||||
hljs-deletion: e06c75
|
||||
hljs-subst: e06c75
|
||||
hljs-literal: 56b6c2
|
||||
hljs-string: 98c379
|
||||
hljs-regexp: 98c379
|
||||
hljs-addition: 98c379
|
||||
hljs-attribute: 98c379
|
||||
hljs-meta-string: 98c379
|
||||
hljs-built_in: e6c07b
|
||||
hljs-class: e6c07b
|
||||
hljs-attr: d19a66
|
||||
hljs-variable: d19a66
|
||||
hljs-template-variable: d19a66
|
||||
hljs-type: d19a66
|
||||
hljs-selector-class: d19a66
|
||||
hljs-selector-attr: d19a66
|
||||
hljs-selector-pseudo: d19a66
|
||||
hljs-number: d19a66
|
||||
hljs-symbol: 61aeee
|
||||
hljs-link: underlined, 61aeee
|
||||
hljs-bullet: 61aeee
|
||||
hljs-meta: 61aeee
|
||||
hljs-selector-id: 61aeee
|
||||
hljs-title: bold, 61aeee
|
||||
hljs-emphasis: italic
|
||||
hljs-strong: bold
|
||||
hll: 404040
|
||||
c: 999999
|
||||
err: a61717
|
||||
esc: d0d0d0
|
||||
g: d0d0d0
|
||||
k: bold, 6ab825
|
||||
l: d0d0d0
|
||||
n: d0d0d0
|
||||
o: d0d0d0
|
||||
x: d0d0d0
|
||||
p: d0d0d0
|
||||
ch: italic, 999999
|
||||
cm: italic, 999999
|
||||
cp: bold, cd2828
|
||||
cpf: italic, 999999
|
||||
c1: italic, 999999
|
||||
cs: bold, e50808
|
||||
gd: d22323
|
||||
ge: italic, d0d0d0
|
||||
gr: d22323
|
||||
gh: bold, ffffff
|
||||
gi: 589819
|
||||
go: cccccc
|
||||
gp: aaaaaa
|
||||
gs: bold, d0d0d0
|
||||
gu: underlined, ffffff
|
||||
gt: d22323
|
||||
kc: bold, 6ab825
|
||||
kd: bold, 6ab825
|
||||
kn: bold, 6ab825
|
||||
kp: 6ab825
|
||||
kr: bold, 6ab825
|
||||
kt: bold, 6ab825
|
||||
ld: d0d0d0
|
||||
m: 3677a9
|
||||
s: ed9d13
|
||||
na: bbbbbb
|
||||
nb: 24909d
|
||||
nc: underlined, 447fcf
|
||||
no: 40ffff
|
||||
nd: ffa500
|
||||
ni: d0d0d0
|
||||
ne: bbbbbb
|
||||
nf: 447fcf
|
||||
nl: d0d0d0
|
||||
nn: underlined, 447fcf
|
||||
nx: d0d0d0
|
||||
py: d0d0d0
|
||||
nt: bold, 6ab825
|
||||
nv: 40ffff
|
||||
ow: bold, 6ab825
|
||||
w: 666666
|
||||
mb: 3677a9
|
||||
mf: 3677a9
|
||||
mh: 3677a9
|
||||
mi: 3677a9
|
||||
mo: 3677a9
|
||||
sa: ed9d13
|
||||
sb: ed9d13
|
||||
sc: ed9d13
|
||||
dl: ed9d13
|
||||
sd: ed9d13
|
||||
s2: ed9d13
|
||||
se: ed9d13
|
||||
sh: ed9d13
|
||||
si: ed9d13
|
||||
sx: ffa500
|
||||
sr: ed9d13
|
||||
s1: ed9d13
|
||||
ss: ed9d13
|
||||
bp: 24909d
|
||||
fm: 447fcf
|
||||
vc: 40ffff
|
||||
vg: 40ffff
|
||||
vi: 40ffff
|
||||
vm: 40ffff
|
||||
il: 3677a9
|
||||
|
||||
BLOCKQUOTE
|
||||
foreground: 6e7686
|
||||
|
@ -138,42 +138,69 @@ font-family: YaHei Consolas Hybrid, Consolas, Monaco, Andale Mono, Monospace, Co
|
||||
FENCEDCODEBLOCK
|
||||
foreground: 673ab7
|
||||
font-family: YaHei Consolas Hybrid, Consolas, Monaco, Andale Mono, Monospace, Courier New
|
||||
# [VNote] Codeblock sylte from HighlightJS (bold, italic, underlined, strikeout, color)
|
||||
# [VNote] Codeblock sylte from Pygment (bold, italic, underlined, strikeout, color)
|
||||
# The last occurence of the same attribute takes effect
|
||||
hljs-comment: 6c6c6c
|
||||
hljs-keyword: 0000ee
|
||||
hljs-attribute: 0000ee
|
||||
hljs-selector-tag: 0000ee
|
||||
hljs-meta-keyword: 0000ee
|
||||
hljs-doctag: 0000ee
|
||||
hljs-name: 0000ee
|
||||
hljs-type: 880000
|
||||
hljs-string: 880000
|
||||
hljs-number: 880000
|
||||
hljs-selector-id: 880000
|
||||
hljs-selector-class: 880000
|
||||
hljs-quote: 880000
|
||||
hljs-template-tag: 880000
|
||||
hljs-deletion: 880000
|
||||
# Could specify multiple attribute in one line
|
||||
hljs-title: bold, 880000
|
||||
hljs-section: bold, 880000
|
||||
hljs-regexp: bc6060
|
||||
hljs-symbol: bc6060
|
||||
hljs-variable: bc6060
|
||||
hljs-template-variable: bc6060
|
||||
hljs-link: bc6060
|
||||
hljs-selector-attr: bc6060
|
||||
hljs-selector-pseudo: bc6060
|
||||
hljs-literal: af00d7
|
||||
hljs-built_in: 008700
|
||||
hljs-bullet: 008700
|
||||
hljs-code: 008700
|
||||
hljs-addition: 008700
|
||||
hljs-meta: 1f7199
|
||||
hljs-meta-string: 4d99bf
|
||||
hljs-emphasis: italic
|
||||
hljs-strong: bold
|
||||
hll: ffffcc
|
||||
c: 888888
|
||||
err: FF0000
|
||||
k: 008800
|
||||
o: 333333
|
||||
ch: 888888
|
||||
cm: 888888
|
||||
cp: 557799
|
||||
cpf: 4d99bf
|
||||
c1: 888888
|
||||
cs: cc0000
|
||||
gd: A00000
|
||||
ge: italic
|
||||
gr: FF0000
|
||||
gh: 000080
|
||||
gi: 00A000
|
||||
go: 888888
|
||||
gp: c65d09
|
||||
gs: bold
|
||||
gu: bold, 800080
|
||||
gt: bold, 0044DD
|
||||
kc: bold, 008800
|
||||
kd: bold, 008800
|
||||
kn: bold, 008800
|
||||
kp: bold, 003388
|
||||
kr: bold, 008800
|
||||
kt: bold, 333399
|
||||
m: bold, 6600EE
|
||||
s: af00d7
|
||||
na: 0000CC
|
||||
nb: 007020
|
||||
nc: bold, BB0066
|
||||
no: bold, 003366
|
||||
nd: bold, 555555
|
||||
ni: bold, 880000
|
||||
ne: bold, FF0000
|
||||
nf: bold, 0066BB
|
||||
nl: bold, 997700
|
||||
nn: bold, 0e84b5
|
||||
nt: 007700
|
||||
nv: 996633
|
||||
ow: bold, 000000
|
||||
w: bbbbbb
|
||||
mb: bold, 6600EE
|
||||
mf: bold, 6600EE
|
||||
mh: bold, 005588
|
||||
mi: bold, 0000DD
|
||||
mo: bold, 4400EE
|
||||
sc: 0044DD
|
||||
sd: DD4422
|
||||
se: 666666
|
||||
sx: DD2200
|
||||
sr: 000000
|
||||
ss: AA6600
|
||||
bp: 007020
|
||||
fm: bold, 0066BB
|
||||
vc: 336699
|
||||
vg: bold, dd7700
|
||||
vi: 3333BB
|
||||
vm: 996633
|
||||
il: bold, 0000DD
|
||||
|
||||
BLOCKQUOTE
|
||||
foreground: 00af00
|
||||
|
@ -139,42 +139,70 @@ font-family: YaHei Consolas Hybrid, Consolas, Monaco, Andale Mono, Monospace, Co
|
||||
FENCEDCODEBLOCK
|
||||
foreground: 673ab7
|
||||
font-family: YaHei Consolas Hybrid, Consolas, Monaco, Andale Mono, Monospace, Courier New
|
||||
# [VNote] Codeblock sylte from HighlightJS (bold, italic, underlined, strikeout, color)
|
||||
# [VNote] Codeblock sylte from Pygment (bold, italic, underlined, strikeout, color)
|
||||
# The last occurence of the same attribute takes effect
|
||||
# Could specify multiple attribute in one line
|
||||
hljs-comment: 6c6c6c
|
||||
hljs-keyword: 0000ee
|
||||
hljs-attribute: 0000ee
|
||||
hljs-selector-tag: 0000ee
|
||||
hljs-meta-keyword: 0000ee
|
||||
hljs-doctag: 0000ee
|
||||
hljs-name: 0000ee
|
||||
hljs-type: 880000
|
||||
hljs-string: 880000
|
||||
hljs-number: 880000
|
||||
hljs-selector-id: 880000
|
||||
hljs-selector-class: 880000
|
||||
hljs-quote: 880000
|
||||
hljs-template-tag: 880000
|
||||
hljs-deletion: 880000
|
||||
hljs-title: bold, 880000
|
||||
hljs-section: bold, 880000
|
||||
hljs-regexp: bc6060
|
||||
hljs-symbol: bc6060
|
||||
hljs-variable: bc6060
|
||||
hljs-template-variable: bc6060
|
||||
hljs-link: bc6060
|
||||
hljs-selector-attr: bc6060
|
||||
hljs-selector-pseudo: bc6060
|
||||
hljs-literal: af00d7
|
||||
hljs-built_in: 008700
|
||||
hljs-bullet: 008700
|
||||
hljs-code: 008700
|
||||
hljs-addition: 008700
|
||||
hljs-meta: 1f7199
|
||||
hljs-meta-string: 4d99bf
|
||||
hljs-emphasis: italic
|
||||
hljs-strong: bold
|
||||
hll: ffffcc
|
||||
c: 888888
|
||||
err: FF0000
|
||||
k: 008800
|
||||
o: 333333
|
||||
ch: 888888
|
||||
cm: 888888
|
||||
cp: 557799
|
||||
cpf: 4d99bf
|
||||
c1: 888888
|
||||
cs: cc0000
|
||||
gd: A00000
|
||||
ge: italic
|
||||
gr: FF0000
|
||||
gh: 000080
|
||||
gi: 00A000
|
||||
go: 888888
|
||||
gp: c65d09
|
||||
gs: bold
|
||||
gu: bold, 800080
|
||||
gt: bold, 0044DD
|
||||
kc: bold, 008800
|
||||
kd: bold, 008800
|
||||
kn: bold, 008800
|
||||
kp: bold, 003388
|
||||
kr: bold, 008800
|
||||
kt: bold, 333399
|
||||
m: bold, 6600EE
|
||||
s: af00d7
|
||||
na: 0000CC
|
||||
nb: 007020
|
||||
nc: bold, BB0066
|
||||
no: bold, 003366
|
||||
nd: bold, 555555
|
||||
ni: bold, 880000
|
||||
ne: bold, FF0000
|
||||
nf: bold, 0066BB
|
||||
nl: bold, 997700
|
||||
nn: bold, 0e84b5
|
||||
nt: 007700
|
||||
nv: 996633
|
||||
ow: bold, 000000
|
||||
w: bbbbbb
|
||||
mb: bold, 6600EE
|
||||
mf: bold, 6600EE
|
||||
mh: bold, 005588
|
||||
mi: bold, 0000DD
|
||||
mo: bold, 4400EE
|
||||
sc: 0044DD
|
||||
sd: DD4422
|
||||
se: 666666
|
||||
sx: DD2200
|
||||
sr: 000000
|
||||
ss: AA6600
|
||||
bp: 007020
|
||||
fm: bold, 0066BB
|
||||
vc: 336699
|
||||
vg: bold, dd7700
|
||||
vi: 3333BB
|
||||
vm: 996633
|
||||
il: bold, 0000DD
|
||||
|
||||
BLOCKQUOTE
|
||||
foreground: 00af00
|
||||
|
@ -135,39 +135,67 @@ font-family: YaHei Consolas Hybrid, Consolas, Monaco, Andale Mono, Monospace, Co
|
||||
# [VNote] Codeblock sylte from HighlightJS (bold, italic, underlined, strikeout, color)
|
||||
# The last occurence of the same attribute takes effect
|
||||
# Could specify multiple attribute in one line
|
||||
hljs-comment: 6c6c6c
|
||||
hljs-keyword: 0000ee
|
||||
hljs-attribute: 0000ee
|
||||
hljs-selector-tag: 0000ee
|
||||
hljs-meta-keyword: 0000ee
|
||||
hljs-doctag: 0000ee
|
||||
hljs-name: 0000ee
|
||||
hljs-type: 880000
|
||||
hljs-string: 880000
|
||||
hljs-number: 880000
|
||||
hljs-selector-id: 880000
|
||||
hljs-selector-class: 880000
|
||||
hljs-quote: 880000
|
||||
hljs-template-tag: 880000
|
||||
hljs-deletion: 880000
|
||||
hljs-title: bold, 880000
|
||||
hljs-section: bold, 880000
|
||||
hljs-regexp: bc6060
|
||||
hljs-symbol: bc6060
|
||||
hljs-variable: bc6060
|
||||
hljs-template-variable: bc6060
|
||||
hljs-link: bc6060
|
||||
hljs-selector-attr: bc6060
|
||||
hljs-selector-pseudo: bc6060
|
||||
hljs-literal: af00d7
|
||||
hljs-built_in: 008700
|
||||
hljs-bullet: 008700
|
||||
hljs-code: 008700
|
||||
hljs-addition: 008700
|
||||
hljs-meta: 1f7199
|
||||
hljs-meta-string: 4d99bf
|
||||
hljs-emphasis: italic
|
||||
hljs-strong: bold
|
||||
hll: ffffcc
|
||||
c: 888888
|
||||
err: FF0000
|
||||
k: 008800
|
||||
o: 333333
|
||||
ch: 888888
|
||||
cm: 888888
|
||||
cp: 557799
|
||||
cpf: 4d99bf
|
||||
c1: 888888
|
||||
cs: cc0000
|
||||
gd: A00000
|
||||
ge: italic
|
||||
gr: FF0000
|
||||
gh: 000080
|
||||
gi: 00A000
|
||||
go: 888888
|
||||
gp: c65d09
|
||||
gs: bold
|
||||
gu: bold, 800080
|
||||
gt: bold, 0044DD
|
||||
kc: bold, 008800
|
||||
kd: bold, 008800
|
||||
kn: bold, 008800
|
||||
kp: bold, 003388
|
||||
kr: bold, 008800
|
||||
kt: bold, 333399
|
||||
m: bold, 6600EE
|
||||
s: af00d7
|
||||
na: 0000CC
|
||||
nb: 007020
|
||||
nc: bold, BB0066
|
||||
no: bold, 003366
|
||||
nd: bold, 555555
|
||||
ni: bold, 880000
|
||||
ne: bold, FF0000
|
||||
nf: bold, 0066BB
|
||||
nl: bold, 997700
|
||||
nn: bold, 0e84b5
|
||||
nt: 007700
|
||||
nv: 996633
|
||||
ow: bold, 000000
|
||||
w: bbbbbb
|
||||
mb: bold, 6600EE
|
||||
mf: bold, 6600EE
|
||||
mh: bold, 005588
|
||||
mi: bold, 0000DD
|
||||
mo: bold, 4400EE
|
||||
sc: 0044DD
|
||||
sd: DD4422
|
||||
se: 666666
|
||||
sx: DD2200
|
||||
sr: 000000
|
||||
ss: AA6600
|
||||
bp: 007020
|
||||
fm: bold, 0066BB
|
||||
vc: 336699
|
||||
vg: bold, dd7700
|
||||
vi: 3333BB
|
||||
vm: 996633
|
||||
il: bold, 0000DD
|
||||
|
||||
BLOCKQUOTE
|
||||
foreground: 00af00
|
||||
|
@ -336,6 +336,9 @@ enable_smart_table=true
|
||||
; Interval (milliseconds) to format table
|
||||
table_format_interval=2000
|
||||
|
||||
; Pygment program to call for code block highlight.
|
||||
pygment_prg=pygmentize
|
||||
|
||||
[export]
|
||||
; Path of the wkhtmltopdf tool
|
||||
wkhtmltopdf=wkhtmltopdf
|
||||
|
@ -5,25 +5,30 @@
|
||||
|
||||
#include "vdocument.h"
|
||||
#include "utils/vutils.h"
|
||||
#include "utils/veditutils.h"
|
||||
#include "pegmarkdownhighlighter.h"
|
||||
#include "vconfigmanager.h"
|
||||
#include "utils/vprocessutils.h"
|
||||
|
||||
extern VConfigManager *g_config;
|
||||
|
||||
#define TaskIdProperty "PygmentTaskId"
|
||||
#define TaskTimeStampProperty "PygmentTaskTimeStamp"
|
||||
|
||||
VCodeBlockHighlightHelper::VCodeBlockHighlightHelper(PegMarkdownHighlighter *p_highlighter,
|
||||
VDocument *p_vdoc,
|
||||
MarkdownConverterType p_type)
|
||||
: QObject(p_highlighter),
|
||||
m_highlighter(p_highlighter),
|
||||
m_vdocument(p_vdoc),
|
||||
m_type(p_type),
|
||||
m_timeStamp(0)
|
||||
{
|
||||
m_program = g_config->getPygmentPrg();
|
||||
m_args << "-f" << "html" << "-O" << "encoding=utf8";
|
||||
|
||||
qDebug() << "code block highlight helper" << m_program << m_args;
|
||||
|
||||
connect(m_highlighter, &PegMarkdownHighlighter::codeBlocksUpdated,
|
||||
this, &VCodeBlockHighlightHelper::handleCodeBlocksUpdated);
|
||||
connect(m_vdocument, &VDocument::textHighlighted,
|
||||
this, &VCodeBlockHighlightHelper::handleTextHighlightResult);
|
||||
|
||||
// Web side is ready for code block highlight.
|
||||
connect(m_vdocument, &VDocument::readyToHighlightText,
|
||||
m_highlighter, &PegMarkdownHighlighter::updateHighlight);
|
||||
}
|
||||
|
||||
QString VCodeBlockHighlightHelper::unindentCodeBlock(const QString &p_text)
|
||||
@ -62,16 +67,6 @@ QString VCodeBlockHighlightHelper::unindentCodeBlock(const QString &p_text)
|
||||
void VCodeBlockHighlightHelper::handleCodeBlocksUpdated(TimeStamp p_timeStamp,
|
||||
const QVector<VCodeBlock> &p_codeBlocks)
|
||||
{
|
||||
if (!m_vdocument->isReadyToHighlight()) {
|
||||
// Immediately return empty results.
|
||||
QVector<HLUnitPos> emptyRes;
|
||||
for (int i = 0; i < p_codeBlocks.size(); ++i) {
|
||||
updateHighlightResults(p_timeStamp, 0, emptyRes);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
m_timeStamp = p_timeStamp;
|
||||
m_codeBlocks = p_codeBlocks;
|
||||
for (int i = 0; i < m_codeBlocks.size(); ++i) {
|
||||
@ -84,11 +79,41 @@ void VCodeBlockHighlightHelper::handleCodeBlocksUpdated(TimeStamp p_timeStamp,
|
||||
updateHighlightResults(p_timeStamp, block.m_startPos, it.value().m_units);
|
||||
} else {
|
||||
QString unindentedText = unindentCodeBlock(block.m_text);
|
||||
m_vdocument->highlightTextAsync(unindentedText, i, p_timeStamp);
|
||||
highlightTextAsync(VEditUtils::removeCodeBlockFence(unindentedText),
|
||||
block.m_lang,
|
||||
i,
|
||||
p_timeStamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VCodeBlockHighlightHelper::highlightTextAsync(const QString &p_text,
|
||||
const QString &p_lang,
|
||||
int p_id,
|
||||
unsigned long long p_timeStamp)
|
||||
{
|
||||
if (p_lang.isEmpty() || m_program.isEmpty()) {
|
||||
updateHighlightResults(p_timeStamp, 0, QVector<HLUnitPos>());
|
||||
return;
|
||||
}
|
||||
|
||||
QProcess *process = new QProcess(this);
|
||||
process->setProperty(TaskIdProperty, p_id);
|
||||
process->setProperty(TaskTimeStampProperty, p_timeStamp);
|
||||
connect(process, SIGNAL(finished(int, QProcess::ExitStatus)),
|
||||
this, SLOT(handleProcessFinished(int, QProcess::ExitStatus)));
|
||||
|
||||
QStringList args(m_args);
|
||||
args << "-l" << p_lang;
|
||||
process->start(m_program, args);
|
||||
|
||||
if (process->write(p_text.toUtf8()) == -1) {
|
||||
qWarning() << "fail to write to QProcess:" << process->errorString();
|
||||
}
|
||||
|
||||
process->closeWriteChannel();
|
||||
}
|
||||
|
||||
void VCodeBlockHighlightHelper::handleTextHighlightResult(const QString &p_html,
|
||||
int p_id,
|
||||
unsigned long long p_timeStamp)
|
||||
@ -154,6 +179,11 @@ void VCodeBlockHighlightHelper::parseHighlightResult(TimeStamp p_timeStamp,
|
||||
|
||||
QXmlStreamReader xml(p_html);
|
||||
|
||||
if (p_html.isEmpty()) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
{
|
||||
// Must have a fenced line at the front.
|
||||
// textIndex is the start index in the code block text to search for.
|
||||
int textIndex = text.indexOf('\n');
|
||||
@ -163,7 +193,7 @@ void VCodeBlockHighlightHelper::parseHighlightResult(TimeStamp p_timeStamp,
|
||||
++textIndex;
|
||||
|
||||
if (xml.readNextStartElement()) {
|
||||
if (xml.name() != "pre") {
|
||||
if (xml.name() != "div") {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@ -171,7 +201,7 @@ void VCodeBlockHighlightHelper::parseHighlightResult(TimeStamp p_timeStamp,
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (xml.name() != "code") {
|
||||
if (xml.name() != "pre") {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@ -209,6 +239,7 @@ void VCodeBlockHighlightHelper::parseHighlightResult(TimeStamp p_timeStamp,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exit:
|
||||
// Pass result back to highlighter.
|
||||
@ -275,8 +306,11 @@ bool VCodeBlockHighlightHelper::parseSpanElement(QXmlStreamReader &p_xml,
|
||||
}
|
||||
|
||||
// Got a complete span. Use relative position here.
|
||||
HLUnitPos unit(unitStart, p_index - unitStart, style);
|
||||
p_units.append(unit);
|
||||
if (p_index > unitStart) {
|
||||
HLUnitPos unit(unitStart, p_index - unitStart, style);
|
||||
p_units.append(unit);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@ -305,3 +339,43 @@ void VCodeBlockHighlightHelper::addToHighlightCache(const QString &p_text,
|
||||
|
||||
m_cache.insert(p_text, HLResult(p_timeStamp, p_units));
|
||||
}
|
||||
|
||||
void VCodeBlockHighlightHelper::handleProcessFinished(int p_exitCode, QProcess::ExitStatus p_exitStatus)
|
||||
{
|
||||
QProcess *process = static_cast<QProcess *>(sender());
|
||||
int id = process->property(TaskIdProperty).toInt();
|
||||
TimeStamp timeStamp = process->property(TaskTimeStampProperty).toULongLong();
|
||||
qDebug() << QString("Pygment finished: id %1 timestamp %2 exitcode %3 exitstatus %4")
|
||||
.arg(id)
|
||||
.arg(timeStamp)
|
||||
.arg(p_exitCode)
|
||||
.arg(p_exitStatus);
|
||||
bool failed = true;
|
||||
if (p_exitStatus == QProcess::NormalExit) {
|
||||
if (p_exitCode < 0) {
|
||||
qWarning() << "Pygment fail" << p_exitCode;
|
||||
} else {
|
||||
failed = false;
|
||||
QByteArray outBa = process->readAllStandardOutput();
|
||||
handleTextHighlightResult(QString::fromUtf8(outBa), id, timeStamp);
|
||||
}
|
||||
} else {
|
||||
qWarning() << "fail to start Pygment process" << p_exitCode << p_exitStatus;
|
||||
}
|
||||
|
||||
QByteArray errBa = process->readAllStandardError();
|
||||
if (!errBa.isEmpty()) {
|
||||
QString errStr(QString::fromLocal8Bit(errBa));
|
||||
if (failed) {
|
||||
qWarning() << "Pygment stderr:" << errStr;
|
||||
} else {
|
||||
qDebug() << "Pygment stderr:" << errStr;
|
||||
}
|
||||
}
|
||||
|
||||
if (failed) {
|
||||
handleTextHighlightResult(QString(), id, timeStamp);
|
||||
}
|
||||
|
||||
process->deleteLater();
|
||||
}
|
||||
|
@ -6,10 +6,11 @@
|
||||
#include <QAtomicInteger>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QHash>
|
||||
#include <QProcess>
|
||||
#include <QStringList>
|
||||
|
||||
#include "vconfigmanager.h"
|
||||
|
||||
class VDocument;
|
||||
class PegMarkdownHighlighter;
|
||||
|
||||
class VCodeBlockHighlightHelper : public QObject
|
||||
@ -17,7 +18,7 @@ class VCodeBlockHighlightHelper : public QObject
|
||||
Q_OBJECT
|
||||
public:
|
||||
VCodeBlockHighlightHelper(PegMarkdownHighlighter *p_highlighter,
|
||||
VDocument *p_vdoc, MarkdownConverterType p_type);
|
||||
MarkdownConverterType p_type);
|
||||
|
||||
// @p_text: text of fenced code block.
|
||||
// Get the indent level of the first line (fence) and unindent the whole block
|
||||
@ -31,6 +32,8 @@ private slots:
|
||||
|
||||
void handleTextHighlightResult(const QString &p_html, int p_id, unsigned long long p_timeStamp);
|
||||
|
||||
void handleProcessFinished(int p_exitCode, QProcess::ExitStatus p_exitStatus);
|
||||
|
||||
private:
|
||||
struct HLResult
|
||||
{
|
||||
@ -65,8 +68,12 @@ private:
|
||||
TimeStamp p_timeStamp,
|
||||
const QVector<HLUnitPos> &p_units);
|
||||
|
||||
void highlightTextAsync(const QString &p_text,
|
||||
const QString &p_lang,
|
||||
int p_id,
|
||||
unsigned long long p_timeStamp);
|
||||
|
||||
PegMarkdownHighlighter *m_highlighter;
|
||||
VDocument *m_vdocument;
|
||||
MarkdownConverterType m_type;
|
||||
|
||||
TimeStamp m_timeStamp;
|
||||
@ -76,6 +83,10 @@ private:
|
||||
// Cache for highlight result, using the code block text as key.
|
||||
// The HLResult has relative position only.
|
||||
QHash<QString, HLResult> m_cache;
|
||||
|
||||
QString m_program;
|
||||
|
||||
QStringList m_args;
|
||||
};
|
||||
|
||||
#endif // VCODEBLOCKHIGHLIGHTHELPER_H
|
||||
|
@ -20,7 +20,7 @@ const QString VConfigManager::orgName = QString("vnote");
|
||||
|
||||
const QString VConfigManager::appName = QString("vnote");
|
||||
|
||||
const QString VConfigManager::c_version = QString("2.7.1");
|
||||
const QString VConfigManager::c_version = QString("2.7.56");
|
||||
|
||||
const QString VConfigManager::c_dirConfigFile = QString("_vnote.json");
|
||||
|
||||
@ -382,6 +382,8 @@ void VConfigManager::initEditorConfigs()
|
||||
m_enableSmartTable = getConfigFromSettings(section, "enable_smart_table").toBool();
|
||||
|
||||
m_tableFormatIntervalMS = getConfigFromSettings(section, "table_format_interval").toInt();
|
||||
|
||||
m_pygmentPrg = getConfigFromSettings(section, "pygment_prg").toString();
|
||||
}
|
||||
|
||||
void VConfigManager::initMarkdownConfigs()
|
||||
|
@ -648,6 +648,8 @@ public:
|
||||
|
||||
bool getEnableCodeBlockCopyButton() const;
|
||||
|
||||
const QString &getPygmentPrg() const;
|
||||
|
||||
private:
|
||||
void initEditorConfigs();
|
||||
|
||||
@ -1147,6 +1149,9 @@ private:
|
||||
// Whether enable copy button in code block in read mode.
|
||||
bool m_enableCodeBlockCopyButton;
|
||||
|
||||
// Pygment program to call for code block highlight in editor.
|
||||
QString m_pygmentPrg;
|
||||
|
||||
// The name of the config file in each directory.
|
||||
static const QString c_dirConfigFile;
|
||||
|
||||
@ -2989,4 +2994,9 @@ inline bool VConfigManager::getEnableCodeBlockCopyButton() const
|
||||
return m_enableCodeBlockCopyButton;
|
||||
}
|
||||
|
||||
inline const QString &VConfigManager::getPygmentPrg() const
|
||||
{
|
||||
return m_pygmentPrg;
|
||||
}
|
||||
|
||||
#endif // VCONFIGMANAGER_H
|
||||
|
@ -101,9 +101,7 @@ VMdEditor::VMdEditor(VFile *p_file,
|
||||
}
|
||||
});
|
||||
|
||||
m_cbHighlighter = new VCodeBlockHighlightHelper(m_pegHighlighter,
|
||||
p_doc,
|
||||
p_type);
|
||||
m_cbHighlighter = new VCodeBlockHighlightHelper(m_pegHighlighter, p_type);
|
||||
|
||||
m_previewMgr = new VPreviewManager(this, m_pegHighlighter);
|
||||
connect(m_pegHighlighter, &PegMarkdownHighlighter::imageLinksUpdated,
|
||||
|
Loading…
x
Reference in New Issue
Block a user