Browse Source

[FIX] web_widget_text_markdown : use lexer on text field only (#942)

Fixes #937
pull/1055/merge
Nicolas JEUDY 6 years ago
committed by Pedro M. Baeza
parent
commit
28d85aa32f
  1. 35
      web_widget_text_markdown/static/src/js/web_widget_text_markdown.js

35
web_widget_text_markdown/static/src/js/web_widget_text_markdown.js

@ -2,20 +2,19 @@
* Copyright 2017 Komit - <http:///komit-consulting.com>
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */
odoo.define("web_widget_text_markdown.bootstrap_markdown",
function (require) {
function(require) {
"use strict";
var core = require('web.core');
var form_common = require('web.form_common');
var formats = require ("web.formats");
var formats = require("web.formats");
var _lt = core._lt;
var ListView = require('web.ListView');
var list_widget_registry = core.list_widget_registry;
var FieldTextMarkDown = form_common.AbstractField.extend(
form_common.ReinitializeFieldMixin,
{
form_common.ReinitializeFieldMixin, {
template: 'FieldMarkDown',
display_name: _lt('MarkDown'),
@ -24,7 +23,7 @@ odoo.define("web_widget_text_markdown.bootstrap_markdown",
'change input': 'store_dom_value'
},
init: function (field_manager, node) {
init: function(field_manager, node) {
this._super(field_manager, node);
this.$txt = false;
@ -35,7 +34,7 @@ odoo.define("web_widget_text_markdown.bootstrap_markdown",
return formats.parse_value(val, this, def);
},
initialize_content: function () {
initialize_content: function() {
// Gets called at each redraw of widget
// - switching between read-only mode and edit mode
// - BUT NOT when switching to next object.
@ -50,7 +49,7 @@ odoo.define("web_widget_text_markdown.bootstrap_markdown",
this.old_value = null; // will trigger a redraw
},
store_dom_value: function () {
store_dom_value: function() {
if (!this.get('effective_readonly') &&
this.is_syntax_valid()) {
// We use internal_set_value because we were called by
@ -64,18 +63,19 @@ odoo.define("web_widget_text_markdown.bootstrap_markdown",
}
},
commit_value: function () {
commit_value: function() {
this.store_dom_value();
return this._super();
},
_get_raw_value: function() {
if (this.$txt === false)
if (this.$txt === false) {
return '';
}
return this.$txt.val();
},
render_value: function () {
render_value: function() {
// Gets called at each redraw/save of widget
// - switching between read-only mode and edit mode
// - when switching to next object.
@ -87,7 +87,7 @@ odoo.define("web_widget_text_markdown.bootstrap_markdown",
} else {
// avoids loading markitup...
marked.setOptions({
highlight: function (code) {
highlight: function(code) {
return hljs.highlightAuto(code).value;
}
});
@ -95,7 +95,7 @@ odoo.define("web_widget_text_markdown.bootstrap_markdown",
}
},
format_value: function (val, def) {
format_value: function(val, def) {
return formats.format_value(val, this, def);
}
}
@ -109,18 +109,19 @@ odoo.define("web_widget_text_markdown.bootstrap_markdown",
**/
ListView.Column.include({
init: function(){
init: function() {
this._super.apply(this, arguments);
hljs.initHighlightingOnLoad();
marked.setOptions({
sanitize: true,
highlight: function (code) {
highlight: function(code) {
return hljs.highlightAuto(code).value;
}
});
},
_format: function(row_data, options){
_format: function(row_data, options) {
if (this.type === "text") {
options = options || {};
var markdown_text = marked(
formats.format_value(
@ -129,8 +130,10 @@ odoo.define("web_widget_text_markdown.bootstrap_markdown",
);
return markdown_text;
}
return this._super(row_data, options)
}
});
list_widget_registry.add('field.bootstrap_markdown', ListView.Column);
});
});
Loading…
Cancel
Save