nitc :: HLCode :: defaultinit
# A standalone highlighted piece of code
class HLCode
super Serializable
# The highlighter used
var hl: HtmlightVisitor
# The raw code source
var content: String
# The pseudo source-file
var source: SourceFile
# JavaScript code to update an existing codemirror editor.
fun code_mirror_update: Template
do
var res = new Template
res.add """
function nitmessage() {
editor.operation(function(){
for (var i = 0; i < widgets.length; ++i)
editor.removeLineWidget(widgets[i]);
widgets.length = 0;
"""
for m in source.messages do
res.add """
var l = document.createElement("div");
l.className = "lint-error"
l.innerHTML = "<span class='glyphicon glyphicon-warning-sign lint-error-icon'></span> {{{m.text.html_escape}}}";
var w = editor.addLineWidget({{{m.location.line_start-1}}}, l);
widgets.push(w);
"""
end
res.add """});}"""
return res
end
redef fun core_serialize_to(v)
do
v.serialize_attribute("code", hl.html.write_to_string)
var msgs = new Array[Map[String, Serializable]]
for m in source.messages do
var o = new Map[String, Serializable]
msgs.add o
o["line"] = m.location.line_start-1
o["message"] = m.text
end
v.serialize_attribute("messages", msgs)
end
end
src/htmlight.nit:23,1--74,3