From 9258de653dbf9403b176149497f5c64255f57fa0 Mon Sep 17 00:00:00 2001 From: Razon Yang Date: Tue, 4 Jun 2024 14:30:37 +0800 Subject: [PATCH] feat: allow overriding `max_lines` parameter via `data-max-lines` attribute (#33) For example, ````markdown ```sh {data-max-lines=20} tree /path/to/large-folder ... ... ``` ```` fix: correct the max_lines calculation --- assets/mods/code-block-panel/js/panel.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/assets/mods/code-block-panel/js/panel.ts b/assets/mods/code-block-panel/js/panel.ts index 7fac659..bfb3407 100644 --- a/assets/mods/code-block-panel/js/panel.ts +++ b/assets/mods/code-block-panel/js/panel.ts @@ -48,8 +48,9 @@ export default class Panel { private maxLines() { const lines = this.lines() - if (params.max_lines > 0 && lines.length > params.max_lines) { - const offsetTop = lines[params.max_lines - 1].offsetTop + const maxLines = this.code.closest('.highlight')?.getAttribute('data-max-lines') ?? params.max_lines + if (maxLines > 0 && lines.length > maxLines) { + const offsetTop = lines[maxLines].offsetTop if (offsetTop > 0) { this.pre.style.maxHeight = this.maxHeight = offsetTop + 'px' }