aboutsummaryrefslogtreecommitdiffstats
path: root/src/css/csstree.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2025-02-18 19:35:05 +0100
committerbptato <nincsnevem662@gmail.com>2025-02-18 19:41:40 +0100
commita1154392ac6d012302031fbbda574d2da059c745 (patch)
treeef47d1bb8e41dd0760cab75a825d858e1a7beb74 /src/css/csstree.nim
parent4f785b483c92ef9755258e49de4a40a14ae4faf6 (diff)
downloadchawan-a1154392ac6d012302031fbbda574d2da059c745.tar.gz
Add mark-links feature
ref. https://todo.sr.ht/~bptato/chawan/43
Diffstat (limited to 'src/css/csstree.nim')
-rw-r--r--src/css/csstree.nim15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/css/csstree.nim b/src/css/csstree.nim
index 4dcdf0d0..80d73758 100644
--- a/src/css/csstree.nim
+++ b/src/css/csstree.nim
@@ -69,6 +69,7 @@ type
n: int32
TreeContext = object
+ markLinks: bool
quoteLevel: int
counters: seq[CSSCounter]
rootProperties: CSSValues
@@ -409,6 +410,11 @@ proc addOptionChildren(frame: var TreeFrame; option: HTMLOptionElement) =
frame.addText("]")
frame.addElementChildren()
+proc addAnchorChildren(frame: var TreeFrame) =
+ if frame.ctx.markLinks:
+ frame.addPseudo(peLinkMarker)
+ frame.addElementChildren()
+
proc addChildren(frame: var TreeFrame) =
case frame.parent.tagType
of TAG_INPUT:
@@ -428,6 +434,8 @@ proc addChildren(frame: var TreeFrame) =
of TAG_OPTION:
let option = HTMLOptionElement(frame.parent)
frame.addOptionChildren(option)
+ of TAG_A:
+ frame.addAnchorChildren()
elif frame.parent.tagType(Namespace.SVG) == TAG_SVG:
frame.addImage(SVGSVGElement(frame.parent).bitmap)
else:
@@ -549,7 +557,7 @@ proc build(ctx: var TreeContext; cached: CSSBox; styledNode: StyledNode):
)
# Root
-proc buildTree*(element: Element; cached: CSSBox): BlockBox =
+proc buildTree*(element: Element; cached: CSSBox; markLinks: bool): BlockBox =
if element.computed == nil:
element.applyStyle()
let styledNode = StyledNode(
@@ -557,5 +565,8 @@ proc buildTree*(element: Element; cached: CSSBox): BlockBox =
element: element,
computed: element.computed
)
- var ctx = TreeContext(rootProperties: rootProperties())
+ var ctx = TreeContext(
+ rootProperties: rootProperties(),
+ markLinks: markLinks
+ )
return BlockBox(ctx.build(cached, styledNode))