-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] web_widget_html_markdown: bidirectional editing
Possible to use markdown for html fields, or html editor and switch between the two.
- Loading branch information
Showing
7 changed files
with
257 additions
and
290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Technical design of the markdown for html fields widget | ||
|
||
When this widget is linked to an html field, the user will be able to switch between an | ||
html editor and a markdown editor for the fields content. The display of the field, and | ||
the contents stored will always be html. | ||
|
||
Actually when editing in markdown, this markdown will also be stored in html, but then | ||
as a hidden code section. In this way using the widget does not need any new database | ||
element. | ||
|
||
To convert from markdown to html, the marked library is used: [marked]: | ||
https://github.com/markedjs/marked | ||
|
||
To convert from html to markdown the turndown library is used: [turndown]: | ||
https://github.com/mixmark-io/turndown | ||
|
||
## Events | ||
|
||
1. Starting the editor | ||
|
||
When a field is going to be edited, we have to show either the html editor or the | ||
markdown editor. For existing records, we just look at the presence or absence of stored | ||
markdown code. For new records we will look at the field options. | ||
|
||
2. Switching to markdown | ||
|
||
- Take the html value and convert it to markdown; | ||
- Create the markdown hidden paragraph, and add it to the html; | ||
- Activate the markdown editor; | ||
- Change to info in the control area to show markdown is being used. | ||
|
||
3. Switching to html | ||
|
||
- Take the markdown content and convert it to html; | ||
- Remove the hidden markdown paragraph; | ||
- Activate the html editor; | ||
- Change to info in the control area to show html is being used. | ||
|
||
4. Saving the form: commiting the changes | ||
|
||
If html is being used, nothing special needs to be done. | ||
|
||
If markdown is being used: | ||
|
||
- Convert the markdown value to html; | ||
- Add the hidden paragraph with the markdown content; | ||
- Replace the html contents with the html genererated, including the hidden paragraph. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
* Tom Blauwendraat <[email protected]> | ||
* Kevin Kamau <[email protected]> | ||
* Giovanni Francesco Capalbo <[email protected]> | ||
* Ronald Portier <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
Behaviour of the module and best practices | ||
========================================== | ||
|
||
This module implements a Markdown editor on Html fields, in contrast to web_widget_text_markdown, which implements it on Text fields. In readonly mode, the widget displays HTML, but when editing, the widget offers you an option to edit in Markdown or in HTML. If you edit markdown, it will save as the rendered HTML, but with the source Markdown embedded inside a <script> tag. When editing again, it will show you the Markdown source. If you edit HTML, you will lose the Markdown and the content will just behave as a regular HTML field with an HTML widget. | ||
This module implements a markdown editor on html fields, in contrast to | ||
web_widget_text_markdown, which implements it on text fields. In readonly mode, | ||
the widget displays html, but when editing, the widget offers you an option to edit | ||
in markdown or in html. If you edit markdown, it will save as the rendered html, | ||
but with the source markdown embedded inside a <script> tag. When editing again, | ||
it will show you the markdown source. If you edit html, you will lose the markdown | ||
and the content will just behave as a regular html field with an html widget. | ||
|
||
Utility of this module vs web_widget_text_markdown | ||
================================================== | ||
The benefit of this module over web_widget_text_html is that it allows markdown-editing of HTML fields such as for example the mail.message body for the chatter, or HTML fields that end up in printed reports such as the Quotation description. Such fields cannot be converted to Text fields because it will cause problems for their functionality. But with this widget, they can still be edited as Markdown. | ||
Limitations | ||
=========== | ||
|
||
A difficulty with this module is that once you start editing a field as HTML, whether with this Markdown widget in HTML mode, or through a view that has the normal HTML editor, you will lose the Markdown source and you will have to keep editing the field as HTML, or do a backconversion to Markdown. This backconversion is always lossy to a certain extent and we did not bother implementing it - but it's something for the roadmap. | ||
. | ||
The module does allow switching from html to markdown editing. However the conversion | ||
from html to markdown will most likely lose some information. That is why users | ||
are warned before making this switch. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
* Implement conversion from HTML to Markdown, either through a JS or a Python module, instead of not allowing it, or allowing it only after HTML is emptied. | ||
* Create a config parameter switch such as this that will enable a markdown option | ||
for html fields throughout the whole system. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.