Last active
January 28, 2025 10:14
-
-
Save hongjr03/51c79ace89c1827980f62cf306c7ffa3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #let hanging-indent(body, indent: 0.5em) = { | |
| let unpack(arr) = { | |
| if type(arr) == array { | |
| arr.map(it => unpack(it)) | |
| } else if repr(arr.func()) == "sequence" { | |
| unpack(arr.children) | |
| } else if repr(arr.func()) == "item" { | |
| if repr(arr.body.func()) == "sequence" { | |
| unpack(arr.body) | |
| } else { | |
| (arr.body, [ ]) | |
| } | |
| } else { | |
| arr | |
| } | |
| } | |
| show list: it => { | |
| let markers = it.marker | |
| let res = unpack(it.children) | |
| let dfs(arr, level) = { | |
| let res = () | |
| for elem in arr { | |
| if type(elem) == array { | |
| for el in dfs(elem, level + 1) { | |
| res.push(el) | |
| } | |
| } else if elem != [ ] { | |
| res.push(( | |
| level: level, | |
| body: elem, | |
| )) | |
| } | |
| } | |
| res | |
| } | |
| for elem in dfs(res, 0) { | |
| box(width: (elem.level - 1) * indent) | |
| markers.at(calc.rem(elem.level, markers.len()) - 1) | |
| h(it.body-indent) | |
| elem.body | |
| linebreak() | |
| } | |
| } | |
| body | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment