Our current technique for switching is the following:
Take the wikitext and add one level of indentation:
```
Foo
bar
==baz==
{|
|quux
|}
```
->
```
:Foo
:bar
:==baz==
:{|
:|quux
:|}
```
Convert this to HTML
```lang=html
<dl>
<dd>Foo</dd>
<dd>bar</dd>
<dd>==baz==</dd>
<!-- very broken table: -->
<dd><dl><dd></dd></dl><table><tbody><tr><td>quux<dd>|}</dd></td></tr></tbody></table></dd>
</dl>
```
then unwrap/de-indent the list down to paragraphs:
```lang=html
<p>Foo</p>
<p>bar</p>
<p>==baz==</p>
<!-- broken table -->
```
Pros:
* Correctly converts single linebreaks into separate paragraphs
* Correctly preserves some unsupported syntax, e.g. headings becoming <p>==baz==</p>
Cons:
* Mangles other syntax, resulting in broken roundtrips when you switch back (e.g. tables, templates)
* No warning shown to the user that something bad is about to happen
The alternative approach we have discussed is:
* ~~do a context-less switch of the wikitext as-entered~~
* It looks like we will need to keep the wrap/unwrap step to support single linebreaks.
* before loading VE, check the HTML for unsupported features: tables, headings, templates, images
* if such a feature is found, refuse to switch or show a warning
Cons:
* We still need an approach for converting single linebreaks into separate paragraphs
=== Implementation details
1. When someone writes a comment in the tool's `source` mode that contains a template //or// a table
2. //And// then attempts to switch to the tool's `visual` mode, they should observe
3. A dialog that meets the following conditions:
- If the comment written in `source` mode contains a **table**, the user should see a dialog that says:
--- `Sorry, switching to visual mode is disabled because **table** syntax was detected in the comment you have written. To switch modes, please delete this syntax. [Learn more](mw:Extension:DiscussionTools/Reply_tool_visual_mode_limitations)."`
- If the comment written in `source` mode contains a **template**, the user should see a dialog that says:
--- `Sorry, switching to visual mode is disabled because **template** syntax was detected in the comment you have written. To switch modes, please delete this syntax. [Learn more](mw:Extension:DiscussionTools/Reply_tool_visual_mode_limitations)."`
=== Open questions
- [x] 1. In what – if any – cases should people be blocked from switching from source to visual?
People will not be able to switch from `source` to `visual` //if// the comment they are writing contains a template or a table.
- [x] 2. In the cases where people are blocked from switching from source to visual, what should be communicated to them? How should this communication be presented?
People will see a dialog* that informs them they are not able to switch to the tool's `visual` mode, why they are not able to switch to the tool's `visual` mode and what they can do to get around this block.
- [x] 3. In what cases should people be warned when attempting to switch from source to visual?
There will be no "warn" case.
- [x] 4. In the cases where people are warned when attempting to switch from source to visual, what should be communicated to them? How this communication be presented?
Moot; see "3." above.
- [x] 5. How should single linebreaks be converted into separate paragraphs?
Comments of this type will be handled as they currently are: wrapped and unwrapped when switching modes. //See: T256150#6256308//
- [ ] 6. @Esanders can you think of a way to present the exception message in a way that allows people to simultaneously read said "exception message" and the comment they've written? As this patch is currently implemented, the exception message obscures the comment the editor has written.
root issue(s) that the Reply tool from handling multi-line templates and tables within comments?
=== Done
- [ ] "Open questions" are answered
- [ ] The tool works as specified in the "Implementation details" section