From 230d4e1d6cd94f6f589defc859ef295f1aa9b0fa Mon Sep 17 00:00:00 2001 From: "Jo. Adly" Date: Thu, 18 Sep 2025 19:46:43 +0300 Subject: [PATCH] added array for skip-line and skip-number --- codly.typ | 8 +++--- src/args.json | 8 +++--- src/lib.typ | 69 +++++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 69 insertions(+), 16 deletions(-) diff --git a/codly.typ b/codly.typ index 39c18ab..dfb9583 100644 --- a/codly.typ +++ b/codly.typ @@ -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 @@ -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 diff --git a/src/args.json b/src/args.json index 7ed868c..19a0de5 100644 --- a/src/args.json +++ b/src/args.json @@ -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```" }, diff --git a/src/lib.typ b/src/lib.typ index 30f072e..4e3b562 100644 --- a/src/lib.typ +++ b/src/lib.typ @@ -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 @@ -1545,11 +1549,29 @@ // 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) @@ -1557,26 +1579,57 @@ } 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); } }