Add url support in tokenizer and qdoc preview
This commit is contained in:
@@ -46,6 +46,7 @@ class TextDocumentTheme:
|
||||
text: QColor = QColor(0, 0, 0)
|
||||
highlight: QColor = QColor(255, 255, 166)
|
||||
head: QColor = QColor(66, 113, 174)
|
||||
link: QColor = QColor(66, 113, 174)
|
||||
comment: QColor = QColor(100, 100, 100)
|
||||
note: QColor = QColor(129, 55, 9)
|
||||
code: QColor = QColor(66, 113, 174)
|
||||
|
||||
@@ -1117,6 +1117,13 @@ class Tokenizer(ABC):
|
||||
for n, fmt in enumerate(fmts) if fmt > 0
|
||||
)
|
||||
|
||||
# Match URLs
|
||||
for res in REGEX_PATTERNS.url.finditer(text):
|
||||
s = res.start(0)
|
||||
e = res.end(0)
|
||||
temp.append((s, s, TextFmt.HRF_B, res.group(0)))
|
||||
temp.append((e, e, TextFmt.HRF_E, ""))
|
||||
|
||||
# Match Shortcodes
|
||||
for res in REGEX_PATTERNS.shortcodePlain.finditer(text):
|
||||
temp.append((
|
||||
|
||||
@@ -29,7 +29,7 @@ from pathlib import Path
|
||||
|
||||
from PyQt5.QtCore import QMarginsF, QSizeF
|
||||
from PyQt5.QtGui import (
|
||||
QFont, QFontMetricsF, QPageSize, QTextBlockFormat, QTextCharFormat,
|
||||
QColor, QFont, QFontMetricsF, QPageSize, QTextBlockFormat, QTextCharFormat,
|
||||
QTextCursor, QTextDocument
|
||||
)
|
||||
from PyQt5.QtPrintSupport import QPrinter
|
||||
@@ -281,8 +281,9 @@ class ToQTextDocument(Tokenizer):
|
||||
) -> None:
|
||||
"""Apply formatting tags to text."""
|
||||
cFmt = QTextCharFormat(dFmt)
|
||||
start = 0
|
||||
temp = text.replace("\n", nwUnicode.U_LSEP)
|
||||
start = 0
|
||||
primary: QColor | None = None
|
||||
for pos, fmt, data in tFmt:
|
||||
|
||||
# Insert buffer with previous format
|
||||
@@ -320,20 +321,25 @@ class ToQTextDocument(Tokenizer):
|
||||
elif fmt == TextFmt.COL_B:
|
||||
if color := self._classes.get(data):
|
||||
cFmt.setForeground(color)
|
||||
primary = color
|
||||
elif fmt == TextFmt.COL_E:
|
||||
cFmt.setForeground(self._theme.text)
|
||||
primary = None
|
||||
elif fmt == TextFmt.ANM_B:
|
||||
cFmt.setAnchor(True)
|
||||
cFmt.setAnchorNames([data])
|
||||
elif fmt == TextFmt.ANM_E:
|
||||
cFmt.setAnchor(False)
|
||||
elif fmt == TextFmt.HRF_B:
|
||||
cFmt.setForeground(primary or self._theme.link)
|
||||
cFmt.setFontUnderline(True)
|
||||
cFmt.setAnchor(True)
|
||||
cFmt.setAnchorHref(data)
|
||||
elif fmt == TextFmt.HRF_E:
|
||||
cFmt.setForeground(primary or self._theme.text)
|
||||
cFmt.setFontUnderline(False)
|
||||
cFmt.setAnchor(False)
|
||||
cFmt.setAnchorHref("")
|
||||
elif fmt == TextFmt.FNOTE:
|
||||
xFmt = QTextCharFormat(self._charFmt)
|
||||
xFmt.setForeground(self._theme.code)
|
||||
|
||||
Reference in New Issue
Block a user