import nitcorn
import nitcorn::log
import template
+import json::serialization_write
# Nitcorn service to hightlight code
#
var hlcode = null
if code != null then hlcode = hightlightcode(hl, code)
+ if http_request.post_args.get_or_null("json") == "true" and hlcode != null then
+ var response = new HttpResponse(200)
+ response.header["Content-Type"] = "text/json"
+ response.body = hlcode.to_json
+ return response
+ end
+
if http_request.post_args.get_or_null("ajax") == "true" and hlcode != null then
page.add hlcode.code_mirror_update
page.add """
import html
import pipeline
import astutil
+import serialization
# Fully process a content as a nit source file.
fun hightlightcode(hl: HighlightVisitor, content: String): HLCode
# A standalone highlighted piece of code
class HLCode
+ super Serializable
+
# The highlighter used
var hl: HighlightVisitor
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
# Visitor used to produce a HTML tree based on a AST on a `Source`