From 7114ae1c8cb9aa806ad88c5487c188f382c0ae87 Mon Sep 17 00:00:00 2001 From: tinger Date: Thu, 18 Apr 2024 14:48:40 +0200 Subject: [PATCH] Add util module --- src/core.typ | 22 +++------------------- src/lib.typ | 7 ++++--- src/util.typ | 17 +++++++++++++++++ test/{core => util}/payload/ref/1.png | Bin test/{core => util}/payload/test.typ | 2 +- 5 files changed, 25 insertions(+), 23 deletions(-) create mode 100644 src/util.typ rename test/{core => util}/payload/ref/1.png (100%) rename test/{core => util}/payload/test.typ (82%) diff --git a/src/core.typ b/src/core.typ index b238916..a3cb766 100644 --- a/src/core.typ +++ b/src/core.typ @@ -1,3 +1,5 @@ +#import "util.typ" as _util + #let keys = ( superfigure: "__subpar:superfigure-unprepared", counter: "__subpar:subfigure-counter", @@ -5,24 +7,6 @@ #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, @@ -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, diff --git a/src/lib.typ b/src/lib.typ index f381764..97e6a4e 100644 --- a/src/lib.typ +++ b/src/lib.typ @@ -1,4 +1,5 @@ #import "core.typ" +#import "util.typ" #let super-figure = core.super-figure-unprepared @@ -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, @@ -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 [ ] diff --git a/src/util.typ b/src/util.typ new file mode 100644 index 0000000..2953b98 --- /dev/null +++ b/src/util.typ @@ -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 +} diff --git a/test/core/payload/ref/1.png b/test/util/payload/ref/1.png similarity index 100% rename from test/core/payload/ref/1.png rename to test/util/payload/ref/1.png diff --git a/test/core/payload/test.typ b/test/util/payload/test.typ similarity index 82% rename from test/core/payload/test.typ rename to test/util/payload/test.typ index 2f301c4..bdd2700 100644 --- a/test/core/payload/test.typ +++ b/test/util/payload/test.typ @@ -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)