Skip to content

Commit

Permalink
Fix line spacing and overflowing content in generated html (#25)
Browse files Browse the repository at this point in the history
* Fix empty line height, explicitly
* Ensure long lines scroll on screen
* Only apply colour to the outer div
* Don't reset line number colour
* Fix borders on empty code lines

See jgm/pandoc#4128
  • Loading branch information
dbaynard authored and jgm committed Dec 10, 2017
1 parent 8b8f028 commit 6bfd86c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Skylighting/Format/HTML.hs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ styleToCss f = unlines $
divspec ++ numberspec ++ colorspec ++ linkspec ++
sort (map toCss (Map.toList (tokenStyles f)))
where colorspec = [
"div.sourceCode, pre.sourceCode, code.sourceCode\n { "
"div.sourceCode\n { "
++ case (defaultColor f, backgroundColor f) of
(Nothing, Nothing) -> ""
(Just c, Nothing) -> "color: " ++ fromColor c ++ ";"
Expand All @@ -154,6 +154,8 @@ styleToCss f = unlines $
numberspec = [
"pre.numberSource a.sourceLine"
, " { position: relative; }"
, "pre.numberSource a.sourceLine:empty"
, " { position: absolute; }"
, "pre.numberSource a.sourceLine::before"
, " { content: attr(data-line-number);"
, " position: absolute; left: -5em; text-align: right; vertical-align: baseline;"
Expand All @@ -172,17 +174,21 @@ styleToCss f = unlines $
" padding-left: 4px; }"
]
divspec = [
"a.sourceLine { display: inline-block; min-height: 1.25em; }"
"a.sourceLine { display: inline-block; line-height: 1.25; }"
, "a.sourceLine { pointer-events: none; color: inherit; text-decoration: inherit; }"
, "a.sourceLine:empty { height: 1.2em; position: absolute; }" -- correct empty line height
, ".sourceCode { overflow: visible; }" -- needed for line numbers
, "code.sourceCode { white-space: pre; }"
, "code.sourceCode { white-space: pre; position: relative; }" -- position relative needed for absolute contents
, "@media screen {"
, "div.sourceCode { overflow: auto; }" -- do not overflow on screen
, "}"
, "@media print {"
, "code.sourceCode { white-space: pre-wrap; }"
, "a.sourceLine { text-indent: -1em; padding-left: 1em; }"
, "}"
]
linkspec = [ "@media screen {"
, "a.sourceLine::before { text-decoration: underline; color: initial; }"
, "a.sourceLine::before { text-decoration: underline; }"
, "}"
]

Expand Down

0 comments on commit 6bfd86c

Please sign in to comment.