Skip to content

Commit

Permalink
Tiny refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
EpicEricEE committed Oct 20, 2024
1 parent fe4b88e commit 0729b14
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/droplet.typ
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,15 @@
has-break = type(sep) == content and sep.func() in (linebreak, parbreak)
}

let last-of-first-inline = inline(split(first, -1).at(1))
let first-of-second-inline = second != none and inline(split(second, 1).at(0))
let func = if last-of-first-inline { box } else { block }
// Find elements at boundary.
let last-of-first = split(first, -1).at(1)
let first-of-second = if second == none { none } else { split(second, 1).at(0) }

let func(body) = if inline(last-of-first) {
box(body) + linebreak()
} else {
block(body)
}

func(grid(
column-gutter: gap,
Expand All @@ -173,13 +179,12 @@
set par(hanging-indent: hanging-indent)
first

if not has-break and last-of-first-inline and first-of-second-inline {
if not has-break and inline(last-of-first) and inline(first-of-second) {
linebreak(justify: justify)
}
}
))

if func == box { linebreak() }
if type(sep) == content and sep.func() in (linebreak, parbreak) { sep }

second
Expand Down
2 changes: 1 addition & 1 deletion src/util.typ
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,5 @@
//
// Requires context.
#let inline(element) = {
measure(h(0.1pt) + element).width > measure(element).width
element != none and measure(h(0.1pt) + element).width > measure(element).width
}

0 comments on commit 0729b14

Please sign in to comment.