-
Notifications
You must be signed in to change notification settings - Fork 19
One blank line in the code block when using highlight.js #191
Comments
What does the generated HTML look like? |
@mhulse it's here: http://legato.ninja |
I meant, line return. |
@mhulse Wow~It's very impressive to have animated solution, cool. I am not sure about what is |
Thanks. Replying from my phone. Try moving the pre and code tags on same line as the code sample. This should take care of your space. It's not pretty looking, but would tighten up the visual gap. Check to see if highlight.js has a trim L/R feature. But I think your best bet is to apply my suggested fix above. |
@mhulse It seems I found a solution here, but still don't know why. Solution is to write the code snippet follows It fixes the problem, but makes raw post not readable in terms of code snippet. |
@mhulse Thank you for your kind help. Yes, it(first solution) do fix this problem! I guess I need to search and learn what is |
Whitespace inside |
Glad to help. Trim is white space removal at beginning and end of strings. You can trim Right (trim R), Left (trim L), or both (trim) depending on Lang/function used. It's a long shot, but maybe highlight JS has an option for trimmin? Since your using JS anyway, you could prob write your own JS trim on the code/pre blocks. OTOH, like has been mentioned, white space is respected, so I think your best bet is to cram the lines or use fenced code and the jekyll highlighter. Personally, iirc, I've always crammed lines when I've run into this issue. Unfortunately it's been a while since I've thought about this scenario, so take what I'm saying with a grain of salt. :) |
This could work too (not tested):
Not sure if that looks any better though. :D Sometimes I do similar technique as above to kill white space from inbetween inline block elements. ;) |
@mhulse Thank you for your help. I have a happy day. |
@nternetinspired Thank you! Now I know it. |
Love the love! Thanks for jumping in, @mhulse! |
var y = document.querySelectorAll("pre code");
for(var i = 0; i < y.length; i++) {
y[i].innerHTML = y[i].innerHTML.replace("\n", "");
} Removes the first newline from each code block. |
I changed my syntax highlighter to highlight.js. It works, but there is always one blank line above the code . I can't find where to adjust it. highlight.js's CSS is:
.hljs {
display: block;
overflow-x: auto;
padding: 0.5em;
background: #23241f;
border-radius: 8px;
-webkit-text-size-adjust: none;
max-width: 600px;
font-size: 0.8em;
}
The text was updated successfully, but these errors were encountered: