-
-
Notifications
You must be signed in to change notification settings - Fork 9k
extra empty line was rendered with // highlight-end
at end of code blocks
#11036
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
Comments
We have padding at the top or bottom of code blocks, although this is not visually the best, this is the current behavior. However it's not supposed to create a new line. I'm not able to reproduce the case where it creates a new line, can you provide a runnable https://docusaurus.new repro please? For me, both of your code blocks render exactly the same: Do you have custom CSS or remark plugins that could cause trouble? Can this be related to characters/encoding? Maybe try a simpler code block using non-chinese content. |
@slorber Oh! I think I found the reason. I'm working on a Windows computer, so the default line break is On repro link: https://codesandbox.io/p/sandbox/wild-glitter-z3djmr (in this file: docs/intro.md) |
@slorber I found that in CodeBlockString component called docusaurus/packages/docusaurus-theme-classic/src/theme/CodeBlock/Content/String.tsx Lines 59 to 63 in c0f3755
the
maybe we need 👇to support CRLF? let code = content.replace(/\r?\n$/, ''); a simple test case: // .replace(/\n$/, '')
"\r\n123\r\n123\r\n".replace(/\n$/, '') // result: '\r\n123\r\n123\r' (❌)
"\n123\n123\n".replace(/\n$/, '') // result: '\n123\n123'
// .replace(/\n$/, '')
"\r\n123\r\n123\r\n".replace(/\r?\n$/, '') // result: '\r\n123\r\n123' (✅)
"\n123\n123\n".replace(/\r?\n$/, '') // result: '\n123\n123' And here
maybe we need const lines = code.split(/\r?\n/); a simple test case: // .split('\n')
"\r\n123\r\n123\r\n".split('\n') // result: ['\r', '123\r', '123\r', ''] (❌)
"\n123\n123\n".split('\n') // result: ['', '123', '123', '']
// .split(/\r?\n/)
"\r\n123\r\n123\r\n".split(/\r?\n/) // result: ['', '123', '123', ''] (✅)
"\n123\n123\n".split(/\r?\n/) // result: ['', '123', '123', ''] |
…highlight-end at end of code blocks See: facebook#11036
…11046) * fix: with CRLF line breaks, an extra empty line was rendered with // highlight-end at end of code blocks See: #11036 * Add unit tests --------- Co-authored-by: sebastien <[email protected]>
Have you read the Contributing Guidelines on issues?
Prerequisites
npm run clear
oryarn clear
command.rm -rf node_modules yarn.lock package-lock.json
and re-installing packages.Description
extra empty line was rendered with
// highlight-end
at end of code blocksReproducible demo
No response
Steps to reproduce
try this markdown
there will be an extra empty line at end of code blocks like this:
but if I set the end line in this style, the result is corrent:
Expected behavior
no extra line was rendered
Actual behavior
an extra line was rendered
Your environment
Self-service
The text was updated successfully, but these errors were encountered: