Distinguish between anchor ref and href in tokenizer
This commit is contained in:
@@ -87,10 +87,12 @@ class TextFmt(IntEnum):
|
||||
COL_E = 16 # End colour
|
||||
ANM_B = 17 # Begin anchor name
|
||||
ANM_E = 18 # End anchor name
|
||||
HRF_B = 19 # Begin href link
|
||||
HRF_E = 20 # End href link
|
||||
FNOTE = 21 # Footnote marker
|
||||
STRIP = 22 # Strip the format code
|
||||
ARF_B = 19 # Begin anchor link
|
||||
ARF_E = 20 # End anchor link
|
||||
HRF_B = 21 # Begin href link
|
||||
HRF_E = 22 # End href link
|
||||
FNOTE = 23 # Footnote marker
|
||||
STRIP = 24 # Strip the format code
|
||||
|
||||
|
||||
class BlockTyp(IntEnum):
|
||||
|
||||
@@ -49,6 +49,7 @@ HTML_OPENER: dict[int, tuple[int, str]] = {
|
||||
TextFmt.SUB_B: (TextFmt.SUB_E, "<sub>"),
|
||||
TextFmt.COL_B: (TextFmt.COL_E, "<span style='color: {0}'>"),
|
||||
TextFmt.ANM_B: (TextFmt.ANM_E, "<a name='{0}'>"),
|
||||
TextFmt.ARF_B: (TextFmt.ARF_E, "<a href='{0}'>"),
|
||||
TextFmt.HRF_B: (TextFmt.HRF_E, "<a href='{0}'>"),
|
||||
}
|
||||
|
||||
@@ -63,6 +64,7 @@ HTML_CLOSER: dict[int, tuple[int, str]] = {
|
||||
TextFmt.SUB_E: (TextFmt.SUB_B, "</sub>"),
|
||||
TextFmt.COL_E: (TextFmt.COL_B, "</span>"),
|
||||
TextFmt.ANM_E: (TextFmt.ANM_B, "</a>"),
|
||||
TextFmt.ARF_E: (TextFmt.ARF_B, "</a>"),
|
||||
TextFmt.HRF_E: (TextFmt.HRF_B, "</a>"),
|
||||
}
|
||||
|
||||
@@ -398,7 +400,7 @@ class ToHtml(Tokenizer):
|
||||
if not state.get(fmt, True):
|
||||
if fmt == TextFmt.COL_B and (color := self._classes.get(data)):
|
||||
tags.append((pos, m[1].format(color.name(QtHexRgb))))
|
||||
elif fmt in (TextFmt.ANM_B, TextFmt.HRF_B):
|
||||
elif fmt in (TextFmt.ANM_B, TextFmt.ARF_B, TextFmt.HRF_B):
|
||||
tags.append((pos, m[1].format(data or "#")))
|
||||
else:
|
||||
tags.append((pos, m[1]))
|
||||
|
||||
@@ -1089,8 +1089,8 @@ class Tokenizer(ABC):
|
||||
for n, bit in enumerate(bits[1:], 2):
|
||||
end = pos + len(bit)
|
||||
fmt.append((pos, TextFmt.COL_B, "tag"))
|
||||
fmt.append((pos, TextFmt.HRF_B, f"#tag_{bit}".lower()))
|
||||
fmt.append((end, TextFmt.HRF_E, ""))
|
||||
fmt.append((pos, TextFmt.ARF_B, f"#tag_{bit}".lower()))
|
||||
fmt.append((end, TextFmt.ARF_E, ""))
|
||||
fmt.append((end, TextFmt.COL_E, ""))
|
||||
txt.append(bit)
|
||||
pos = end
|
||||
|
||||
@@ -330,12 +330,12 @@ class ToQTextDocument(Tokenizer):
|
||||
cFmt.setAnchorNames([data])
|
||||
elif fmt == TextFmt.ANM_E:
|
||||
cFmt.setAnchor(False)
|
||||
elif fmt == TextFmt.HRF_B:
|
||||
elif fmt in (TextFmt.HRF_B, TextFmt.ARF_B):
|
||||
cFmt.setForeground(primary or self._theme.link)
|
||||
cFmt.setFontUnderline(True)
|
||||
cFmt.setAnchor(True)
|
||||
cFmt.setAnchorHref(data)
|
||||
elif fmt == TextFmt.HRF_E:
|
||||
elif fmt in (TextFmt.HRF_E, TextFmt.ARF_E):
|
||||
cFmt.setForeground(primary or self._theme.text)
|
||||
cFmt.setFontUnderline(False)
|
||||
cFmt.setAnchor(False)
|
||||
|
||||
Reference in New Issue
Block a user