Skip to content

Conversation

@westonruter
Copy link
Owner

@westonruter westonruter commented Apr 22, 2020

Fixes #79.
Fixes #78.

  • Use mark element to indicate highlighted lines.
  • Prefix class names.
  • Ensure Code block renders properly when no styles are loaded.
  • Prevent flash of unstyled content by printing stylesheet before first Code block.
  • Add Wrap Lines option, and ensure do not wrap by default for consistency.
  • Improve code style.

With styles (note the lack of highlights and extra line breaks):

image

Before without styles:

image

After without styles (with line spacing and highlights preserved):

image

Note this is in the Twenty Twenty theme which has a default style of:

mark {
	background-color: #eee;
	color: #222;
}

* Use CSS hack to force empty cell to show instead of line break
* Prefix class names
}

.hljs.shcb-line-numbers .shcb-loc > span {
padding-left: 0.75em;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this 0de9d10 and you'll knock out #78 also

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Humm. I'm not seeing line wrapping at all anymore.

Copy link
Contributor

@allejo allejo Apr 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may want to address #78 (comment) at this point. If we add white-space: pre-wrap to each line, then we'll get the wrapping behavior and adding display: table-cell to the span will fix the indentation.

diff --git a/style.css b/style.css
index 14033b3..5597986 100644
--- a/style.css
+++ b/style.css
@@ -5,6 +5,7 @@
 
 .hljs.shcb-code-table > .shcb-loc {
 	display: table-row;
+	white-space: pre-wrap;
 	width: 100%;
 }
 
@@ -18,6 +19,7 @@
 }
 
 .hljs.shcb-line-numbers .shcb-loc > span {
+	display: table-cell;
 	padding-left: 0.75em;
 }
 

Copy link
Contributor

@allejo allejo Apr 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment, I'm having a hard time getting the <code> to respect the <pre>'s padding. This is because when I use display: table, it will disregard a parent's padding for overflow and only respect the parent's boundary. Resulting in this behavior:

image

If you're open to changing our output from <pre><code> to <pre><div><code>, then that will let us have wrapping and overflow enabled very easily. The extra div would work because it will be a display: block, meaning it will respect the <pre>'s padding and if we add an overflow to the div, then <code> (a display: table) will respect the div's boundary. Thoughts?

(p.s. and if I'm not making sense, it's because I'm sleepy and can write up a better explanation in the morning 😅)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not against adding another div wrapper! Please amend the PR with what you have in mind.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look at a503c31 and let me know what you think. Improvements welcome!

@allejo
Copy link
Contributor

allejo commented Apr 23, 2020

If we do introduce the line wrapping option (which I just added to show how it'd work), I'm not sure how we want to handle that in Gutenberg. Do we want to modify the PlainText's attributes to make it nowrap?

@westonruter
Copy link
Owner Author

In regards to the wrapping I can see that regular block editor does line wrapping in the editor:

image

But on the frontend no wrapping is done:

image

Ah, but this is in Twenty Twenty. In Twenty Nineteen there is line wrapping on the frontend:

image

So the inconsistent line wrapping seems like an inconsistency in the themes.

Therefore, if we add a line wrapping option we'd need not only have it add line wrapping, but also to force line wrapping to be removed if not enabled.

@westonruter westonruter reopened this Apr 26, 2020
@westonruter
Copy link
Owner Author

@allejo your changes fix the line wrapping in Twenty Nineteen:

image

And in Twenty Twenty (which does not do line wrapping on the frontend), it also looks good:

image

@westonruter
Copy link
Owner Author

@allejo The Wrap Lines checkbox logic seems to be inverted:

image

vs:

image

@westonruter
Copy link
Owner Author

I'm not sure how we want to handle that in Gutenberg. Do we want to modify the PlainText's attributes to make it nowrap?

Yes, I suppose so?

Also, supply default values and proper types for attributes.
@westonruter
Copy link
Owner Author

If we do introduce the line wrapping option (which I just added to show how it'd work), I'm not sure how we want to handle that in Gutenberg. Do we want to modify the PlainText's attributes to make it nowrap?

I just implemented this using CSS in b4c09ce. Maybe there's a better way.

Also fixed the inversion I noted in #80 (comment).

This is feeling solid.

@allejo
Copy link
Contributor

allejo commented Apr 26, 2020

I just implemented this using CSS in b4c09ce. Maybe there's a better way.

I'm liking this implementation! Thanks for the fix

Copy link
Contributor

@allejo allejo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels pretty solid to me!

@westonruter

This comment has been minimized.

@westonruter
Copy link
Owner Author

I broke it in 28a8c20 somehow.


.hljs.shcb-code-table {
display: table;
width: 100%;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@allejo Is the width:100% required? I'm finding in some themes, like Twenty Fourteen, it causes a bit of horizontal scrolling even when line wrapping is enabled. Can we remove it?

Suggested change
width: 100%;

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Humm. Seems like it is needed. If line numbers are turned off and the contents don't cause any wrapping, then the table is not wide enough:

image

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found the problem with Twenty Fourteen: the .hljs element wasn't getting box-sizing:border-box, so the combination of width:100% and the padding resulted in an overflow. Fixed in e236851.

@westonruter westonruter changed the title Use mark element to indicate highlighted lines Use mark element to indicate highlighted lines, ensure formatting when styles omitted, add Wrap Lines option Apr 26, 2020
@westonruter westonruter merged commit ede8daa into master Apr 26, 2020
@westonruter westonruter deleted the use/mark branch April 26, 2020 19:37
@allejo allejo mentioned this pull request Feb 9, 2021
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.

Consider using mark elements to contain highlighted lines Wrapped lines are not indented properly

3 participants