Skip to content

Tutorial extra empty line bug #662

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

Closed
2 tasks done
Kyle-Ye opened this issue May 16, 2023 · 2 comments · Fixed by #667
Closed
2 tasks done

Tutorial extra empty line bug #662

Kyle-Ye opened this issue May 16, 2023 · 2 comments · Fixed by #667
Labels
bug Something isn't working

Comments

@Kyle-Ye
Copy link
Contributor

Kyle-Ye commented May 16, 2023

Description

Extra line is render for code in tutorial.

Checklist

  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue.

Expected Behavior

Show the correct highlighting for Line 25-29

image image
{
  "content": [...],
  "fileName": "CustomizedSlothView.swift",
  "fileType": "swift",
  "highlights": [
    {
      "line": 25
    },
    {
      "line": 26
    },
    {
      "line": 27
    },
    {
      "line": 28
    },
    {
      "line": 29
    }
  ],
  "identifier": "01-creating-code-02-08.swift",
  "syntax": "swift",
  "type": "file"
}

Actual behavior

Show the wrong highlighting (Due to extra empty line on Line 4 and Line 5).

There should be only 1 empty line (Line 3). Currently there will be 3 empty line(Line 3 - Line 5)

image

Steps To Reproduce

The tutorial resource can be downloaded from https://developer.apple.com/documentation/xcode/slothcreator_building_docc_documentation_in_xcode

Swift-DocC-Render Version Information

No response

@Kyle-Ye Kyle-Ye added the bug Something isn't working label May 16, 2023
@Kyle-Ye
Copy link
Contributor Author

Kyle-Ye commented May 16, 2023

The original json info is the following:

"/*",
"See LICENSE folder for this sample’s licensing information.",
"",
"Abstract:",

And the 3rd element should be <span class="syntax-comment"></span>.

Currently it occupied 3 elements. And this is why we have 2 extra new empty line.

image

@Kyle-Ye
Copy link
Contributor Author

Kyle-Ye commented May 16, 2023

Looks like this is a bug in the implementation of highlightContent in src/utils/syntax-highlight.js

const result = getLines(element.innerHTML)
  .reduce((all, lineText) => `${all}<span class="${className}">${lineText || '\n\n'}</span>\n`, '');

This question can turn into this js issue:

var a = ['/*', 'S', '', 'A', '*/']
var className = "syntax-comment"
const result = a
    .reduce((all, lineText) => `${all}<span class="${className}">${lineText || '\n\n'}</span>\n`, '');
console.log(result)
// Expected output:
<span class="syntax-comment">/*</span>
<span class="syntax-comment">S</span>
<span class="syntax-comment"></span>
<span class="syntax-comment">A</span>
<span class="syntax-comment">*/</span>
// Current output
<span class="syntax-comment">/*</span>
<span class="syntax-comment">S</span>
<span class="syntax-comment">

</span>
<span class="syntax-comment">A</span>
<span class="syntax-comment">*/</span>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant