Skip to content

Commit

Permalink
Add util module
Browse files Browse the repository at this point in the history
  • Loading branch information
tingerrr committed Apr 18, 2024
1 parent 26f64c7 commit 7114ae1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 23 deletions.
22 changes: 3 additions & 19 deletions src/core.typ
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
#import "util.typ" as _util

#let keys = (
superfigure: "__subpar:superfigure-unprepared",
counter: "__subpar:subfigure-counter",
)

#let subfigure-counter = counter(keys.counter)

#let is-element(value, func) = {
type(value) == content and value.func() == func
}

#let extract-payload(body) = {
if not body.has("children") { return }
if body.children.len() == 0 { return }

let first = body.children.first()

if not is-element(first, metadata) { return }
first.value
}

#let embed-payload(body, ..payload) = {
metadata(payload.named()) + body
}

#let apply-for-all(
values,
rule,
Expand Down Expand Up @@ -53,7 +37,7 @@
supplement: supplement,
gap: gap,
outlined: outlined,
embed-payload(
_util.embed-payload(
kind: kind,
numbering-sub: numbering-sub,
numbering-sub-ref: numbering-sub-ref,
Expand Down
7 changes: 4 additions & 3 deletions src/lib.typ
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import "core.typ"
#import "util.typ"

#let super-figure = core.super-figure-unprepared

Expand All @@ -8,7 +9,7 @@
body,
) = {
show figure.where(kind: core.keys.superfigure): it => {
let payload = core.extract-payload(it.body)
let payload = util.extract-payload(it.body)

core.super-figure-prepared(
kind-super: payload.kind,
Expand All @@ -31,8 +32,8 @@
// TODO: outline adjustement

show ref: it => {
if core.is-element(it.element, figure) and it.element.kind == core.keys.superfigure {
let payload = core.extract-payload(it.element.body)
if util.is-element(it.element, figure) and it.element.kind == core.keys.superfigure {
let payload = util.extract-payload(it.element.body)
link(it.element.location(), {
it.element.supplement
[ ]
Expand Down
17 changes: 17 additions & 0 deletions src/util.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#let is-element(value, func) = {
type(value) == content and value.func() == func
}

#let extract-payload(body) = {
if not body.has("children") { return }
if body.children.len() == 0 { return }

let first = body.children.first()

if not is-element(first, metadata) { return }
first.value
}

#let embed-payload(body, ..payload) = {
metadata(payload.named()) + body
}
File renamed without changes
2 changes: 1 addition & 1 deletion test/core/payload/test.typ → test/util/payload/test.typ
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import "/src/core.typ": embed-payload, extract-payload
#import "/src/util.typ": embed-payload, extract-payload

#set page(width: 1cm, height: 1cm)

Expand Down

0 comments on commit 7114ae1

Please sign in to comment.