Skip to content

Commit e77680d

Browse files
committed
Added a property to tweak the design of code listings
1 parent 4475ac5 commit e77680d

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/Renderers/CodeNodeRenderer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ public function render(): string
8383
'languageMapping' => self::LANGUAGES_MAPPING[$language] ?? $language,
8484
'code' => $code,
8585
'lineNumbers' => rtrim($lineNumbers),
86+
// this is the number of digits of the codeblock lines-of-code
87+
// e.g. LOC = 5, digits = 1; LOC = 18, digits = 2
88+
// this is useful to tweak the code listings according to their length
89+
'numLocDigits' => (int) floor(log10(\count($lines))) + 1,
8690
]
8791
);
8892
}

src/Templates/default/html/code.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="literal-block">
1+
<div class="literal-block loc-{{ numLocDigits }}">
22
<div class="highlight-{{ language }}">
33
<table class="highlighttable">
44
<tr>

0 commit comments

Comments
 (0)