samclarke / SCEditor

A lightweight HTML and BBCode WYSIWYG editor
http://www.sceditor.com/
Other
643 stars 186 forks source link

Need a setting to remove the display of line breaks on the boundaries of the bbcode and its content in HTML #937

Open MioVisman opened 1 year ago

MioVisman commented 1 year ago

Extra blank lines in HTML if bbcode is on a separate line from the content. Example

[code]
abcde
12345
[/code]

result i1

or

---
[b]
abcde
12345
[/b]
---

result i2

Maybe I searched badly, but I did not find a method to solve the problem. Made a crutch https://github.com/forkbb/forkbb/commit/2e4941b857364eb5e59ff65bd53d09ae700c7ce4

P.S. After that, the text with bbcodes changes of course

---
[b]abcde
12345[/b]
---

But it's better than empty lines :|

samclarke commented 1 year ago

Do you want to add a line break after the opening tag and before the closing tag? If so, there is the breakStart and breakEnd BBCode options which do that. They would need to be added to each individual BBCode.

For example: https://jsbin.com/saqagiyife/edit?html,js,output (only the [b] and [code] tags have been updated in the example).

There is also a breakStartBlock and breakEndBlock options which will do the same but for all block BBCodes. Unfortunately, there isn't an option to do it for all BBCodes so inline BBCodes will still need to have breakStart / breakEnd added manually.

MioVisman commented 1 year ago

I raised a situation where messages with bbcodes were created not by the editor, but manually. In this case, such newlines may occur. On forum pages (eg fluxbb, punbb, forkbb) such messages are displayed without these extra empty lines, as the parsers swallow these newlines. But if this message is opened for editing in sceditor, then it looks ugly, the name has many empty lines at the beginning and end of the bbcodes. I corrected this situation for myself with a crutch (link above). But maybe someone else with a similar situation will face / faced.

samclarke commented 1 year ago

Are you wanting to ignore the first/last line of BBCodes like breakStart/breakEnd does without the editor outputting them?

Or is it that all first/last newlines at the start/end of BBCodes should be ignored? So a BBCode like:

---
[b]

test

[/b]
---

would be the equivalent of:

---
[b]test[/b]
---
MioVisman commented 1 year ago

Are you wanting to ignore the first/last line of BBCodes like breakStart/breakEnd does without the editor outputting them?

Yes.

My code removes 1 empty line at the beginning and 1 empty line at the end if they are present in the content. For all bbcodes. content = content.replace(/^\x20*<br \/>/, '').replace(/<br \/>\x20*$/, '');

samclarke commented 1 year ago

Is there a reason for not wanting the lines added to the output when they're supported in the input?

If they're not added to the output, what should happen when editing previously output BBCode or if toggling between WYSIWYG and BBCode? As that will cause lines to be removed.

For example, with the BBCode:

[code]

Should have a single line above.
[/code]

The first time it's edited there will be one line above but if the ignored lines aren't added to the output, the resulting BBCode will be:

[code]
Should have a single line above.[/code]

Then, the next time it is edited/toggled between source and WYSIWYG, the line above will be stripped.

MioVisman commented 1 year ago

Yes, but do leading and trailing lines within bbcodes make sense? Can it be correct to place empty lines outside of bbcodes? I don't know, I need more experience with messages.