parent
bc42e9aa98
commit
5beed56d0a
2 changed files with 21 additions and 20 deletions
|
|
@ -370,6 +370,7 @@ proc nodeToHighlightedHtml(d: PDoc; n: PNode; result: var Rope; renderFlags: TRe
|
||||||
var kind = tkEof
|
var kind = tkEof
|
||||||
var tokenPos = 0
|
var tokenPos = 0
|
||||||
var procTokenPos = 0
|
var procTokenPos = 0
|
||||||
|
template escLit(): untyped = rope(esc(d.target, literal))
|
||||||
while true:
|
while true:
|
||||||
getNextTok(r, kind, literal)
|
getNextTok(r, kind, literal)
|
||||||
inc tokenPos
|
inc tokenPos
|
||||||
|
|
@ -378,7 +379,7 @@ proc nodeToHighlightedHtml(d: PDoc; n: PNode; result: var Rope; renderFlags: TRe
|
||||||
break
|
break
|
||||||
of tkComment:
|
of tkComment:
|
||||||
dispA(d.conf, result, "<span class=\"Comment\">$1</span>", "\\spanComment{$1}",
|
dispA(d.conf, result, "<span class=\"Comment\">$1</span>", "\\spanComment{$1}",
|
||||||
[rope(esc(d.target, literal))])
|
[escLit])
|
||||||
of tokKeywordLow..tokKeywordHigh:
|
of tokKeywordLow..tokKeywordHigh:
|
||||||
if kind in {tkProc, tkMethod, tkIterator, tkMacro, tkTemplate, tkFunc, tkConverter}:
|
if kind in {tkProc, tkMethod, tkIterator, tkMacro, tkTemplate, tkFunc, tkConverter}:
|
||||||
procTokenPos = tokenPos
|
procTokenPos = tokenPos
|
||||||
|
|
@ -386,53 +387,53 @@ proc nodeToHighlightedHtml(d: PDoc; n: PNode; result: var Rope; renderFlags: TRe
|
||||||
[rope(literal)])
|
[rope(literal)])
|
||||||
of tkOpr:
|
of tkOpr:
|
||||||
dispA(d.conf, result, "<span class=\"Operator\">$1</span>", "\\spanOperator{$1}",
|
dispA(d.conf, result, "<span class=\"Operator\">$1</span>", "\\spanOperator{$1}",
|
||||||
[rope(esc(d.target, literal))])
|
[escLit])
|
||||||
of tkStrLit..tkTripleStrLit:
|
of tkStrLit..tkTripleStrLit:
|
||||||
dispA(d.conf, result, "<span class=\"StringLit\">$1</span>",
|
dispA(d.conf, result, "<span class=\"StringLit\">$1</span>",
|
||||||
"\\spanStringLit{$1}", [rope(esc(d.target, literal))])
|
"\\spanStringLit{$1}", [escLit])
|
||||||
of tkCharLit:
|
of tkCharLit:
|
||||||
dispA(d.conf, result, "<span class=\"CharLit\">$1</span>", "\\spanCharLit{$1}",
|
dispA(d.conf, result, "<span class=\"CharLit\">$1</span>", "\\spanCharLit{$1}",
|
||||||
[rope(esc(d.target, literal))])
|
[escLit])
|
||||||
of tkIntLit..tkUInt64Lit:
|
of tkIntLit..tkUInt64Lit:
|
||||||
dispA(d.conf, result, "<span class=\"DecNumber\">$1</span>",
|
dispA(d.conf, result, "<span class=\"DecNumber\">$1</span>",
|
||||||
"\\spanDecNumber{$1}", [rope(esc(d.target, literal))])
|
"\\spanDecNumber{$1}", [escLit])
|
||||||
of tkFloatLit..tkFloat128Lit:
|
of tkFloatLit..tkFloat128Lit:
|
||||||
dispA(d.conf, result, "<span class=\"FloatNumber\">$1</span>",
|
dispA(d.conf, result, "<span class=\"FloatNumber\">$1</span>",
|
||||||
"\\spanFloatNumber{$1}", [rope(esc(d.target, literal))])
|
"\\spanFloatNumber{$1}", [escLit])
|
||||||
of tkSymbol:
|
of tkSymbol:
|
||||||
let s = getTokSym(r)
|
let s = getTokSym(r)
|
||||||
# -2 because of the whitespace in between:
|
# -2 because of the whitespace in between:
|
||||||
if procTokenPos == tokenPos-2 and procLink != nil:
|
if procTokenPos == tokenPos-2 and procLink != nil:
|
||||||
dispA(d.conf, result, "<a href=\"#$2\"><span class=\"Identifier\">$1</span></a>",
|
dispA(d.conf, result, "<a href=\"#$2\"><span class=\"Identifier\">$1</span></a>",
|
||||||
"\\spanIdentifier{$1}", [rope(esc(d.target, literal)), procLink])
|
"\\spanIdentifier{$1}", [escLit, procLink])
|
||||||
elif s != nil and s.kind in {skType, skVar, skLet, skConst} and
|
elif s != nil and s.kind in {skType, skVar, skLet, skConst} and
|
||||||
sfExported in s.flags and s.owner != nil and
|
sfExported in s.flags and s.owner != nil and
|
||||||
belongsToPackage(d.conf, s.owner) and d.target == outHtml:
|
belongsToPackage(d.conf, s.owner) and d.target == outHtml:
|
||||||
let external = externalDep(d, s.owner)
|
let external = externalDep(d, s.owner)
|
||||||
result.addf "<a href=\"$1#$2\"><span class=\"Identifier\">$3</span></a>",
|
result.addf "<a href=\"$1#$2\"><span class=\"Identifier\">$3</span></a>",
|
||||||
[rope changeFileExt(external, "html"), rope literal,
|
[rope changeFileExt(external, "html"), rope literal,
|
||||||
rope(esc(d.target, literal))]
|
escLit]
|
||||||
else:
|
else:
|
||||||
dispA(d.conf, result, "<span class=\"Identifier\">$1</span>",
|
dispA(d.conf, result, "<span class=\"Identifier\">$1</span>",
|
||||||
"\\spanIdentifier{$1}", [rope(esc(d.target, literal))])
|
"\\spanIdentifier{$1}", [escLit])
|
||||||
of tkSpaces, tkInvalid:
|
of tkSpaces, tkInvalid:
|
||||||
result.add(literal)
|
result.add(literal)
|
||||||
of tkCurlyDotLe:
|
of tkCurlyDotLe:
|
||||||
dispA(d.conf, result, "<span>" & # This span is required for the JS to work properly
|
template fun(s) = dispA(d.conf, result, s, "\\spanOther{$1}", [escLit])
|
||||||
|
if renderRunnableExamples in renderFlags: fun "$1"
|
||||||
|
else: fun: "<span>" & # This span is required for the JS to work properly
|
||||||
"""<span class="Other">{</span><span class="Other pragmadots">...</span><span class="Other">}</span>
|
"""<span class="Other">{</span><span class="Other pragmadots">...</span><span class="Other">}</span>
|
||||||
</span>
|
</span>
|
||||||
<span class="pragmawrap">
|
<span class="pragmawrap">
|
||||||
<span class="Other">$1</span>
|
<span class="Other">$1</span>
|
||||||
<span class="pragma">""".replace("\n", ""), # Must remove newlines because wrapped in a <pre>
|
<span class="pragma">""".replace("\n", "") # Must remove newlines because wrapped in a <pre>
|
||||||
"\\spanOther{$1}",
|
|
||||||
[rope(esc(d.target, literal))])
|
|
||||||
of tkCurlyDotRi:
|
of tkCurlyDotRi:
|
||||||
dispA(d.conf, result, """
|
template fun(s) = dispA(d.conf, result, s, "\\spanOther{$1}", [escLit])
|
||||||
|
if renderRunnableExamples in renderFlags: fun "$1"
|
||||||
|
else: fun """
|
||||||
</span>
|
</span>
|
||||||
<span class="Other">$1</span>
|
<span class="Other">$1</span>
|
||||||
</span>""".replace("\n", ""),
|
</span>""".replace("\n", "")
|
||||||
"\\spanOther{$1}",
|
|
||||||
[rope(esc(d.target, literal))])
|
|
||||||
of tkParLe, tkParRi, tkBracketLe, tkBracketRi, tkCurlyLe, tkCurlyRi,
|
of tkParLe, tkParRi, tkBracketLe, tkBracketRi, tkCurlyLe, tkCurlyRi,
|
||||||
tkBracketDotLe, tkBracketDotRi, tkParDotLe,
|
tkBracketDotLe, tkBracketDotRi, tkParDotLe,
|
||||||
tkParDotRi, tkComma, tkSemiColon, tkColon, tkEquals, tkDot, tkDotDot,
|
tkParDotRi, tkComma, tkSemiColon, tkColon, tkEquals, tkDot, tkDotDot,
|
||||||
|
|
@ -440,7 +441,7 @@ proc nodeToHighlightedHtml(d: PDoc; n: PNode; result: var Rope; renderFlags: TRe
|
||||||
tkGStrLit, tkGTripleStrLit, tkInfixOpr, tkPrefixOpr, tkPostfixOpr,
|
tkGStrLit, tkGTripleStrLit, tkInfixOpr, tkPrefixOpr, tkPostfixOpr,
|
||||||
tkBracketLeColon:
|
tkBracketLeColon:
|
||||||
dispA(d.conf, result, "<span class=\"Other\">$1</span>", "\\spanOther{$1}",
|
dispA(d.conf, result, "<span class=\"Other\">$1</span>", "\\spanOther{$1}",
|
||||||
[rope(esc(d.target, literal))])
|
[escLit])
|
||||||
|
|
||||||
proc testExample(d: PDoc; ex: PNode) =
|
proc testExample(d: PDoc; ex: PNode) =
|
||||||
if d.conf.errorCounter > 0: return
|
if d.conf.errorCounter > 0: return
|
||||||
|
|
@ -525,7 +526,7 @@ proc getAllRunnableExamplesRec(d: PDoc; n, orig: PNode; dest: var Rope) =
|
||||||
for b in body:
|
for b in body:
|
||||||
if i > 0: dest.add "\n"
|
if i > 0: dest.add "\n"
|
||||||
inc i
|
inc i
|
||||||
nodeToHighlightedHtml(d, b, dest, {}, nil)
|
nodeToHighlightedHtml(d, b, dest, {renderRunnableExamples}, nil)
|
||||||
dest.add(d.config.getOrDefault"doc.listing_end" % id)
|
dest.add(d.config.getOrDefault"doc.listing_end" % id)
|
||||||
else: discard
|
else: discard
|
||||||
for i in 0..<n.safeLen:
|
for i in 0..<n.safeLen:
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ import
|
||||||
type
|
type
|
||||||
TRenderFlag* = enum
|
TRenderFlag* = enum
|
||||||
renderNone, renderNoBody, renderNoComments, renderDocComments,
|
renderNone, renderNoBody, renderNoComments, renderDocComments,
|
||||||
renderNoPragmas, renderIds, renderNoProcDefs, renderSyms
|
renderNoPragmas, renderIds, renderNoProcDefs, renderSyms, renderRunnableExamples
|
||||||
TRenderFlags* = set[TRenderFlag]
|
TRenderFlags* = set[TRenderFlag]
|
||||||
TRenderTok* = object
|
TRenderTok* = object
|
||||||
kind*: TTokType
|
kind*: TTokType
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue