diff options
Diffstat (limited to 'lib/packages')
-rw-r--r-- | lib/packages/docutils/docutils.babel | 6 | ||||
-rw-r--r-- | lib/packages/docutils/docutils.nimble | 5 | ||||
-rw-r--r-- | lib/packages/docutils/highlite.nim | 27 | ||||
-rw-r--r-- | lib/packages/docutils/rst.nim | 8 | ||||
-rw-r--r-- | lib/packages/docutils/rstast.nim | 3 | ||||
-rw-r--r-- | lib/packages/docutils/rstgen.nim | 72 |
6 files changed, 50 insertions, 71 deletions
diff --git a/lib/packages/docutils/docutils.babel b/lib/packages/docutils/docutils.babel deleted file mode 100644 index 1ed86ca05..000000000 --- a/lib/packages/docutils/docutils.babel +++ /dev/null @@ -1,6 +0,0 @@ -[Package] -name = "docutils" -version = "0.9.0" -author = "Andreas Rumpf" -description = "Nimrod's reStructuredText processor." -license = "MIT" diff --git a/lib/packages/docutils/docutils.nimble b/lib/packages/docutils/docutils.nimble new file mode 100644 index 000000000..e32cc6bdb --- /dev/null +++ b/lib/packages/docutils/docutils.nimble @@ -0,0 +1,5 @@ +name = "docutils" +version = "0.10.0" +author = "Andreas Rumpf" +description = "Nim's reStructuredText processor." +license = "MIT" diff --git a/lib/packages/docutils/highlite.nim b/lib/packages/docutils/highlite.nim index 2a58854a6..4f1264c9e 100644 --- a/lib/packages/docutils/highlite.nim +++ b/lib/packages/docutils/highlite.nim @@ -13,6 +13,7 @@ import strutils +from algorithm import binarySearch type TokenClass* = enum @@ -365,32 +366,10 @@ proc generalStrLit(g: var GeneralTokenizer, position: int): int = result = pos proc isKeyword(x: openArray[string], y: string): int = - var a = 0 - var b = len(x) - 1 - while a <= b: - var mid = (a + b) div 2 - var c = cmp(x[mid], y) - if c < 0: - a = mid + 1 - elif c > 0: - b = mid - 1 - else: - return mid - result = - 1 + binarySearch(x, y) proc isKeywordIgnoreCase(x: openArray[string], y: string): int = - var a = 0 - var b = len(x) - 1 - while a <= b: - var mid = (a + b) div 2 - var c = cmpIgnoreCase(x[mid], y) - if c < 0: - a = mid + 1 - elif c > 0: - b = mid - 1 - else: - return mid - result = - 1 + binarySearch(x, y, cmpIgnoreCase) type TokenizerFlag = enum diff --git a/lib/packages/docutils/rst.nim b/lib/packages/docutils/rst.nim index 223fc836a..adac16777 100644 --- a/lib/packages/docutils/rst.nim +++ b/lib/packages/docutils/rst.nim @@ -43,8 +43,8 @@ type mwUnsupportedField MsgHandler* = proc (filename: string, line, col: int, msgKind: MsgKind, - arg: string) {.nimcall.} ## what to do in case of an error - FindFileHandler* = proc (filename: string): string {.nimcall.} + arg: string) {.closure.} ## what to do in case of an error + FindFileHandler* = proc (filename: string): string {.closure.} const messages: array[MsgKind, string] = [ @@ -853,7 +853,6 @@ type DirKind = enum # must be ordered alphabetically! dkNone, dkAuthor, dkAuthors, dkCode, dkCodeBlock, dkContainer, dkContents, dkFigure, dkImage, dkInclude, dkIndex, dkRaw, dkTitle -{.deprecated: [TDirKind: DirKind].} const DirIds: array[0..12, string] = ["", "author", "authors", "code", @@ -1114,7 +1113,6 @@ proc parseHeadline(p: var RstParser): PRstNode = type IntSeq = seq[int] -{.deprecated: [TIntSeq: IntSeq].} proc tokEnd(p: RstParser): int = result = p.tok[p.idx].col + len(p.tok[p.idx].symbol) - 1 @@ -1408,8 +1406,6 @@ type hasArg, hasOptions, argIsFile, argIsWord DirFlags = set[DirFlag] SectionParser = proc (p: var RstParser): PRstNode {.nimcall.} -{.deprecated: [TDirFlag: DirFlag, TDirFlags: DirFlags, - TSectionParser: SectionParser].} proc parseDirective(p: var RstParser, flags: DirFlags): PRstNode = ## Parses arguments and options for a directive block. diff --git a/lib/packages/docutils/rstast.nim b/lib/packages/docutils/rstast.nim index 7be4470c1..f3596b571 100644 --- a/lib/packages/docutils/rstast.nim +++ b/lib/packages/docutils/rstast.nim @@ -70,8 +70,6 @@ type ## the document or the section level*: int ## valid for some node kinds sons*: RstNodeSeq ## the node's sons -{.deprecated: [TRstNodeKind: RstNodeKind, TRstNodeSeq: RstNodeSeq, - TRstNode: RstNode].} proc len*(n: PRstNode): int = result = len(n.sons) @@ -99,7 +97,6 @@ type RenderContext {.pure.} = object indent: int verbatim: int -{.deprecated: [TRenderContext: RenderContext].} proc renderRstToRst(d: var RenderContext, n: PRstNode, result: var string) {.gcsafe.} diff --git a/lib/packages/docutils/rstgen.nim b/lib/packages/docutils/rstgen.nim index e6c95b59e..03a27017a 100644 --- a/lib/packages/docutils/rstgen.nim +++ b/lib/packages/docutils/rstgen.nim @@ -208,6 +208,7 @@ proc nextSplitPoint*(s: string, start: int): int = dec(result) # last valid index proc esc*(target: OutputTarget, s: string, splitAfter = -1): string = + ## Escapes the HTML. result = "" if splitAfter >= 0: var partLen = 0 @@ -769,43 +770,45 @@ proc renderTocEntries*(d: var RstGenerator, j: var int, lvl: int, result.add(tmp) proc renderImage(d: PDoc, n: PRstNode, result: var string) = - template valid(s): bool = - s.len > 0 and allCharsInSet(s, {'.','/',':','%','_','\\','\128'..'\xFF'} + - Digits + Letters + WhiteSpace) let arg = getArgument(n) - isObject = arg.toLower().endsWith(".svg") var options = "" - content = "" - var s = getFieldValue(n, "scale") - if s.valid: dispA(d.target, options, if isObject: "" else: " scale=\"$1\"", - " scale=$1", [strip(s)]) - s = getFieldValue(n, "height") - if s.valid: dispA(d.target, options, " height=\"$1\"", " height=$1", [strip(s)]) + var s = esc(d.target, getFieldValue(n, "scale").strip()) + if s.len > 0: + dispA(d.target, options, " scale=\"$1\"", " scale=$1", [s]) - s = getFieldValue(n, "width") - if s.valid: dispA(d.target, options, " width=\"$1\"", " width=$1", [strip(s)]) + s = esc(d.target, getFieldValue(n, "height").strip()) + if s.len > 0: + dispA(d.target, options, " height=\"$1\"", " height=$1", [s]) - s = getFieldValue(n, "alt") - if s.valid: - # <object> displays its content if it cannot render the image - if isObject: dispA(d.target, content, "$1", "", [strip(s)]) - else: dispA(d.target, options, " alt=\"$1\"", "", [strip(s)]) + s = esc(d.target, getFieldValue(n, "width").strip()) + if s.len > 0: + dispA(d.target, options, " width=\"$1\"", " width=$1", [s]) - s = getFieldValue(n, "align") - if s.valid: dispA(d.target, options, " align=\"$1\"", "", [strip(s)]) + s = esc(d.target, getFieldValue(n, "alt").strip()) + if s.len > 0: + dispA(d.target, options, " alt=\"$1\"", "", [s]) + + s = esc(d.target, getFieldValue(n, "align").strip()) + if s.len > 0: + dispA(d.target, options, " align=\"$1\"", "", [s]) if options.len > 0: options = dispF(d.target, "$1", "[$1]", [options]) - if arg.valid: - let htmlOut = if isObject: - "<object data=\"$1\" type=\"image/svg+xml\"$2 >" & content & "</object>" - else: - "<img src=\"$1\"$2 />" - dispA(d.target, result, htmlOut, "\\includegraphics$2{$1}", - [arg, options]) + var htmlOut = "" + if arg.endsWith(".mp4") or arg.endsWith(".ogg") or + arg.endsWith(".webm"): + htmlOut = """ + <video src="$1"$2 autoPlay='true' loop='true' muted='true'> + Sorry, your browser doesn't support embedded videos + </video> + """ + else: + htmlOut = "<img src=\"$1\"$2/>" + dispA(d.target, result, htmlOut, "\\includegraphics$2{$1}", + [esc(d.target, arg), options]) if len(n) >= 3: renderRstToOut(d, n.sons[2], result) proc renderSmiley(d: PDoc, n: PRstNode, result: var string) = @@ -820,7 +823,7 @@ proc parseCodeBlockField(d: PDoc, n: PRstNode, params: var CodeBlockParams) = ## ## This supports the special ``default-language`` internal string generated ## by the ``rst`` module to communicate a specific default language. - case n.getArgument.toLower + case n.getArgument.toLowerAscii of "number-lines": params.numberLines = true # See if the field has a parameter specifying a different line than 1. @@ -836,8 +839,11 @@ proc parseCodeBlockField(d: PDoc, n: PRstNode, params: var CodeBlockParams) = params.filename = n.getFieldValue.strip of "test": params.testCmd = n.getFieldValue.strip - if params.testCmd.len == 0: params.testCmd = "nim c -r $1" - of "status": + if params.testCmd.len == 0: + params.testCmd = "nim c -r $1" + else: + params.testCmd = unescape(params.testCmd) + of "status", "exitcode": var status: int if parseInt(n.getFieldValue, status) > 0: params.status = status @@ -878,7 +884,8 @@ proc buildLinesHTMLTable(d: PDoc; params: CodeBlockParams, code: string): inc d.listingCounter let id = $d.listingCounter if not params.numberLines: - result = (d.config.getOrDefault"doc.listing_start" % [id, $params.lang], + result = (d.config.getOrDefault"doc.listing_start" % + [id, sourceLanguageToStr[params.lang]], d.config.getOrDefault"doc.listing_end" % id) return @@ -891,7 +898,8 @@ proc buildLinesHTMLTable(d: PDoc; params: CodeBlockParams, code: string): line.inc codeLines.dec result.beginTable.add("</pre></td><td>" & ( - d.config.getOrDefault"doc.listing_start" % [id, $params.lang])) + d.config.getOrDefault"doc.listing_start" % + [id, sourceLanguageToStr[params.lang]])) result.endTable = (d.config.getOrDefault"doc.listing_end" % id) & "</td></tr></tbody></table>" & ( d.config.getOrDefault"doc.listing_button" % id) @@ -941,7 +949,7 @@ proc renderCodeBlock(d: PDoc, n: PRstNode, result: var string) = proc renderContainer(d: PDoc, n: PRstNode, result: var string) = var tmp = "" renderRstToOut(d, n.sons[2], tmp) - var arg = strip(getArgument(n)) + var arg = esc(d.target, strip(getArgument(n))) if arg == "": dispA(d.target, result, "<div>$1</div>", "$1", [tmp]) else: |