use Qt native MarkdownText for prose blocks
Stop hand-rolling markdown with regex. Qt 6 Text supports textFormat: Text.MarkdownText natively — handles backticks, bold, italic, links, lists correctly. Code blocks and diffs still use our custom KSyntaxHighlighting rendering.
This commit is contained in:
parent
cc24400ba7
commit
c907aee653
18
gui/main.qml
18
gui/main.qml
|
|
@ -519,17 +519,7 @@ ApplicationWindow {
|
|||
|
||||
// --- Chat block delegates ---
|
||||
|
||||
function linkifyPaths(text) {
|
||||
// Escape HTML entities first
|
||||
let escaped = text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
||||
// Inline code: `text` → monospace styled span
|
||||
escaped = escaped.replace(/`([^`\n]+)`/g, '<code style="font-family:monospace;background:rgba(128,128,128,0.15);padding:1px 4px;border-radius:3px;">$1</code>')
|
||||
// Convert newlines to <br>
|
||||
escaped = escaped.replace(/\n/g, '<br>')
|
||||
// Match /absolute/path or /absolute/path:line
|
||||
escaped = escaped.replace(/(\/[\w\-.\/]+(?::\d+)?)/g, '<a href="file://$1">$1</a>')
|
||||
return escaped
|
||||
}
|
||||
|
||||
|
||||
Component {
|
||||
id: userDelegate
|
||||
|
|
@ -702,12 +692,12 @@ ApplicationWindow {
|
|||
id: proseSubDelegate
|
||||
Text {
|
||||
width: parent ? parent.width : implicitWidth
|
||||
text: root.linkifyPaths(subBlock.content)
|
||||
text: subBlock.content || ""
|
||||
wrapMode: Text.Wrap
|
||||
textFormat: Text.RichText
|
||||
textFormat: Text.MarkdownText
|
||||
color: palette.text
|
||||
font.pixelSize: Qt.application.font.pixelSize
|
||||
lineHeight: 1.4
|
||||
lineHeight: 1.3
|
||||
onLinkActivated: function(link) {
|
||||
Qt.openUrlExternally(link)
|
||||
}
|
||||
|
|
|
|||
Reference in New Issue