smileys configurable; safer image attribute handling
This commit is contained in:
parent
51dd4b7601
commit
80b8361187
3 changed files with 28 additions and 21 deletions
|
|
@ -254,11 +254,11 @@ proc getTokens(buffer: string, skipPounds: bool, tokens: var TTokenSeq): int =
|
||||||
|
|
||||||
type
|
type
|
||||||
TLevelMap = array[char, int]
|
TLevelMap = array[char, int]
|
||||||
TSubstitution{.final.} = object
|
TSubstitution = object
|
||||||
key*: string
|
key*: string
|
||||||
value*: PRstNode
|
value*: PRstNode
|
||||||
|
|
||||||
TSharedState {.final.} = object
|
TSharedState = object
|
||||||
options: TRstParseOptions # parsing options
|
options: TRstParseOptions # parsing options
|
||||||
uLevel, oLevel: int # counters for the section levels
|
uLevel, oLevel: int # counters for the section levels
|
||||||
subs: seq[TSubstitution] # substitutions
|
subs: seq[TSubstitution] # substitutions
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@ type
|
||||||
seenIndexTerms: Table[string, int] ## \
|
seenIndexTerms: Table[string, int] ## \
|
||||||
## Keeps count of same text index terms to generate different identifiers
|
## Keeps count of same text index terms to generate different identifiers
|
||||||
## for hyperlinks. See renderIndexTerm proc for details.
|
## for hyperlinks. See renderIndexTerm proc for details.
|
||||||
|
smileyFrmt: string ## How to massage the smiley filename.
|
||||||
|
|
||||||
PDoc = var TRstGenerator ## Alias to type less.
|
PDoc = var TRstGenerator ## Alias to type less.
|
||||||
|
|
||||||
|
|
@ -79,8 +80,9 @@ proc init(p: var CodeBlockParams) =
|
||||||
proc initRstGenerator*(g: var TRstGenerator, target: TOutputTarget,
|
proc initRstGenerator*(g: var TRstGenerator, target: TOutputTarget,
|
||||||
config: StringTableRef, filename: string,
|
config: StringTableRef, filename: string,
|
||||||
options: TRstParseOptions,
|
options: TRstParseOptions,
|
||||||
findFile: TFindFileHandler,
|
findFile: TFindFileHandler=nil,
|
||||||
msgHandler: TMsgHandler) =
|
msgHandler: TMsgHandler=nil,
|
||||||
|
smileyFrmt = "/images/smilies/$1.gif") =
|
||||||
## Initializes a ``TRstGenerator``.
|
## Initializes a ``TRstGenerator``.
|
||||||
##
|
##
|
||||||
## You need to call this before using a ``TRstGenerator`` with any other
|
## You need to call this before using a ``TRstGenerator`` with any other
|
||||||
|
|
@ -121,10 +123,7 @@ proc initRstGenerator*(g: var TRstGenerator, target: TOutputTarget,
|
||||||
## import packages/docutils/rstgen
|
## import packages/docutils/rstgen
|
||||||
##
|
##
|
||||||
## var gen: TRstGenerator
|
## var gen: TRstGenerator
|
||||||
##
|
## gen.initRstGenerator(outHtml, defaultConfig(), "filename", {})
|
||||||
## gen.initRstGenerator(outHtml, defaultConfig(),
|
|
||||||
## "filename", {}, nil, nil)
|
|
||||||
|
|
||||||
g.config = config
|
g.config = config
|
||||||
g.target = target
|
g.target = target
|
||||||
g.tocPart = @[]
|
g.tocPart = @[]
|
||||||
|
|
@ -143,6 +142,7 @@ proc initRstGenerator*(g: var TRstGenerator, target: TOutputTarget,
|
||||||
let s = config["split.item.toc"]
|
let s = config["split.item.toc"]
|
||||||
if s != "": g.splitAfter = parseInt(s)
|
if s != "": g.splitAfter = parseInt(s)
|
||||||
for i in low(g.meta)..high(g.meta): g.meta[i] = ""
|
for i in low(g.meta)..high(g.meta): g.meta[i] = ""
|
||||||
|
g.smileyFrmt = smileyFrmt
|
||||||
|
|
||||||
proc writeIndexFile*(g: var TRstGenerator, outfile: string) =
|
proc writeIndexFile*(g: var TRstGenerator, outfile: string) =
|
||||||
## Writes the current index buffer to the specified output file.
|
## Writes the current index buffer to the specified output file.
|
||||||
|
|
@ -746,33 +746,39 @@ proc renderTocEntries*(d: var TRstGenerator, j: var int, lvl: int,
|
||||||
result.add(tmp)
|
result.add(tmp)
|
||||||
|
|
||||||
proc renderImage(d: PDoc, n: PRstNode, result: var string) =
|
proc renderImage(d: PDoc, n: PRstNode, result: var string) =
|
||||||
|
template valid(s): expr =
|
||||||
|
s.len > 0 and allCharsInSet(s, {'/',':','%','_','\\','\128'..'\xFF'} +
|
||||||
|
Digits + Letters + WhiteSpace)
|
||||||
|
|
||||||
var options = ""
|
var options = ""
|
||||||
var s = getFieldValue(n, "scale")
|
var s = getFieldValue(n, "scale")
|
||||||
if s != "": dispA(d.target, options, " scale=\"$1\"", " scale=$1", [strip(s)])
|
if s.valid: dispA(d.target, options, " scale=\"$1\"", " scale=$1", [strip(s)])
|
||||||
|
|
||||||
s = getFieldValue(n, "height")
|
s = getFieldValue(n, "height")
|
||||||
if s != "": dispA(d.target, options, " height=\"$1\"", " height=$1", [strip(s)])
|
if s.valid: dispA(d.target, options, " height=\"$1\"", " height=$1", [strip(s)])
|
||||||
|
|
||||||
s = getFieldValue(n, "width")
|
s = getFieldValue(n, "width")
|
||||||
if s != "": dispA(d.target, options, " width=\"$1\"", " width=$1", [strip(s)])
|
if s.valid: dispA(d.target, options, " width=\"$1\"", " width=$1", [strip(s)])
|
||||||
|
|
||||||
s = getFieldValue(n, "alt")
|
s = getFieldValue(n, "alt")
|
||||||
if s != "": dispA(d.target, options, " alt=\"$1\"", "", [strip(s)])
|
if s.valid: dispA(d.target, options, " alt=\"$1\"", "", [strip(s)])
|
||||||
|
|
||||||
s = getFieldValue(n, "align")
|
s = getFieldValue(n, "align")
|
||||||
if s != "": dispA(d.target, options, " align=\"$1\"", "", [strip(s)])
|
if s.valid: dispA(d.target, options, " align=\"$1\"", "", [strip(s)])
|
||||||
|
|
||||||
if options.len > 0: options = dispF(d.target, "$1", "[$1]", [options])
|
if options.len > 0: options = dispF(d.target, "$1", "[$1]", [options])
|
||||||
|
|
||||||
|
let arg = getArgument(n)
|
||||||
|
if arg.valid:
|
||||||
dispA(d.target, result, "<img src=\"$1\"$2 />", "\\includegraphics$2{$1}",
|
dispA(d.target, result, "<img src=\"$1\"$2 />", "\\includegraphics$2{$1}",
|
||||||
[getArgument(n), options])
|
[arg, options])
|
||||||
if len(n) >= 3: renderRstToOut(d, n.sons[2], result)
|
if len(n) >= 3: renderRstToOut(d, n.sons[2], result)
|
||||||
|
|
||||||
proc renderSmiley(d: PDoc, n: PRstNode, result: var string) =
|
proc renderSmiley(d: PDoc, n: PRstNode, result: var string) =
|
||||||
dispA(d.target, result,
|
dispA(d.target, result,
|
||||||
"""<img src="/images/smilies/$1.gif" width="15"
|
"""<img src="$1" width="15"
|
||||||
height="17" hspace="2" vspace="2" />""",
|
height="17" hspace="2" vspace="2" class="smiley" />""",
|
||||||
"\\includegraphics{$1}", [n.text])
|
"\\includegraphics{$1}", [d.smileyFrmt % n.text])
|
||||||
|
|
||||||
proc parseCodeBlockField(d: PDoc, n: PRstNode, params: var CodeBlockParams) =
|
proc parseCodeBlockField(d: PDoc, n: PRstNode, params: var CodeBlockParams) =
|
||||||
## Parses useful fields which can appear before a code block.
|
## Parses useful fields which can appear before a code block.
|
||||||
|
|
|
||||||
1
todo.txt
1
todo.txt
|
|
@ -1,6 +1,7 @@
|
||||||
version 0.10
|
version 0.10
|
||||||
============
|
============
|
||||||
|
|
||||||
|
- introduce ``--experimental`` switch
|
||||||
- make nimble part of the distribution
|
- make nimble part of the distribution
|
||||||
- split idetools into separate tool
|
- split idetools into separate tool
|
||||||
- split docgen into separate tool
|
- split docgen into separate tool
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue