Codemirror的HTMLHint验证器

时间:2015-08-10 19:04:20

标签: javascript html validation codemirror lint

我正在为lint

寻找html Codemirror

我找到HTMLHintACE Editor,但在搜索Codemirror's Git Repository之后,我找到了他们lint's。我以前玩过CSSLint和JSHint,但是没有为Codemirror找到任何东西。

有没有人知道如何使用像HTMLHint这样的HTML验证器来使用Codemirror?

var delay;

// Initialize CodeMirror editor
var editor = CodeMirror(document.getElementById('code'), {
  mode: 'text/html',
  tabMode: 'indent',
  styleActiveLine: true,
  lineNumbers: true,
  lineWrapping: true,
  autoCloseTags: true,
  foldGutter: true,
  dragDrop : true,
  lint: true,
  gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter', 'CodeMirror-lint-markers'],
  value: '<div class="container-fluid">\n  <div class="row">\n    <div class="col-lg-12">\n      <div class="input-group">\n        <input type="txt" class="form-control" data-action="genoutput" />\n        <span class="input-group-btn" class="input-group-btn">\n          <button class="btn btn-default btn-primary" type="button" data-action"gen">\n            Generate!\n          </button>\n        </span>\n      </div>\n    </div>\n  </div>\n</div>'
});

// Live preview
editor.on('change', function() {
  clearTimeout(delay);
  delay = setTimeout(updatePreview, 300);
});
function updatePreview() {
  var previewFrame = document.getElementById('preview');
  var preview =  previewFrame.contentDocument ||  previewFrame.contentWindow.document;
  preview.open();
  preview.write(editor.getValue());
  preview.close();
}
setTimeout(updatePreview, 300);
@import url("http://necolas.github.io/normalize.css/3.0.1/normalize.css");
@import url("http://codemirror.net/lib/codemirror.css");
@import url("http://codemirror.net/addon/lint/lint.css");
@import url("http://codemirror.net/addon/fold/foldgutter.css");

.CodeMirror {
  float: left;
  width: 50%;
  border: 1px solid black;
}

iframe {
  width: 49%;
  float: left;
  height: 300px;
  border: 1px solid black;
  border-left: 0;
}
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="http://codemirror.net/lib/codemirror.js"></script>
<script src="http://codemirror.net/javascripts/code-completion.js"></script>
<script src="http://codemirror.net/javascripts/css-completion.js"></script>
<script src="http://codemirror.net/javascripts/html-completion.js"></script>
<script src="http://codemirror.net/mode/javascript/javascript.js"></script>
<script src="http://codemirror.net/mode/xml/xml.js"></script>
<script src="http://codemirror.net/mode/css/css.js"></script>
<script src="http://codemirror.net/mode/htmlmixed/htmlmixed.js"></script>
<script src="http://codemirror.net/addon/edit/closetag.js"></script>
<script src="http://codemirror.net/addon/edit/matchbrackets.js"></script>
<script src="http://codemirror.net/addon/selection/active-line.js"></script>
<script src="http://codemirror.net/keymap/extra.js"></script>
<script src="http://codemirror.net/addon/fold/foldcode.js"></script>
<script src="http://codemirror.net/addon/fold/foldgutter.js"></script>
<script src="http://codemirror.net/addon/fold/brace-fold.js"></script>
<script src="http://codemirror.net/addon/fold/xml-fold.js"></script>
<script src="http://codemirror.net/addon/fold/comment-fold.js"></script>
<script src="http://codemirror.net/addon/lint/lint.js"></script>
<script src="http://codemirror.net/addon/hint/xml-hint.js"></script>
<script src="http://codemirror.net/addon/hint/html-hint.js"></script>
<script src="http://codemirror.net/addon/lint/javascript-lint.js"></script>
<script src="http://codemirror.net/addon/lint/css-lint.js"></script>

<div id="code" name="code"></div>
<iframe id="preview"></iframe>

1 个答案:

答案 0 :(得分:1)

您必须编写将HTMLHint输出连接到CodeMirror的lint插件的粘合代码。请参阅docs here,并使用其他lint模块包装器作为示例。 (如果你得到了一些工作,拉动请求将它放入发行版中将是非常值得的。)