diff --git a/web_widget_html_markdown/README.rst b/web_widget_html_markdown/README.rst index 426183ccf669..6bf7d069672b 100644 --- a/web_widget_html_markdown/README.rst +++ b/web_widget_html_markdown/README.rst @@ -1,5 +1,5 @@ ======================================== -Web Widget Html Markdown Unidirectional +Web Widget Html Markdown Unidirectional ======================================== .. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -14,13 +14,13 @@ Web Widget Html Markdown Unidirectional :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github - :target: https://github.com/OCA/web/tree/14.0/web_widget_html_markdown + :target: https://github.com/OCA/web/tree/14/web_widget_html_markdown :alt: OCA/web .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/web-14-0/web-14-0-web_widget_html_markdown + :target: https://translation.odoo-community.org/projects/web-14/web-14-web_widget_html_markdown :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/162/14.0 + :target: https://runbot.odoo-community.org/runbot/162/14 :alt: Try me on Runbot |badge1| |badge2| |badge3| |badge4| |badge5| @@ -31,7 +31,6 @@ Behaviour of the module and best practices - In readonly mode, the widget renders as Html - In editable mode, there is a switcher to choose if the source should be HTML or Markdown. If HTML, it shows the HTML edit widget. If Markdown, it shows a markdown widget. When done editing, it will save in the field as Html, no matter which widget is chosen. - The Module converts only from markdown to html, so if i am writing HTML and then switch to markdown, i will lose all my HTML. - Therefore the module is called "unidirectional" the conversion will only be markdown-->Html. - when switching from markdown to HTML: the markdown will always be converted and saved in html. - if I switch again from HTML to markdown, i will lose all my html again, only the part i wrote in markdown will be preserved. - Module provides a warning "You will lose all your current HTML if you switch to markdown" @@ -61,29 +60,33 @@ Usage Your XML form view definition should contain: ... - + ... -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. +The widget is used on a Html field to edit HTML 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. + #### Options + - default_markdown_on_new : if true when creating a new record, markdown will + be selected by default. + - only_markdown_on_new : if true when creating a new record, only markdown + will be present on radiobutton. Known issues / Roadmap ====================== * HTML Will be lost when passing from Html to markdown - Bug Tracker =========== Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -123,6 +126,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -This module is part of the `OCA/web `_ project on GitHub. +This module is part of the `OCA/web `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_widget_html_markdown/demo/bootstrap_markdown.xml b/web_widget_html_markdown/demo/bootstrap_markdown.xml index 0db7ff30a713..277a0c429cbc 100644 --- a/web_widget_html_markdown/demo/bootstrap_markdown.xml +++ b/web_widget_html_markdown/demo/bootstrap_markdown.xml @@ -5,7 +5,7 @@ - html_markdown_unidirectional + html_markdown diff --git a/web_widget_html_markdown/readme/DESCRIPTION.rst b/web_widget_html_markdown/readme/DESCRIPTION.rst index 11a126a031e4..f10b292bb2e5 100644 --- a/web_widget_html_markdown/readme/DESCRIPTION.rst +++ b/web_widget_html_markdown/readme/DESCRIPTION.rst @@ -4,7 +4,6 @@ Behaviour of the module and best practices - In readonly mode, the widget renders as Html - In editable mode, there is a switcher to choose if the source should be HTML or Markdown. If HTML, it shows the HTML edit widget. If Markdown, it shows a markdown widget. When done editing, it will save in the field as Html, no matter which widget is chosen. - The Module converts only from markdown to html, so if i am writing HTML and then switch to markdown, i will lose all my HTML. - Therefore the module is called "unidirectional" the conversion will only be markdown-->Html. - when switching from markdown to HTML: the markdown will always be converted and saved in html. - if I switch again from HTML to markdown, i will lose all my html again, only the part i wrote in markdown will be preserved. - Module provides a warning "You will lose all your current HTML if you switch to markdown" diff --git a/web_widget_html_markdown/readme/USAGE.rst b/web_widget_html_markdown/readme/USAGE.rst index a23f1150b7ff..d988e0ab3b01 100644 --- a/web_widget_html_markdown/readme/USAGE.rst +++ b/web_widget_html_markdown/readme/USAGE.rst @@ -1,11 +1,11 @@ Your XML form view definition should contain: ... - + ... -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. +The widget is used on a Html field to edit HTML 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. diff --git a/web_widget_html_markdown/static/description/index.html b/web_widget_html_markdown/static/description/index.html index 97f25027ee10..264b0b0c09f7 100644 --- a/web_widget_html_markdown/static/description/index.html +++ b/web_widget_html_markdown/static/description/index.html @@ -4,7 +4,7 @@ -Web Widget Html Markdown +Web Widget Html Markdown Unidirectional -
-

Web Widget Html Markdown

+
+

Web Widget Html Markdown Unidirectional

-

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runbot

+

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runbot

Behaviour of the module and best practices

  • In readonly mode, the widget renders as Html
  • In editable mode, there is a switcher to choose if the source should be HTML or Markdown. If HTML, it shows the HTML edit widget. If Markdown, it shows a markdown widget. When done editing, it will save in the field as Html, no matter which widget is chosen.
  • -
  • In markdown mode, the markdown is saved embedded within the HTML so that it can be shown again on subsequent edits of the field and there is no loss from backconversion of Html to Markdown.
  • -
  • When switching the widget from Markdown to HTML, the Markdown source is lost.
  • -
  • When switching the widget from HTML back to Markdown, the Showdown.JS backconversion is used to generate a reasonable representation of the HTML in markdown. This is where some information loss can occur, so the user should not needlessly switch from HTML to Markdown and back - in general, choose one way to edit your field content, and stick to it.
  • -
  • In edit mode, the widget provides some feedback about potential loss of information when switching from HTML to markdown or when editing in HTML text that was edited in markdown.
  • +
  • +
    The Module converts only from markdown to html, so if i am writing HTML and then switch to markdown, i will lose all my HTML.
    +
      +
    • when switching from markdown to HTML: the markdown will always be converted and saved in html.
    • +
    • if I switch again from HTML to markdown, i will lose all my html again, only the part i wrote in markdown will be preserved.
    • +
    +
    +
    +
  • +
  • Module provides a warning “You will lose all your current HTML if you switch to markdown”
  • +
  • +
    Best usages of this module:
    +
      +
    1. As normal Html editor, only HTML
    2. +
    3. Write some markdown and then add some HTML. ( will cause loss of HTML if you edit markdown again)
    4. +
    5. Only markdown.
    6. +
    +
    +
    +
  • +
  • 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.
@@ -391,14 +409,27 @@

Usage

… <field name=”field_name” widget=”html_markdown”/> … +

The widget is used on a Html field to edit HTML 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.

+
+
+
#### Options
+
    +
  • default_markdown_on_new : if true when creating a new record, markdown will +be selected by default.
  • +
  • only_markdown_on_new : if true when creating a new record, only markdown +will be present on radiobutton.
  • +
+
+
+

Known issues / Roadmap

    -
  • Images Will be lost when passing from Html to markdown
  • -
  • Other information may be lost when switching from Html to markdown
  • +
  • HTML Will be lost when passing from Html to markdown
@@ -406,7 +437,7 @@

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed -feedback.

+feedback.

Do not contact contributors directly about support or help with technical issues.

@@ -441,7 +472,7 @@

Maintainers

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

-

This module is part of the OCA/web project on GitHub.

+

This module is part of the OCA/web project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

diff --git a/web_widget_html_markdown/static/src/js/web_widget_html_markdown.js b/web_widget_html_markdown/static/src/js/web_widget_html_markdown.js index 41c6455eb849..dff361caf2bb 100644 --- a/web_widget_html_markdown/static/src/js/web_widget_html_markdown.js +++ b/web_widget_html_markdown/static/src/js/web_widget_html_markdown.js @@ -4,27 +4,21 @@ odoo.define("web_widget_html_markdown.FieldHtmlMarkDown", function(require) { "use strict"; - var ajax = require('web.ajax'); - var basic_fields = require('web.basic_fields'); + var field_html = require('web_editor.field.html'); var config = require('web.config'); var core = require('web.core'); var Wysiwyg = require('web_editor.wysiwyg.root'); var field_registry = require('web.field_registry'); require('web._field_registry'); + // Can be removed once the only dialog is removed. var Dialog = require('web.Dialog'); - var QWeb = core.qweb; - var assetsLoaded; - var jinjaRegex = /(^|\n)\s*%\s(end|set\s)/; var _t = core._t; var _lt = core._lt; - var TranslatableFieldMixin = basic_fields.TranslatableFieldMixin; var LIBS_PATH = "/web_widget_html_markdown/static/src/lib/"; var CUST_LIBS_PATH = "/web_widget_html_markdown/static/src/css/"; - - - var FieldHtmlMarkDown = basic_fields.DebouncedField.extend(TranslatableFieldMixin, { + var FieldHtmlMarkDown = field_html.extend({ description: _lt("HtmlMarkdown"), classname: 'oe_form_field oe_form_field_html_markdown', supportedFieldTypes: ['html'], @@ -37,94 +31,67 @@ odoo.define("web_widget_html_markdown.FieldHtmlMarkDown", function(require) { LIBS_PATH + "bootstrap-markdown.min.css", CUST_LIBS_PATH + "web_widget_html_markdown.css", ], - - custom_events: { - wysiwyg_focus: '_onWysiwygFocus', - wysiwyg_blur: '_onWysiwygBlur', - wysiwyg_change: '_onChange', - wysiwyg_attachment: '_onAttachmentChange', - }, + + /*=========================INIT AND START===============*/ init: function (parent, options) { this._super.apply(this, arguments); + this.isSwitch = false; this.options = _.extend({ default_markdown_on_new: true, only_markdown_on_new : true, }, options || {}); }, - willStart: function () { + start: function() { + this._super(); + // Inject MARKDOWN BUTTON + var md_s = $ + ( +"
"+ +" " + +"" + +"
") var self = this; - this.isSwitch = false; - this.isRendered = false; - this._onUpdateIframeId = 'onLoad_' + _.uniqueId('FieldHtmlMarkdown'); - var defAsset; - if (this.nodeOptions.cssReadonly) { - defAsset = ajax.loadAsset(this.nodeOptions.cssReadonly); - } + this.$el.prepend(md_s); + // + this.$el.find('input').addClass('mk_html_switch'); + this.$el.find('input').change([self], self._switch_markdown_html); + // widgets elements as general object attributes, used everywhere + this.infoarea = this.$el.find('div#md_infoarea'); + this.input_markdown = this.$el.find('input#markdown'); + this.input_html = this.$el.find('input#html'); + this.markdown_label = this.$el.find('label#markdown_label'); + this.html_label = this.$el.find('label#html_label'); + }, - if (!assetsLoaded) { // Avoid flickering when begin to edit - assetsLoaded = new Promise(function (resolve) { - var wysiwyg = new Wysiwyg(self, {}); - wysiwyg.attachTo($('