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

How to keep line breaks #28

Open
fliak opened this issue Mar 23, 2023 · 4 comments
Open

How to keep line breaks #28

fliak opened this issue Mar 23, 2023 · 4 comments

Comments

@fliak
Copy link

fliak commented Mar 23, 2023

Guys could you provide help, how to keep line breaks.
I have a text with paragraphs

<p>First sentence</p>\n<p>Next one</p>

I want to satanize it for Telegram bot which don't like <p>, but seems that paired tags cannot be transformed to something like \n.
Line breaks \nin original text also become wiped.

I'll be grateful for any ideas

@bymoses
Copy link

bymoses commented May 26, 2023

There's no such option to disable whitespace normalization here. Idk why so.

I faced the same issue with telegram, so I used this random.choice(['dirty', 'ugly', 'stinky', 'nasty']) workaround:

initial_text = "<strong>kek</strong>\n\n<s>lol</s>"

message = Sanitizer({
  "tags": {'a', 'br', 'b', 'strong', 'i', 'em', 'code', 's', 'strike', 'del', 'u'},
  "attributes": {},
  "whitespace": {},
  'empty': {'a', 'br'},
  'separate': {'br'},
}).sanitize(initial_text.replace("\n", "<br>")).replace("<br>", "\n")

bot.send_message(message)

@chwilko
Copy link

chwilko commented Jan 3, 2024

I have similar problem with

<code>
git status
git add
git commit
</code> 

@matthiask
Copy link
Owner

"keep_typographic_whitespace": True may help?

matthiask added a commit that referenced this issue Jan 3, 2024
@Paillat-dev
Copy link

+1 on this, I am integrating user-inputted <code> blocks and I need to keep linebreaks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants