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

New AccessKit feature: Remove unusual spacing #1171

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

marcustyphoon
Copy link
Collaborator

@marcustyphoon marcustyphoon commented Jul 29, 2023

"This should be easy," I say, immediately before spending 6 hours on a still only partially working draft.

Interesting decisions include:

  • does one use white-space: pre-line, which handles a lot of the whitespace collapsing for you but removes leading indentation, or try to go without it and correctly manually parse e.g. hello <strong> world</strong> (simple regex will not see two spaces between hello and world there)

Description

This adds an AccessKit feature that renders posts (and content in the trail in the post editor) as if they did not have multiple consecutive spaces. Artificially increasing spacing between words using is a formatting style used by a subset of the roleplay community, and many find it difficult to read.

To perform this manipulation safely and reversibly, this code clones textBlock elements that contain multiple spaces between words, leaving the real DOM elements hidden via CSS and untouched. It traverses its cloned nodes and replaces unusual space characters like &nbsp in each text node with regular spaces (per MDN, white-space only collapses regular space and regular tab characters). This is preferable over setting innerHTML for security reasons.

This also implements a control button on posts it affects, allowing the user to toggle between viewing the original and adjusted formatting. Sadly, this problem is complicated enough that I don't think it's feasible to fix every edge case and just present a perfect view (indentation via leading whitespace gets removed by the implementation as of writing this, for example).

Testing steps

@marcustyphoon marcustyphoon marked this pull request as ready for review July 29, 2023 11:25
Zavionspain

This comment was marked as off-topic.

@marcustyphoon marcustyphoon marked this pull request as draft March 24, 2024 02:26
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

Successfully merging this pull request may close these issues.

2 participants