mirror of https://github.com/status-im/NimYAML.git
Merge branch 'master' into variant-objects
This commit is contained in:
commit
592158fad0
|
@ -88,10 +88,7 @@
|
||||||
</section>
|
</section>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function setTextContent(element, text) {
|
function setTextContent(element, text) {
|
||||||
while (element.firstChild!==null) {
|
element.innerHTML = text;
|
||||||
element.removeChild(element.firstChild); // remove all existing content
|
|
||||||
}
|
|
||||||
element.appendChild(document.createTextNode(text));
|
|
||||||
}
|
}
|
||||||
function parse() {
|
function parse() {
|
||||||
var r = new XMLHttpRequest();
|
var r = new XMLHttpRequest();
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -4,7 +4,8 @@
|
||||||
# See the file "copying.txt", included in this
|
# See the file "copying.txt", included in this
|
||||||
# distribution, for details about the copyright.
|
# 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
|
import yaml
|
||||||
|
|
||||||
routes:
|
routes:
|
||||||
|
@ -38,10 +39,27 @@ routes:
|
||||||
resp resultNode.pretty, "application/json"
|
resp resultNode.pretty, "application/json"
|
||||||
tokens = true
|
tokens = true
|
||||||
if not tokens:
|
if not tokens:
|
||||||
var output = newStringStream()
|
var
|
||||||
|
output = newStringStream()
|
||||||
|
highlighted = ""
|
||||||
transform(newStringStream(@"input"), output, defineOptions(style))
|
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["code"] = %0
|
||||||
resultNode["output"] = %output.data
|
resultNode["output"] = %highlighted
|
||||||
resp resultNode.pretty, "application/json"
|
resp resultNode.pretty, "application/json"
|
||||||
except YamlParserError:
|
except YamlParserError:
|
||||||
let e = (ref YamlParserError)(getCurrentException())
|
let e = (ref YamlParserError)(getCurrentException())
|
||||||
|
|
20
yaml.nim
20
yaml.nim
|
@ -144,6 +144,14 @@ type
|
||||||
## ``1.2``.
|
## ``1.2``.
|
||||||
## - If there is an unknown directive encountered.
|
## - 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
|
YamlParser* = ref object
|
||||||
## A parser object. Retains its ``TagLibrary`` across calls to
|
## A parser object. Retains its ``TagLibrary`` across calls to
|
||||||
## `parse <#parse,YamlParser,Stream>`_. Can be used
|
## `parse <#parse,YamlParser,Stream>`_. Can be used
|
||||||
|
@ -151,10 +159,20 @@ type
|
||||||
## only until the document goes out of scope (i.e. until
|
## only until the document goes out of scope (i.e. until
|
||||||
## ``yamlEndDocument`` is yielded).
|
## ``yamlEndDocument`` is yielded).
|
||||||
tagLib: TagLibrary
|
tagLib: TagLibrary
|
||||||
anchors: OrderedTable[string, AnchorId]
|
|
||||||
callback: WarningCallback
|
callback: WarningCallback
|
||||||
lexer: BaseLexer
|
lexer: BaseLexer
|
||||||
tokenstart: int
|
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
|
PresentationStyle* = enum
|
||||||
## Different styles for YAML character stream output.
|
## Different styles for YAML character stream output.
|
||||||
|
|
Loading…
Reference in New Issue