Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove the first doctype tooltip of the ace-editor in my html-editor?

We ask the user here to define html, so add a div or a section or something like that. So, I want the validation-tooltips when editing my HTML. But don't wanna have the doc-type warning.

tooltip of ace editor

like image 635
Sjoerd Valk Avatar asked Oct 20 '15 09:10

Sjoerd Valk


3 Answers

Try this

var session = editor.getSession();
session.on("changeAnnotation", function() {
  var annotations = session.getAnnotations()||[], i = len = annotations.length;
  while (i--) {
    if(/doctype first\. Expected/.test(annotations[i].text)) {
      annotations.splice(i, 1);
    }
  }
  if(len>annotations.length) {
    session.setAnnotations(annotations);
  }
});
like image 176
Chris Greener Avatar answered Nov 09 '22 19:11

Chris Greener


With "Unexpected End of File. Expected DOCTYPE." warning filtered.

var session = editor.getSession();
session.on("changeAnnotation", function () {
    var annotations = session.getAnnotations() || [], i = len = annotations.length;
    while (i--) {
        if (/doctype first\. Expected/.test(annotations[i].text)) {
            annotations.splice(i, 1);
        }
        else if (/Unexpected End of file\. Expected/.test(annotations[i].text)) {
            annotations.splice(i, 1);
        }
    }
    if (len > annotations.length) {
        session.setAnnotations(annotations);
    }
});
like image 3
Jarosław Wasilewski Avatar answered Nov 09 '22 20:11

Jarosław Wasilewski


If instead you operate on the annotations directly and call the editor onChangeAnnotation method directly to update the annotations on the page you can prevent firing another changeAnnotation event and calling this event handler twice as Chris's answer does.

var editor = Application.ace.edit(element),
    session = editor.getSession();

session.on('changeAnnotation', function () {
  session.$annotations = session.$annotations.filter(function(annotation){
    return !(/doctype first\. Expected/.test(annotation.text) || /Unexpected End of file\. Expected/.test(annotation.text))
  });
  editor.$onChangeAnnotation();
});
like image 3
Macro Avatar answered Nov 09 '22 18:11

Macro