Hi everyone! Inspired by https://www.mediawiki.org/wiki/VisualEditor/Gadgets#Implementing_a_custom_co... I was trying to add a `<br />` into the VE using this command:
``` ve.init.target.getSurface().getModel().getFragment().insertContent( [ { type: 'break' }, { type: '/break' } ] ); ```
While it actually inserted the line break in visual edit mode, there was not `<br />` in the wikitext after saving the page or switching to wikitext mode within the edit session. I also tried to implement the whole "command/tool" in an extension, but the behavior was the same. The odd thing is that a `<br />` inserted in wikitext mode survives the round trip. The linear data model shows it as "alienInline" node then.
Any ideas why the official example didn't work for me?
Greetings, Robert
I don't know the reason of the problem, but I think, it is generally a good idea to avoid these XML-like self-closing tags in the world of HTML5. Why not just <br>?
Hi Robert,
While waiting for VE devs to respond, there are a few things you could do to narrow-down the issue: 1. Check what the diff window shows (click on Publish changes, then on the popup "Review your changes" in the lower-left corner). 2. Check if there was actually one or more newline(s) (\n) inserted in wikitext.In this case, the parser probably tries to simplify the wikitext unless a hooman decided otherwise (this seems in line with the "alienInline" you see).
Regards, Strainu
În lun., 13 mar. 2023 la 09:37, Robert Vogel via Wikitech-l < wikitech-l@lists.wikimedia.org> a scris:
Hi everyone! Inspired by https://www.mediawiki.org/wiki/VisualEditor/Gadgets#Implementing_a_custom_co... I was trying to add a `<br />` into the VE using this command:
ve.init.target.getSurface().getModel().getFragment().insertContent( [ { type: 'break' }, { type: '/break' } ] );While it actually inserted the line break in visual edit mode, there was not `<br />` in the wikitext after saving the page or switching to wikitext mode within the edit session. I also tried to implement the whole "command/tool" in an extension, but the behavior was the same. The odd thing is that a `<br />` inserted in wikitext mode survives the round trip. The linear data model shows it as "alienInline" node then.
Any ideas why the official example didn't work for me?
Greetings, Robert _______________________________________________ Wikitech-l mailing list -- wikitech-l@lists.wikimedia.org To unsubscribe send an email to wikitech-l-leave@lists.wikimedia.org https://lists.wikimedia.org/postorius/lists/wikitech-l.lists.wikimedia.org/
Hi Robert and all,
I would recommend using <br /> for the following reasons:
1) Text and XML editors that highlight XML syntax in different colours will highlight properly with <br /> but this is not always the case if you use <br>
2) <br /> is backwards-compatible with XHTML and well-formed HTML (ie: XHTML) is often easier to validate for errors and debug
3) Some old parsers and some coding specs require the space before the closing slash (ie: <br /> instead of <br/>) such as the WordPress Plugin Coding spec: http://make.wordpress.org/core/handbook/coding-standards/html/
In my experience, I have never come across a case where using <br /> is problematic, however, there are many cases where <br/> or especially <br> might be problematic in older browsers and tools.
Kind regards Doc Taxon
Am Mo., 13. März 2023 um 13:34 Uhr schrieb Strainu strainu10@gmail.com:
Hi Robert,
While waiting for VE devs to respond, there are a few things you could do to narrow-down the issue:
- Check what the diff window shows (click on Publish changes, then on the
popup "Review your changes" in the lower-left corner). 2. Check if there was actually one or more newline(s) (\n) inserted in wikitext.In this case, the parser probably tries to simplify the wikitext unless a hooman decided otherwise (this seems in line with the "alienInline" you see).
Regards, Strainu
În lun., 13 mar. 2023 la 09:37, Robert Vogel via Wikitech-l < wikitech-l@lists.wikimedia.org> a scris:
Hi everyone! Inspired by https://www.mediawiki.org/wiki/VisualEditor/Gadgets#Implementing_a_custom_co... I was trying to add a `<br />` into the VE using this command:
ve.init.target.getSurface().getModel().getFragment().insertContent( [ { type: 'break' }, { type: '/break' } ] );While it actually inserted the line break in visual edit mode, there was not `<br />` in the wikitext after saving the page or switching to wikitext mode within the edit session. I also tried to implement the whole "command/tool" in an extension, but the behavior was the same. The odd thing is that a `<br />` inserted in wikitext mode survives the round trip. The linear data model shows it as "alienInline" node then.
Any ideas why the official example didn't work for me?
Greetings, Robert _______________________________________________ Wikitech-l mailing list -- wikitech-l@lists.wikimedia.org To unsubscribe send an email to wikitech-l-leave@lists.wikimedia.org
https://lists.wikimedia.org/postorius/lists/wikitech-l.lists.wikimedia.org/
Wikitech-l mailing list -- wikitech-l@lists.wikimedia.org To unsubscribe send an email to wikitech-l-leave@lists.wikimedia.org https://lists.wikimedia.org/postorius/lists/wikitech-l.lists.wikimedia.org/
On 2023-03-13 08:36, Robert Vogel via Wikitech-l wrote:
Hi everyone! Inspired by https://www.mediawiki.org/wiki/VisualEditor/Gadgets#Implementing_a_custom_co... I was trying to add a `<br />` into the VE using this command:
ve.init.target.getSurface().getModel().getFragment().insertContent( [ { type: 'break' }, { type: '/break' } ] );While it actually inserted the line break in visual edit mode, there was not `<br />` in the wikitext after saving the page or switching to wikitext mode within the edit session. I also tried to implement the whole "command/tool" in an extension, but the behavior was the same. The odd thing is that a `<br />` inserted in wikitext mode survives the round trip. The linear data model shows it as "alienInline" node then.
Any ideas why the official example didn't work for me?
Interesting, I can reproduce the problem. As far as I know this should work, and has worked in the past.
The line break disappears when the HTML generated by visual editor is being turned into wikitext in Parsoid.
Parsoid is supposed to apply some "cleanup" before saving the page (e.g. if you leave an empty heading in the document, it will disappear when saving in visual editor), and IIRC some of these cleanups also affected br tags, but I don't think they're supposed to be removed entirely.
Want to file a bug?
wikitech-l@lists.wikimedia.org