Skip to content

Preformatted plugin improvement - #1683

Open
stefl0n wants to merge 192 commits into
Alex-D:developfrom
stefl0n:preformatted-plugin
Open

Preformatted plugin improvement#1683
stefl0n wants to merge 192 commits into
Alex-D:developfrom
stefl0n:preformatted-plugin

Conversation

@stefl0n

@stefl0n stefl0n commented Jun 16, 2026

Copy link
Copy Markdown

The preformat-function is imho ment to wrap and convert a pre-formatted text (e.g. code example) to a proper pre or code block.

Current behaviour (on the trumbowyg homepage):
preformatted-1

Expected behavior (in this PR):
preformatted-2

@stefl0n stefl0n changed the title Preformatted plugin Preformatted plugin improvement Jun 16, 2026

@Alex-D Alex-D left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added some feedbacks, also, can you rebase on the main branch since I've merge your other PR?
Thank you :)

var container = null;

if (document.selection) { //for IE
if (document.selection) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing the comment?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, the comment may stay. I accidentally removed it while cleaning up my own comments.

Comment on lines +131 to +136
return html .replace(/<p>/gi, '')
.replace(/<\/p>/gi, '\n')
.replace(/<br\s*\/?>/gi, '\n')
.replace(/<h[1-6]>|<\/h[1-6]>/gi, '\n')
.replace(/<li>/gi, '- ')
.replace(/<\/li>/gi, '\n');

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure about this way to do it, there are a lot more tags missing here, no?
What's the goal of this function?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. That was indeed not my final version of that conversion function. I rewrote it now completely in my final version.

// step 2: keep whitespaces & line breaks
html = html
.replace(/ /g, '&nbsp;&nbsp;') // keep double spaces
.replace(/\t/g, '&nbsp;&nbsp;&nbsp;&nbsp;') // keep tabs

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why replacing tabs with 4 spaces? Can't we use &Tab;?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. good point. Let's use &tab; here.

@stefl0n
stefl0n force-pushed the preformatted-plugin branch from b5eb79c to f6b6882 Compare August 6, 2026 14:56
@stefl0n

stefl0n commented Aug 6, 2026

Copy link
Copy Markdown
Author

I rebased with main and tried to commit my final changes. Not sure if everything went well 🙈

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.

8 participants