Skip to content
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

Update stylesheet for code blocks with line-numbers #1596

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

atusy
Copy link
Contributor

@atusy atusy commented Jul 4, 2019

This PR update stylesheet for code blocks with line-numbers.
Examples are at the bottom.

Changes

Background of <div class="sourceCode"> is changed to transpreant.

In some syntax highlighting, background color of <div class="sourceCode"> are specified (e.g., tango)
This cause ugly appearance especially in theme: darkly
As long as line numbers are not used, background color of the div tags are not visible.
Thus, I considered it is okay to letting them transparent.

Background of pre for chunk output are changed to white

Previously, specifying class.output="numberLines" caused output code block to have gray background where white is expected.
This is fixed by exact matching of class attributes.
Thus, white background are only applied when

  • pre has no class (just like before)
  • pre has the classes only related to line numbering on code blocks.

The latter is approached by the exact matching of classes.
Exact matching is required for the backward compatibility.
Otherwise, Bootstrap would not work to fill background colors for example by class.output = "numberLines bg-warning".

Note

If the output pre tag has the lineAnchors class, but not the numberLines, it is filled with gray.
Because line numbering is not working.

Examples

Before

image

After

image

Source

---
output: 
  html_document:
    highlight: tango
    theme: darkly
---

## Code blocks with line numbers

`class.source='numberLines'` and `class.output='numberLines'`

```{r, class.source='numberLines', class.output='numberLines'}
"hello"
```

`class.output='numberLines lineAnchors'`

```{r, class.source='numberLines', class.output='numberLines lineAnchors', echo = FALSE}
"hello"
```

`class.output='lineAnchors numberLines'`

```{r, class.source='numberLines', class.output='lineAnchors numberLines', echo = FALSE}
"hello"
```

`class.output='lineAnchors'`

```{r, class.source='numberLines', class.output='lineAnchors', echo = FALSE}
"hello"
```

## Bootstrap friendly

`class.output='numberLines bg-warning'` properly applies Bootstrap's `bg-warning` class to style background.

```{r class.output='numberLines bg-warning', echo = FALSE}
"hello"
```

@atusy
Copy link
Contributor Author

atusy commented Jul 6, 2019

As long as line numbers are not used, background color of the div tags are not visible.

I just noticed the background color of the div is visible even in the line numbers are not used.
It appears at the outside of rounded corners of pre and making the corners as if squared.

@atusy
Copy link
Contributor Author

atusy commented Jul 6, 2019

My update CSS in the below looks too fat.

  pre:not([class]),
  pre[class="sourceCode numberSource numberLines"],
  pre[class="sourceCode numberSource numberLines lineAnchors"],
  pre[class="sourceCode numberSource numberLines line-anchors"],
  pre[class="sourceCode numberSource number-lines"],
  pre[class="sourceCode numberSource number-lines lineAnchors"],
  pre[class="sourceCode numberSource number-lines line-anchors"],
  pre[class="sourceCode numberSource lineAnchors numberLines"],
  pre[class="sourceCode numberSource lineAnchors number-Lines"],
  pre[class="sourceCode numberSource line-anchors numberLines"],
  pre[class="sourceCode numberSource line-anchors number-lines"] {
    background-color: white;
  }

I feel I can remove the lines mixing up camelCases and kebab-cases, which is a bad manner and most users won't do it (I hope).

  pre:not([class]),
  pre[class="sourceCode numberSource numberLines"],
  pre[class="sourceCode numberSource numberLines lineAnchors"],
  pre[class="sourceCode numberSource lineAnchors numberLines"],
  pre[class="sourceCode numberSource number-lines"],
  pre[class="sourceCode numberSource number-lines line-anchors"],
  pre[class="sourceCode numberSource line-anchors number-lines"] {
    background-color: white;
  }

What do you think?

@atusy
Copy link
Contributor Author

atusy commented Jul 7, 2019

Background of <div class="sourceCode"> is changed to transpreant.

This part is approached by #1598, and thus is reverted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant