Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][ADD] web_widget_html_markdown #7

Open
wants to merge 2 commits into
base: 14.0
Choose a base branch
from

Conversation

thomaspaulb
Copy link
Member

No description provided.

Copy link
Member Author

@thomaspaulb thomaspaulb left a comment

Choose a reason for hiding this comment

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

Generally OK, could use a cleanup pass, we can do it together in a sprint.

2) Write some markdown and then add some HTML. ( will cause loss of HTML if you edit markdown again)
3) Only markdown.
- RE-editing pure markdown content is LOSSLESS because we preserve the markdown content in a special tag.
- Every switch to markdown will cause destruction of HTML. Html Can Be added after writing Markdown part but will always be deleted.
Copy link
Member Author

Choose a reason for hiding this comment

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

I would change this a little bit:


This module implements a Markdown editor on Html fields, in contract 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.

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.

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.

Choose a reason for hiding this comment

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

I like. shorter. Done. I used your text, but i left the two titles.

@@ -0,0 +1 @@
* HTML Will be lost when passing from Html to markdown
Copy link
Member Author

Choose a reason for hiding this comment

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

  • Implement conversion from HTML to Markdown, either through a JS or a Python module, instead of currently just wiping the content of the field.

Choose a reason for hiding this comment

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

Done but slightly different, now that we changed stuff:

  • 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.

web_widget_html_markdown/readme/USAGE.rst Outdated Show resolved Hide resolved
...

The widget is called unidiectional because itt is used on a Html field to edit HTML
or Markdown, but the conversion is unidirectional, ONLY from Markdown to HTML.
Copy link
Member Author

Choose a reason for hiding this comment

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

This part I think can go, the DESCRIPTION explains it enough

Choose a reason for hiding this comment

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

done

or Markdown, but the conversion is unidirectional, ONLY from Markdown to HTML.

This will replace the default Html widget by the new Markdown/HTML widget and
allow the field to be edited as Markdown or HTML, depending on the user's choice.
Copy link
Member Author

Choose a reason for hiding this comment

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

This part is good, and then below we can explain the new options that will be added.

Choose a reason for hiding this comment

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

Done.

.replace(/\<\/p\>/g,'')
.replace(/\<\/br\>/g,'')
.replace(/\<br\>/g,'')
.replace(/&nbsp;/g,'')
Copy link
Member Author

Choose a reason for hiding this comment

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

Doesnt the isSet function already do this?

Copy link
Member Author

Choose a reason for hiding this comment

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

This works on the current value, and isSet works on the last-saved value.

Choose a reason for hiding this comment

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

confirmed. done.




var FieldHtmlMarkDown = basic_fields.DebouncedField.extend(TranslatableFieldMixin, {
Copy link
Member Author

Choose a reason for hiding this comment

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

We should, I think, spend some together-time still on trying to make this widget inherit directly from HtmlField. I shot down that idea earlier but we duplicate a lot of code here, so it's worth another shot.

Choose a reason for hiding this comment

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

Now done and tested

// this will use marked
var render_val = self._getHtmlValue(e.getContent());
return render_val;
},
Copy link
Member Author

Choose a reason for hiding this comment

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

Currently the dropzone.js functionality, added in the 11.0 version of the text widget module, does not work. We can re-enable it.

Choose a reason for hiding this comment

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

Done

this.$el.prepend(md_s);
//
this.$el.find('input').addClass('mk_html_switch');
this.$el.find('input').change([self], self._switch_markdown_html);
Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's best practice to make a separate sub-widget out of this and then instantiate it with:

this.sub_widget = new SubWidgetClass(this);
this.$el.prepend(this.sub_widget);

And then do the events in the Odoo events: way, let them bubble up to here via messages, and then catch them here.

Choose a reason for hiding this comment

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

@thomaspaulb Question: Are we sure? All other issues are done. I see the radiobutton+the editors as one widget.
The radiobutton+information_area as a separate widget would make sense if it was reusable elsewhere, this part of the widget is used once and makes sense only in conjunction with the rest. so I don't see why we should separate this.

After the cleanup, the widget is 200lines, i have refactored the views in XML, so if your concern is length of code it should not be a problem.
I am all for modularity, but this sub-widget has not use anywhere else.

var has_md_source_tag = self._html_has_md_source_tag();
if (!is_empty && !has_md_source_tag ) {
// THIS SHOULD NEVER APPEAR, WE HAVE HIDDEN THE RADIOBUTTON IN ALL
// POSSIBLE CIRCUMSTANCES, KEEPING IT FOR TESTING PURPOSES.
Copy link
Member Author

Choose a reason for hiding this comment

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

Are we now keeping the radiobutton or not?

Copy link
Member Author

Choose a reason for hiding this comment

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

Gio says we can clean it up.

Choose a reason for hiding this comment

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

Done

@gfcapalbo
Copy link

gfcapalbo commented Sep 20, 2022

@thomaspaulb All errors found. Tested, works perfect

  •    Complete cleanup of unnecessary code
    
  •    fixed all bugs
    
  •    Comments explaining why and how of choices
    
  •    Better infoarea/radio management ( the object is defined once and then re-used.)
    
  •    refactored in sections with titles.
    
  •    tested.
    
  •    Table formatting works while editing and also readonly.
    

ONLY ONE SMALL PROBLEM:

  [ENTER, CRTRL-X,  CTRL-Z, MOUSE ACTIONS are not seen as "onchange" in HTML editor]

SHould be quite easy to extend though, i am surprised it is not so in HTML widget. ( confirmed, HTML widget did not see those clipboard, mouse and actions as "onchange" events.

REST WORKS PERFECT

@gfcapalbo gfcapalbo force-pushed the 14.0-web_widget_html_markdown_monodirectional branch 2 times, most recently from 4bd0744 to dbfc425 Compare September 20, 2022 10:56
@@ -0,0 +1,131 @@
========================================
Web Widget Html Markdown Unidirectional
========================================
Copy link
Member Author

Choose a reason for hiding this comment

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

reset this to an empty file, it will be autogenerated anyway

Choose a reason for hiding this comment

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

This title is fetched from manifest. I gave it this name , in the hopes of a 2-way version. But i will remove.
If we make a 2-way version it will be a replacement. cleaning up.

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,27 @@
# Copyright (C) 2014 Sudokeys (<http://www.sudokeys.com>)
# Copyright (C) 2017 Komit (<http://www.komit-consulting.com>)
Copy link
Member Author

Choose a reason for hiding this comment

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

change to therp

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1 @@
* Therp B.V. https://therp.nl
Copy link
Member Author

Choose a reason for hiding this comment

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

brackets

Choose a reason for hiding this comment

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

Done

" <div id='radio_container'> <input id='markdown' type='radio' name='mk_html_switcher' value='markdown'>"+
" <label id='markdown_label' for='markdown'>Markdown</label> " +
"<input type='radio' id='html' name='mk_html_switcher' value='html' checked >" +
" <label id='html_lable' for='html'>HTML</label></div><div id='md_infoarea'></div>")
Copy link
Member Author

Choose a reason for hiding this comment

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

Make this a template

Choose a reason for hiding this comment

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

Done

var layoutInfo = $.summernote.core.dom.makeLayoutInfo(this.wysiwyg.$editor);
$.summernote.pluginEvents.codeview(undefined, undefined, layoutInfo, false);
}
if (self.mode == 'edit' && self.$is_markdown) {
Copy link
Member Author

Choose a reason for hiding this comment

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

indent

Choose a reason for hiding this comment

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

done

// we use recursion (max1) is_markdown is reset
return self.commitChanges()
});
} else if (self.mode == 'edit') {
Copy link
Member Author

Choose a reason for hiding this comment

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

But what if mode is not edit? Shouldnt we still call super?

Choose a reason for hiding this comment

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

No/ this is taken from source HTML. if we are not in edit mode commit changes shouldnt be ran.
We have replicated 5 lines of code because we had to add forceChange:true.
I explain in a brief comment.

Not done.

var has_md_source_tag = self._html_has_md_source_tag();
if (!is_empty && !has_md_source_tag ) {
// THIS SHOULD NEVER APPEAR, WE HAVE HIDDEN THE RADIOBUTTON IN ALL
// POSSIBLE CIRCUMSTANCES, KEEPING IT FOR TESTING PURPOSES.
Copy link
Member Author

Choose a reason for hiding this comment

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

Gio says we can clean it up.

.replace(/\<\/p\>/g,'')
.replace(/\<\/br\>/g,'')
.replace(/\<br\>/g,'')
.replace(/&nbsp;/g,'')
Copy link
Member Author

Choose a reason for hiding this comment

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

This works on the current value, and isSet works on the last-saved value.

@gfcapalbo gfcapalbo force-pushed the 14.0-web_widget_html_markdown_monodirectional branch from a77dbc6 to 7b126be Compare September 21, 2022 09:56
@gfcapalbo
Copy link

@thomaspaulb all done. one commit. Just one question.

@gfcapalbo gfcapalbo force-pushed the 14.0-web_widget_html_markdown_monodirectional branch from d35c428 to 0cee218 Compare September 21, 2022 10:50
@gfcapalbo
Copy link

@thomaspaulb added all the options, and verified for no regressions.

While testing, added a useful badge that tells user in readonly mode if content was saved in pure HTML or with Markdown tag.

markdown
html

@gfcapalbo gfcapalbo force-pushed the 14.0-web_widget_html_markdown_monodirectional branch from 0de1384 to a4d10e7 Compare September 21, 2022 16:36
@gfcapalbo
Copy link

@thomaspaulb working and testable. Had some troubles , solved.
Now working, as proof-of concept. It uses jQuery.html() to compare the first HTML element and works perfectly.
all i need to do is extend it to compare a checksum generated by all HTML,except the hidden tag.

@gfcapalbo gfcapalbo force-pushed the 14.0-web_widget_html_markdown_monodirectional branch 2 times, most recently from c552826 to cbb493a Compare September 21, 2022 20:47
@gfcapalbo gfcapalbo force-pushed the 14.0-web_widget_html_markdown_monodirectional branch 2 times, most recently from b762848 to c984871 Compare October 11, 2022 13:34
@gfcapalbo gfcapalbo force-pushed the 14.0-web_widget_html_markdown_monodirectional branch from 6278a15 to b5a08d7 Compare October 11, 2022 14:15
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.

2 participants