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

Formatting (newlines and indentation) lost after parsing #3242

Closed
wolfiex opened this issue Jun 14, 2021 · 2 comments
Closed

Formatting (newlines and indentation) lost after parsing #3242

wolfiex opened this issue Jun 14, 2021 · 2 comments
Labels
bug help welcome Could use help from community parser

Comments

@wolfiex
Copy link

wolfiex commented Jun 14, 2021

Describe the issue/behavior that seems buggy
The newline formatting and indentation of the code is lost after parsing with hilight.

Sample Code or Instructions to Reproduce
Starting with a string literal:

  north_row = num_rows
  DO i = num_rows, 1, - 1
    IF (ANY(frame_mask(:, i))) THEN
      EXIT
    END IF
  END DO

I run the following

code.innerHTML = hljs.highlight(data.code, {language: 'f90'}).value

which results in no newlines and a loss of indentation.

I am able to fix the newlines by appending .replace(/\n/g,' <br> ') to the end, but have had no such luck regarding the initial indentation.

Update:

Inline indentation can be achieved through

hljs.highlight(data.code.replace(/  /g,' --- '), {language: 'f90'}).value.replace(/\n/g,' <br>').replace(/ --- /g,'&nbsp;&nbsp;')

It almost feels like this should be done in the background, with a possible argument/switch.


@wolfiex wolfiex added bug help welcome Could use help from community parser labels Jun 14, 2021
@joshgoebel
Copy link
Member

joshgoebel commented Jun 14, 2021

Are you putting this content in <pre><code> block? That is the happy path. If you're doing something else then yes you need to jump thru a lot of hoops to deal with spacing and newlines and things you get for "free" when on the happy path.

Indents

We do no special processing of tabs (or spacing)... if you want to convert them to spaces, you need to do that yourself. If you want to style them with CSS (usually simpler) you can use tab-size. But if you're just putting spaces into normal HTML - again HTML doesn't care (it will squash them all to a single space, as HTML does).

Newlines

Newlines (typically) mean nothing in HTML outside of <pre> . If you're having to add <br> yourself then I'd guess you're not using <pre>, in which case - yes, that's just what you must do.


If you don't want to deal with these things, use <pre><code> blocks as strongly recommended by our docs.

@wolfiex
Copy link
Author

wolfiex commented Jun 15, 2021

I was using the code block but has forgotten the preformatted text element.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help welcome Could use help from community parser
Projects
None yet
Development

No branches or pull requests

2 participants