question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Single empty line breaks are ignored

See original GitHub issue

I’m rendering some markdown line so:

import auth from '@react-native-firebase/auth';
import database from '@react-native-firebase/database';
 
async function onCreateAccount() {
  // Get the users ID
  const uid = auth().currentUser.uid;
  // ..

The rendering works fine, however there is no line break happening between the imports/function:

image

It looks like the line token plain child is an empty string, rather than a string with a single space. I’m able to get around this by doing:

<code>
              {tokens.map((line, i) => {

                // Ensure blank lines/spaces drop onto a new line
                if (line.length === 1 && line[0].content === '') {
                  line[0].content = ' ';
                }

                return (
                  <div {...getLineProps({ line, key: i })}>
                    {line.map((token, key) => {

Not sure if it’s a bug or something my end? There doesn’t seem to be an issue when it’s already within a line.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:7

github_iconTop GitHub Comments

4reactions
rwieruchcommented, Apr 28, 2020

I had a similar issue and the solution by @Ehesp fixed it for me. I think this is not in this library yet. See when I use the following markdown:

import abc from 'abc';

import zoo from 'zoo';

I get rendered what I wished for:

import abc from 'abc';

import zoo from 'zoo';

But when I copy and paste the code to my editor/IDE, I get:

import abc from 'abc';
import zoo from 'zoo';

without the line break. I can see it also on my blog that there is nothing “selected” as line in between:

Screenshot 2020-04-28 at 14 18 42

However, when I use the solution by @Ehesp with:

// Ensure blank lines/spaces drop onto a new line
if (line.length === 1 && line[0].content === '') {
  line[0].content = ' ';
}

it preserves the empty line when copy and pasting the code and it also shows it as something “empty” selected on my blog:

Screenshot 2020-04-28 at 14 20 21

I guess more people have this problem without noticing. Just wanted to mention it here again and thank @Ehesp 👍

1reaction
domharringtoncommented, Oct 6, 2021

Following the instructions here I was getting an empty line at the end of all of my code blocks:

image

To fix this, I modified this part of the example code:

{tokens.map((line, i) => (
  <div key={i} {...getLineProps({line, key: i})}>
    {line.map((token, key) => (
      <span key={key} {...getTokenProps({token, key})} />
    ))}
  </div>
))}

And I added a .filter() to remove empty lines:

{tokens.map((line, i) => (
  <div key={i} {...getLineProps({ line, key: i })}>
    {line
      .filter((l, k) => {
        return l.empty !== true;
      })
      .map((token, key) => (
        <span key={key} {...getTokenProps({ token, key })} />
      ))}
  </div>
))}

And this seemed to do the trick:

image

Hope this helps someone.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ignore double \newline on page break - LaTeX Stack Exchange
I am new to Latex, but it seems to me that people don't want to leave empty lines between paragraphs, but just have...
Read more >
Do all browsers ignore blank lines in html - Stack Overflow
Line returns in the HTML document are ignored. ... Line breaks are displayed, however, when text is tagged as preformatted text ( <pre>...
Read more >
Line breaks and blank spaces - Overleaf, Online LaTeX Editor
As you can see, single line break in the code acts as a space in text. However, leaving an empty line starts a...
Read more >
Remove empty lines and Line Breaks in text — oracle-tech
So to remove empty lines means replacing 2 sets of line breaks directly after one another, with a single set. E.g..
Read more >
rule-empty-line-before - Stylelint
This rule ignores rules that are the very first node in a source. The fix option can automatically fix all of the problems...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found