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

[code copy]: shell lang code block remove trailing newline #1559

Closed
4 tasks done
Zhengqbbb opened this issue Oct 30, 2022 · 1 comment
Closed
4 tasks done

[code copy]: shell lang code block remove trailing newline #1559

Zhengqbbb opened this issue Oct 30, 2022 · 1 comment

Comments

@Zhengqbbb
Copy link
Contributor

Zhengqbbb commented Oct 30, 2022

Is your feature request related to a problem? Please describe.

let { innerText: text = '' } = sibling
if (isShell) {
text = text.replace(/^ *(\$|>) /gm, '')
}

Use innerText will include element properties. Like block element will make text with trailing newline \n

Describe the solution you'd like

code copy remove trailing newline

And I'm not sure if all lang code copy should remove this hidden problem.

But should be removed in the shell lang . Because in SHELL env (like bash) or some termianl apps, there is a trailing newline in our copy, the command will to be executed directly after paste, which is dangerous.

Describe alternatives you've considered

If maintainer agree, I will submit a PR

if (isShell)
  text = text.replace(/^ *($|>) /gm, '').replace(/[\n\r]$/, '')

Additional context

No response

Validations

@brc-dd
Copy link
Member

brc-dd commented Oct 30, 2022

Yeah I agree it's dangerous. Better directly put .trim() there. Feel free to create a PR! 🙌

@brc-dd brc-dd closed this as completed Oct 31, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants