Skip to content
Open
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
8 changes: 4 additions & 4 deletions codly.typ
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
/// - skip-last-empty (bool, function): skip-last-empty
/// - breakable (bool): breakable
/// - skips (array, none, function): skips
/// - skip-line (content, none, function): skip-line
/// - skip-number (content, none, function): skip-number
/// - skip-line (content, none, array, function): skip-line
/// - skip-number (content, none, array, function): skip-number
/// - annotations (array, none, function): annotations
/// - annotation-format (none, function): annotation-format
/// - highlighted-lines (array, none, function): highlighted-lines
Expand Down Expand Up @@ -358,8 +358,8 @@
/// - skip-last-empty (bool, function): skip-last-empty
/// - breakable (bool): breakable
/// - skips (array, none, function): skips
/// - skip-line (content, none, function): skip-line
/// - skip-number (content, none, function): skip-number
/// - skip-line (content, none, array, function): skip-line
/// - skip-number (content, none, array, function): skip-number
/// - annotations (array, none, function): annotations
/// - annotation-format (none, function): annotation-format
/// - highlighted-lines (array, none, function): highlighted-lines
Expand Down
8 changes: 4 additions & 4 deletions src/args.json
Original file line number Diff line number Diff line change
Expand Up @@ -313,17 +313,17 @@
},
"skip-line": {
"title": "Skip line",
"description": "Sets the content with which the line code is filled when a skip is encountered.",
"description": "Sets the content with which the line code is filled when a skip is encountered. Can be a single content value applied to all skips, or an array of content values for individual skip formatting.",
"default": "align(center)[ ... ]",
"ty": [ "content", "type(none)" ],
"ty": [ "content", "type(none)", "array" ],
"function": true,
"example": "#codly(\n skips: ((4, 32), ),\n skip-line: align(center, emoji.face.shock)\n)\n```py\ndef fib(n):\n if n <= 1:\n return n\n return fib(n - 1) + fib(n - 2)\nfib(25)\n```"
},
"skip-number": {
"title": "Skip number",
"description": "Sets the content with which the line number columns is filled when a skip is encountered. If line numbers are disabled, this has no effect.",
"description": "Sets the content with which the line number columns is filled when a skip is encountered. If line numbers are disabled, this has no effect. Can be a single content value applied to all skips, or an array of content values for individual skip formatting.",
"default": "[ ... ]",
"ty": [ "content", "type(none)" ],
"ty": [ "content", "type(none)", "array" ],
"function": true,
"example": "#codly(\n skips: ((4, 32), ),\n skip-number: align(center, emoji.face.shock)\n)\n```py\ndef fib(n):\n if n <= 1:\n return n\n return fib(n - 1) + fib(n - 2)\nfib(25)\n```"
},
Expand Down
69 changes: 61 additions & 8 deletions src/lib.typ
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,10 @@
smart-skip.values().any((v) => v)
}

// Track the original number of skips for array indexing
let original-skip-count = skips.len()
let processed-skips = 0

let in-skip = false
let in-first = true
let had-first = false
Expand Down Expand Up @@ -1545,38 +1549,87 @@
// Try and look for a skip
let skip = skips.at(0, default: none)
if skip != none and line.number == skip.at(0) {
// Determine skip index for array access
let skip-index = processed-skips
processed-skips += 1

// Get skip-number content (array or single value)
let skip-number-content = if type(skip-number) == array {
skip-number.at(skip-index, default: skip-number.at(-1, default: [ ... ]))
} else {
skip-number
}

// Get skip-line content (array or single value)
let skip-line-content = if type(skip-line) == array {
skip-line.at(skip-index, default: skip-line.at(-1, default: align(center)[ ... ]))
} else {
skip-line
}

if numbers-format != none {
items.push(skip-number)
items.push(skip-number-content)
}

items.push(skip-line)
items.push(skip-line-content)
lines_to_number.push(-99999999);
// Advance the offset.
offset += skip.at(1)
_ = skips.remove(0)
} else if smart-skip-enabled and not in_range(ranges, line.number) and not in-skip {
if in-first {
if smart-skip-top {
// Smart skips use default values since they're not indexed
if numbers-format != none {
items.push(skip-number)
let skip-number-content = if type(skip-number) == array {
skip-number.at(-1, default: [ ... ])
} else {
skip-number
}
items.push(skip-number-content)
}
let skip-line-content = if type(skip-line) == array {
skip-line.at(-1, default: align(center)[ ... ])
} else {
skip-line
}
items.push(skip-line)
items.push(skip-line-content)
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 {
items.push(skip-number)
let skip-number-content = if type(skip-number) == array {
skip-number.at(-1, default: [ ... ])
} else {
skip-number
}
items.push(skip-number-content)
}
let skip-line-content = if type(skip-line) == array {
skip-line.at(-1, default: align(center)[ ... ])
} else {
skip-line
}
items.push(skip-line)
items.push(skip-line-content)
lines_to_number.push(-99999999);
}
} else {
if smart-skip-bot {
if numbers-format != none {
items.push(skip-number)
let skip-number-content = if type(skip-number) == array {
skip-number.at(-1, default: [ ... ])
} else {
skip-number
}
items.push(skip-number-content)
}
let skip-line-content = if type(skip-line) == array {
skip-line.at(-1, default: align(center)[ ... ])
} else {
skip-line
}
items.push(skip-line)
items.push(skip-line-content)
lines_to_number.push(-99999999);
}
}
Expand Down