Skip to content

Commit

Permalink
feat: allow overriding max_lines parameter via data-max-lines att…
Browse files Browse the repository at this point in the history
…ribute (#33)

For example,

````markdown
```sh {data-max-lines=20}
tree /path/to/large-folder
...
...
```
````

fix: correct the max_lines calculation
  • Loading branch information
razonyang authored Jun 4, 2024
1 parent 912077f commit 9258de6
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions assets/mods/code-block-panel/js/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down

0 comments on commit 9258de6

Please sign in to comment.