Merge branch 'master' into variant-objects

This commit is contained in:
Felix Krause 2016-05-25 23:18:32 +02:00
commit 592158fad0
4 changed files with 670 additions and 618 deletions

View File

@ -88,10 +88,7 @@
</section>
<script type="text/javascript">
function setTextContent(element, text) {
while (element.firstChild!==null) {
element.removeChild(element.firstChild); // remove all existing content
}
element.appendChild(document.createTextNode(text));
element.innerHTML = text;
}
function parse() {
var r = new XMLHttpRequest();

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,8 @@
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
import jester, asyncdispatch, json, streams
import jester, asyncdispatch, json, streams, strutils
import packages.docutils.rstgen, packages.docutils.highlite
import yaml
routes:
@ -38,10 +39,27 @@ routes:
resp resultNode.pretty, "application/json"
tokens = true
if not tokens:
var output = newStringStream()
var
output = newStringStream()
highlighted = ""
transform(newStringStream(@"input"), output, defineOptions(style))
# syntax highlighting (stolen and modified from stlib's rstgen)
var g: GeneralTokenizer
g.initGeneralTokenizer(output.data)
while true:
g.getNextToken(langYaml)
case g.kind
of gtEof: break
of gtNone, gtWhitespace:
highlighted.add(substr(output.data, g.start, g.length + g.start - 1))
else:
highlighted.addf("<span class=\"$2\">$1</span>", "\\span$2{$1}", [
esc(outHtml, substr(output.data, g.start, g.length+g.start-1)),
tokenClassToStr[g.kind]])
resultNode["code"] = %0
resultNode["output"] = %output.data
resultNode["output"] = %highlighted
resp resultNode.pretty, "application/json"
except YamlParserError:
let e = (ref YamlParserError)(getCurrentException())

View File

@ -144,6 +144,14 @@ type
## ``1.2``.
## - If there is an unknown directive encountered.
FastParseLevelKind = enum
fplUnknown, fplSequence, fplMapKey, fplMapValue, fplSinglePairKey,
fplSinglePairValue, fplScalar, fplDocument
FastParseLevel = object
kind: FastParseLevelKind
indentation: int
YamlParser* = ref object
## A parser object. Retains its ``TagLibrary`` across calls to
## `parse <#parse,YamlParser,Stream>`_. Can be used
@ -151,10 +159,20 @@ type
## only until the document goes out of scope (i.e. until
## ``yamlEndDocument`` is yielded).
tagLib: TagLibrary
anchors: OrderedTable[string, AnchorId]
callback: WarningCallback
lexer: BaseLexer
tokenstart: int
content, after: string
ancestry: seq[FastParseLevel]
level: FastParseLevel
tagUri: string
tag: TagId
anchor: AnchorId
shorthands: Table[string, string]
anchors: Table[string, AnchorId]
nextAnchorId: AnchorId
newlines: int
indentation: int
PresentationStyle* = enum
## Different styles for YAML character stream output.