jgm / skylighting

A Haskell syntax highlighting library with tokenizers derived from KDE syntax highlighting descriptions
189 stars 61 forks source link

Fix jgm/pandoc#9292 #193

Open lawcho opened 1 month ago

lawcho commented 1 month ago

This PR aims to fix https://github.com/jgm/pandoc/issues/9292

I'm not sure what the (-5 + 5) calculation was trying to do -- it [was added] in a commit about line numbers (#14), but doesn't seem to affect HTML rendering in firefox:

image

Weasyprint always renders the code better without:

image

Test source code:


<style>
body { columns: 2; }
div.sourceCode { border: 2pt solid black; }
.old {border: 1px solid red}
.new {border: 1px solid green}
.new pre > code.sourceCode > span {
  text-indent:  0 !important;
  padding-left: 0 !important;
}
</style>

:::: old

```{.haskell}
-- Here is some haskell code
-- which doesn't quite fit
-- into a 2-column layout
(>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c
(bs >=> cs) a = do
  b <- bs a
  cs b
-- Here is some haskell code
-- which doesn't quite fit
-- into a 2-column layout
(>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c
(bs >=> cs) a = do
  b <- bs a
  cs b

::::

:::: new

-- Here is some haskell code
-- which doesn't quite fit
-- into a 2-column layout
(>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c
(bs >=> cs) a = do
  b <- bs a
  cs b
-- Here is some haskell code
-- which doesn't quite fit
-- into a 2-column layout
(>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c
(bs >=> cs) a = do
  b <- bs a
  cs b

::::



HTML generated with `pandoc test.md --standalone --pdf-engine weasyprint -o out.html`

PDF generated with `pandoc test.md --standalone --pdf-engine weasyprint -o out.pdf`

[was added]: https://github.com/jgm/skylighting/commit/8a44b8613f5165ffeb917e5ebb28450b8a569d48#diff-fd5b0787fb5eb358b0149fbab54b772771099a796b33e40e8bcb1a2a8f819685R161
jgm commented 1 month ago

@dbaynard can you comment on what the +5 -5 is doing in the CSS?

pre > code.sourceCode > span { display: inline-block; text-indent: -5em; padding-left: 5em; }

This PR would remove it. I'm wondering if there are any potential bad consequences that I'm not seeing.

dbaynard commented 1 month ago

Hanging indent. It means code with and without line numbers should align in the same position.

It doesn't appear to be working, though, from this example — I can dig out the original examples, if needed?

jgm commented 1 month ago

It would be great to figure out whether this is doing anything important. If not, there's a benefit to removing it, as seen by the above case.

dbaynard commented 1 month ago

OK, it's going to take me a week to make time for this. I see my PRs from 2017 onwards include some examples, so I'll check those.

dbaynard commented 2 weeks ago

I've been delayed on this but it's on my list for July. Thanks for your patience.