fix: define renderCodeWithLineNumbers in script.js to resolve ReferenceError#436
Open
anshul23102 wants to merge 1 commit into
Open
fix: define renderCodeWithLineNumbers in script.js to resolve ReferenceError#436anshul23102 wants to merge 1 commit into
anshul23102 wants to merge 1 commit into
Conversation
…ceError (komalharshita#406) The fetchStarterCode callback called renderCodeWithLineNumbers(data.code) but the function was never defined, causing a ReferenceError that left the code panel blank after every View Code click. Added the missing function inside the detail-page block. It splits the code string by newline, then builds one div.code-line per line containing a span.line-number (gutter) and a span.line-content (code text), matching the CSS classes already defined in style.css. textContent is used for both spans so no markup in the source file can be interpreted as HTML.
|
@anshul23102 is attempting to deploy a commit to the komalsony234-1530's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary [required]
Clicking View Code on any project detail page crashed the JavaScript with
ReferenceError: renderCodeWithLineNumbers is not defined. ThefetchStarterCodecallback called this function to render the fetched code with a numbered gutter, but the function had never been implemented, so the code panel stayed blank after every click.This PR adds the missing
renderCodeWithLineNumbersfunction inside the detail-page block ofstatic/script.js. It splits the raw code string by newline and builds onediv.code-lineelement per line. Each row contains aspan.line-numberfor the gutter and aspan.line-contentfor the code text. These class names exactly match the CSS rules already defined instatic/style.css(.code-line,.line-number,.line-content), so the display renders correctly with no CSS changes required.textContentis used for both spans, which means any HTML-like content in the source files is displayed as literal text and cannot be interpreted by the browser.Related Issue [required]
Closes #406
Type of Change [required]
What Was Changed [required]
static/script.jsrenderCodeWithLineNumbersfunction inside the detail-page blockHow to Test This PR [required]
git checkout fix/render-code-with-line-numberspip install -r requirements.txtpython app.pypython tests/test_basic.pyExpected test output:
Test Results [required]
Self-Review Checklist [required]
feat/,fix/,docs/,data/,style/,test/python tests/test_basic.pyand all tests passprint()orconsole.log()debug statementsvardeclarations and ES5-compatible patterns per the project JS style guideNotes for Reviewer
The CSS classes
.code-line,.line-number, and.line-contentwere already defined instatic/style.css(lines 2824 to 2848) with the correct flex layout and gutter styling. The function was the only missing piece. UsingtextContentinstead ofinnerHTMLensures source files containing HTML or script tags are rendered safely as plain text.