最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin5浏览0评论

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.

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.

Share Improve this question edited Oct 22, 2015 at 10:01 Unheilig 16.3k193 gold badges69 silver badges101 bronze badges asked Oct 20, 2015 at 9:16 Sjoerd ValkSjoerd Valk 1345 bronze badges 1
  • As stated in this thread, it doesn't seem to be possible to filter certain errors, though you can disable them all. – Jelle De Loecker Commented Oct 20, 2015 at 14:52
Add a ment  | 

3 Answers 3

Reset to default 12

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);
  }
});

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);
    }
});

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();
});
发布评论

评论列表(0)

  1. 暂无评论