Skip to content

Commit

Permalink
Fix oversized padding around code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
phacks committed Aug 1, 2018
1 parent beff9ea commit a5cc869
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions examples/using-remark/src/utils/typography.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,15 @@ const options = {
backgroundColor: `transparent`,
borderRadius: 0,
margin: 0,
padding: 0,
overflow: `initial`,
float: `left`,
minWidth: `100%`,
textShadow: `none`,
},
".gatsby-highlight pre[class*='language-'].line-numbers": {
paddingLeft: `2.8em`,
},
".gatsby-highlight-code-line": {
background: `#fff2cc`,
display: `block`,
Expand Down
5 changes: 5 additions & 0 deletions packages/gatsby-remark-prismjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,19 @@ CSS along your PrismJS theme and the styles for `.gatsby-highlight-code-line`:
* padding and overflow.
* 1. Make the element just wide enough to fit its content.
* 2. Always fill the visible space in .gatsby-highlight.
* 3. Adjust the position of the line numbers
*/
.gatsby-highlight pre[class*="language-"] {
background-color: transparent;
margin: 0;
padding: 0;
overflow: initial;
float: left; /* 1 */
min-width: 100%; /* 2 */
}
.gatsby-highlight pre[class*="language-"].line-numbers {
paddingLeft: 2.8em; /* 3 */
}
```

#### Optional: Add line numbering
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ const addLineNumbers = require(`../add-line-numbers`)
describe(`returns the line numbers container`, () => {
it(`should return the <span> container with the right classes`, () => {
expect(addLineNumbers(``)).toEqual(
`<span aria-hidden="true" class="line-numbers-rows" style="white-space: normal; top:1em; left:0;">`
`<span aria-hidden="true" class="line-numbers-rows" style="white-space: normal; width: auto; left: 0;">`
+ `</span>`
)
})
it(`should return return as many <span></span> children as there are code lines`, () => {
expect(addLineNumbers(`line1\nline2\nline3`)).toEqual(
`<span aria-hidden="true" class="line-numbers-rows" style="white-space: normal; top:1em; left:0;">`
`<span aria-hidden="true" class="line-numbers-rows" style="white-space: normal; width: auto; left: 0;">`
+ `<span></span><span></span><span></span>`
+ `</span>`
)
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-remark-prismjs/src/add-line-numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = (code = []) => {
// Relevant code in the Prism Line Numbers plugin can be found here:
// https://github.com/PrismJS/prism/blob/f356dfe71bf126e6dc060c03f3e042de28a9bec4/plugins/line-numbers/prism-line-numbers.js#L99-L115
const lineNumbersWrapper =
`<span aria-hidden="true" class="line-numbers-rows" style="white-space: normal; top:1em; left:0;">`
`<span aria-hidden="true" class="line-numbers-rows" style="white-space: normal; width: auto; left: 0;">`
+ `${generateSpans(numberOfLines)}`
+ `</span>`
return lineNumbersWrapper
Expand Down

0 comments on commit a5cc869

Please sign in to comment.