Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions src/lib.typ
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
/// ```
///
/// - offset (int): the offset to apply to the code block
///
///
/// -> content
#let codly-offset(offset: 0) = {
(__codly-args.offset.update)(offset)
Expand All @@ -71,7 +71,7 @@
///
/// - start (int): the start of the displayed range
/// - end (none, int): the end of the displayed range, none for the rest of the block
///
///
/// -> content
#let codly-range(
start,
Expand All @@ -98,7 +98,7 @@
/// ```
/// Hello, world!
/// ```
///
///
/// -> content
#let codly-disable() = {
(__codly-args.enabled.update)(false)
Expand All @@ -121,7 +121,7 @@
/// ```
/// Hello, world!
/// ```
///
///
/// -> content
#let codly-enable() = {
(__codly-args.enabled.update)(true)
Expand All @@ -139,7 +139,7 @@
/// #no-codly(```
/// Hello, world!
/// ```)
///
///
/// -> content
#let no-codly(body) = {
(__codly-args.enabled.update)(false)
Expand All @@ -160,7 +160,7 @@
/// #yes-codly(```
/// Hello, world!
/// ```)
///
///
/// -> content
#let yes-codly(body) = {
(__codly-args.enabled.update)(true)
Expand All @@ -175,10 +175,10 @@
/// Hello, world!
/// Goodbye, world!
/// ```
///
///
/// - position (int): the line at which to insert the skip
/// - length (int): the number of lines the skip is long
///
///
/// -> content
#let codly-skip(
position,
Expand Down Expand Up @@ -710,7 +710,7 @@
)(if "highlight-inset" in extra {
extra.highlight-inset
} else {
state("highlight-inset", __codly-args.highlight-inset.default).get()
state("codly-highlight-inset", __codly-args.highlight-inset.default).get()
});

show raw.line.where(label: <codly-highlighted>): codly-line.with(
Expand Down Expand Up @@ -974,7 +974,7 @@
skips.sorted(key: x => x.at(0)).dedup()
}
}

let highlighted-lines = (
__codly-args.highlighted-lines.type_check
)(if "highlighted-lines" in extra {
Expand All @@ -993,7 +993,7 @@

let highlighted-by-line = ()
if highlighted-lines == none {

} else if type(highlighted-lines) == array {
if highlighted-lines.len() > 0 {
let ix = 1
Expand All @@ -1004,7 +1004,7 @@
assert(l.len() == 2, message: "codly: a highlighted line definition must be an integer or an array of two elements: the line, and the highlight color (array length mismatch)")
let ln = l.at(0)
assert(type(ln) == int, message: "codly: the type of a `highlighted-lines` line must be either an integer, found: " + str(type(ln)));

let col = l.at(1)
assert(
type(col) == color or type(col) == gradient or type(col) == pattern,
Expand Down Expand Up @@ -1423,7 +1423,7 @@
let smart-skip-enabled = if type(smart-skip) == bool {
smart-skip
} else {
smart-skip.values().any((v) => v)
smart-skip.values().any((v) => v)
}

let in-skip = false
Expand Down Expand Up @@ -1457,7 +1457,7 @@
// Try and look for a skip
let skip = skips.at(0, default: none)
if skip != none and line.number == skip.at(0) {
if numbers-format != none {
if numbers-format != none {
items.push(skip-number)
}

Expand All @@ -1469,23 +1469,23 @@
} else if smart-skip-enabled and not in_range(ranges, line.number) and not in-skip {
if in-first {
if smart-skip-top {
if numbers-format != none {
if numbers-format != none {
items.push(skip-number)
}
items.push(skip-line)
lines_to_number.push(-99999999);
}
} else if array.range(line.number, line.count).any((i) => in_range(ranges, i)) {
if smart-skip-rest {
if numbers-format != none {
if numbers-format != none {
items.push(skip-number)
}
items.push(skip-line)
lines_to_number.push(-99999999);
}
} else {
if smart-skip-bot {
if numbers-format != none {
if numbers-format != none {
items.push(skip-number)
}
items.push(skip-line)
Expand Down Expand Up @@ -1530,7 +1530,7 @@
// Must be done before the smart indentation code.
// Otherwise it results in two paragraphs.
if numbers-format != none {
items.push(numbers-format(line.number + offset))
items.push(numbers-format(line.number + offset))
}

let annot = none
Expand Down Expand Up @@ -1568,7 +1568,7 @@
annot-content,
)
}

if had-first or (
display-names != true and display-icons != true
) {
Expand Down Expand Up @@ -1695,7 +1695,7 @@
type(zebra-color) != color and zebra-color != none
)
)

let width_lines_number = calc.max(2, (calc.ceil(calc.log(it.lines.len())) + 1)) * 1em

let line_colors = ()
Expand Down Expand Up @@ -1748,7 +1748,7 @@
(auto, 1fr)
},
inset: padding.pairs().map(((k, x)) => (k, x * 1.5)).to-dict(),
stroke: (x,y) =>
stroke: (x,y) =>
if numbers-outside {
let idx_end = if has-annotations {
2
Expand All @@ -1770,7 +1770,7 @@
none
} else {
(x, y) => if numbers-outside and x == 0 {
none
none
} else {
line_colors.at(y, default: fill)
}
Expand Down Expand Up @@ -1801,9 +1801,9 @@
}
},
)

block_content

figure(
kind: "__codly-end-block",
supplement: none,
Expand Down Expand Up @@ -1868,9 +1868,9 @@
/// ```typ
/// #show: codly-init
/// ```
///
///
/// - body (content): the body of the document
///
///
/// -> content
#let codly-init(
body,
Expand Down
38 changes: 34 additions & 4 deletions tests/issues/22-highlight-align.typ
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,39 @@
#set page(width: 300pt, height: auto)
#show: codly-init.with()

#codly(highlight-inset: (x: 0pt, y: 0.32em))
#codly(
display-icon: false,
display-name: false,
)

#grid(columns: 3)[
#codly(highlights: ((line: 2, start: 0, end: none), ))
```kotlin
private val n = 0
private val n = 0
```
val n = 0
val n = 0
```
][
#codly(highlights: ((line: 1, start: 0, end: none), ))
#local(
highlight-inset: 0em,
highlight-outset: 0.32em,
highlight-clip: true,
)[
```kotlin
val n = 0
val n = 0
```
]
][
#codly(highlights: ((line: 2, start: 0, end: none), ))
#local(
highlight-inset: 0em,
highlight-outset: 0.32em,
highlight-clip: true,
)[
```kotlin
val n = 0
val n = 0
```
]
]
Binary file modified tests/issues/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading