-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Too much indentation in highlighted code in Weasyprint #9292
Comments
Weasyprint just produces a PDF using the CSS you provide. So this should just be a matter of adjusting the CSS to your taste. But you may need to study the HTML pandoc produces for highlighted blocks in order to figure out what CSS adjustments are needed. |
Keeping this issue as reference for others using Weasyprint and I could extract all styles related to highlighting: /* CSS for syntax highlighting */
pre > code.sourceCode {
white-space: pre;
position: relative;
}
pre > code.sourceCode > span {
line-height: 1.25;
}
pre > code.sourceCode > span:empty {
height: 1.2em;
}
.sourceCode {
overflow: visible;
}
code.sourceCode > span {
color: inherit;
text-decoration: inherit;
}
div.sourceCode {
margin: 1em 0;
}
pre.sourceCode {
margin: 0;
}
@media screen {
div.sourceCode {
overflow: auto;
}
}
@media print {
pre > code.sourceCode {
white-space: pre-wrap;
}
pre > code.sourceCode > span {
text-indent: -5em;
padding-left: 5em;
}
}
pre.numberSource code {
counter-reset: source-line 0;
}
pre.numberSource code > span {
position: relative;
left: -4em;
counter-increment: source-line;
}
pre.numberSource code > span > a:first-child::before {
content: counter(source-line);
position: relative;
left: -1em;
text-align: right;
vertical-align: baseline;
border: none;
display: inline-block;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
padding: 0 4px;
width: 4em;
background-color: #ffffff;
color: #a0a0a0;
}
pre.numberSource {
margin-left: 3em;
border-left: 1px solid #a0a0a0;
padding-left: 4px;
}
div.sourceCode {
color: #1f1c1b;
background-color: #ffffff;
}
@media screen {
pre > code.sourceCode > span > a:first-child::before {
text-decoration: underline;
}
} |
A work-around is to put this in my CSS file: /* Work around pandoc ticket #9292 */
pre > code.sourceCode > span {
text-indent: 0 !important;
padding-left: 0 !important;
} |
What is different than expected?
I enter a code block (e.g. Python) in a markdown file.
Then, I convert to a PDF with Pandoc (3.1.11, Mac Homebrew) with highlighting on (= default) with Weasyprint.
There is a huge margin before the actual code (see area with label (1) in screenshot):
I lose a lot of valuable space.
And it's odd that when the code line breaks, it does use this space. (see area with label (2) in screenshot)
What I tried to fix it myself?
No hightlight = no indentation
I checked what happens when I switch highlighting off (
--no-hightlight
).And sure enough, the indentation is as expected (no indentation at label (1)).
Add line numbers = total chaos
Next, I added line numbers via
python{.numberLines}
Try to fix CSS manually
I suspected the highlight wrapper
.sourceCode
and added some margin and padding resets:Well, did not really help:
Minimum reproducible setup
Run pandoc:
Python in Markdown:
CSS:
I don't have anything specific that could cause it in my custom CSS:
Why reporting as bug?
The text was updated successfully, but these errors were encountered: