site banner

Small-Scale Question Sunday for February 2, 2025

Do you have a dumb question that you're kind of embarrassed to ask in the main thread? Is there something you're just not sure about?

This is your opportunity to ask questions. No question too simple or too silly.

Culture war topics are accepted, and proposals for a better intro post are appreciated.

1
Jump in the discussion.

No email address required.

How can I escape the tilde character on this site? Backslash does not appear to function in actual posts - just in the comment preview.

test test
\test\ test
/test/ /test/
test test
~test test
test test~~

lol

strikethrough_regex = re.compile('''~{1,2}([^~]+)~{1,2}''', flags=re.A)

Used here

# turn ~something~ or ~~something~~  into <del>something</del>
sanitized = strikethrough_regex.sub(r'<del>\1</del>', sanitized)

Anyway maybe like ~this~?

Which looks like &amp;#126;this&amp;#126;

In unrelated news I'm not sure how much I trust the variable named sanitized to contain what it says on the tin.

ETA: In accordance with the new rules on AI, disclaimer that the escape sequences for tildes was AI generated (and then I verified that the proposal worked).

Ah, the wonders of HTML character entities. Thank you!

~test~

`~test~` ~test~  
`\~test\~` \~test\~  
`/~test/~` /~test/~  
`~~test~~` ~~test~~  
`~~~test~~~ ` ~~~test~~~  
`~~~~test~~~~ ` ~~~~test~~~~

Huh. Doesn't work in the comment preview, but does in the final comment.

Also I really don't trust that comment-parsing code you linked.

On inspection it looks like the "strip disallowed html tags and attributes" step happens after all the sketchy regex stuff so it's probably fine.

Wait, it gets worse. It appears to have escaping problems even inside code tags? For reference, the source of the prior comment was:

`test` test  
`\test\` \test\  
`/test/` /test/  
`test` test  
`~test ` test  
`test ` test~~

...assuming pre works, at least.

EDIT: nope, pre doesn't work either...

Looks like your top-level comment about formatting is filtered.

fixed.