Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Kate
Commits
1055027f
Commit
1055027f
authored
Feb 12, 2021
by
Waqar Ahmed
Browse files
Improved markdown handling a bit
parent
71c34ef4
Changes
1
Hide whitespace changes
Inline
Side-by-side
addons/lspclient/lsptooltip.cpp
View file @
1055027f
...
...
@@ -62,14 +62,21 @@ public:
out
.
reset
();
outputString
.
clear
();
bool
inCodeBlock
=
false
;
KSyntaxHighlighting
::
State
state
;
bool
li
=
false
;
// World's smallest markdown parser :)
while
(
!
in
.
atEnd
())
{
currentLine
=
in
.
readLine
();
if
(
currentLine
.
isEmpty
())
{
// allow empty lines in code blocks, no ruler here
if
(
!
inCodeBlock
&&
currentLine
.
isEmpty
())
{
out
<<
"<hr>"
;
continue
;
}
// list
if
(
!
li
&&
currentLine
.
startsWith
(
QLatin1String
(
"- "
)))
{
currentLine
.
remove
(
0
,
2
);
out
<<
"<ul><li>"
;
...
...
@@ -81,6 +88,24 @@ public:
out
<<
"</li></ul>"
;
li
=
false
;
}
// code block
if
(
!
inCodeBlock
&&
currentLine
.
startsWith
(
QLatin1String
(
"```"
)))
{
inCodeBlock
=
true
;
continue
;
}
else
if
(
inCodeBlock
&&
currentLine
.
startsWith
(
QLatin1String
(
"```"
)))
{
inCodeBlock
=
false
;
continue
;
}
// ATX heading
if
(
currentLine
.
startsWith
(
QStringLiteral
(
"# "
)))
{
currentLine
.
remove
(
0
,
2
);
currentLine
=
QStringLiteral
(
"<h3>"
)
+
currentLine
+
QStringLiteral
(
"</h3>"
);
out
<<
currentLine
;
continue
;
}
state
=
highlightLine
(
currentLine
,
state
);
if
(
li
)
{
out
<<
"</li>"
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment