This commit is contained in:
parent
924ab3adea
commit
a7bb973a24
6 changed files with 76 additions and 56 deletions
|
|
@ -446,22 +446,22 @@ proc nodeToHighlightedHtml(d: PDoc; n: PNode; result: var Rope; renderFlags: TRe
|
|||
"\\spanIdentifier{$1}", [escLit])
|
||||
of tkSpaces, tkInvalid:
|
||||
result.add(literal)
|
||||
of tkCurlyDotLe:
|
||||
of tkHideableStart:
|
||||
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>
|
||||
else:
|
||||
# 1st span is required for the JS to work properly
|
||||
fun """
|
||||
<span>
|
||||
<span class="Other pragmadots">...</span>
|
||||
</span>
|
||||
<span class="pragmawrap">
|
||||
<span class="Other">$1</span>
|
||||
<span class="pragma">""".replace("\n", "") # Must remove newlines because wrapped in a <pre>
|
||||
of tkCurlyDotRi:
|
||||
<span class="pragmawrap">""".replace("\n", "") # Must remove newlines because wrapped in a <pre>
|
||||
of tkHideableEnd:
|
||||
template fun(s) = dispA(d.conf, result, s, "\\spanOther{$1}", [escLit])
|
||||
if renderRunnableExamples in renderFlags: fun "$1"
|
||||
else: fun """
|
||||
</span>
|
||||
<span class="Other">$1</span>
|
||||
</span>""".replace("\n", "")
|
||||
else: fun "</span>"
|
||||
of tkCurlyDotLe: dispA(d.conf, result, "$1", "\\spanOther{$1}", [escLit])
|
||||
of tkCurlyDotRi: dispA(d.conf, result, "$1", "\\spanOther{$1}", [escLit])
|
||||
of tkParLe, tkParRi, tkBracketLe, tkBracketRi, tkCurlyLe, tkCurlyRi,
|
||||
tkBracketDotLe, tkBracketDotRi, tkParDotLe,
|
||||
tkParDotRi, tkComma, tkSemiColon, tkColon, tkEquals, tkDot, tkDotDot,
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ type
|
|||
tkDot = ".", tkDotDot = "..", tkBracketLeColon = "[:",
|
||||
tkOpr, tkComment, tkAccent = "`",
|
||||
# these are fake tokens used by renderer.nim
|
||||
tkSpaces, tkInfixOpr, tkPrefixOpr, tkPostfixOpr
|
||||
tkSpaces, tkInfixOpr, tkPrefixOpr, tkPostfixOpr, tkHideableStart, tkHideableEnd
|
||||
|
||||
TokTypes* = set[TokType]
|
||||
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ proc dedent(g: var TSrcGen) =
|
|||
proc put(g: var TSrcGen, kind: TokType, s: string; sym: PSym = nil) =
|
||||
if kind != tkSpaces:
|
||||
addPendingNL(g)
|
||||
if s.len > 0:
|
||||
if s.len > 0 or kind in {tkHideableStart, tkHideableEnd}:
|
||||
addTok(g, kind, s, sym)
|
||||
else:
|
||||
g.pendingWhitespace = s.len
|
||||
|
|
@ -587,13 +587,30 @@ proc putWithSpace(g: var TSrcGen, kind: TokType, s: string) =
|
|||
put(g, kind, s)
|
||||
put(g, tkSpaces, Space)
|
||||
|
||||
proc isHideable(config: ConfigRef, n: PNode): bool =
|
||||
# xxx compare `ident` directly with `getIdent(cache, wRaises)`, but
|
||||
# this requires a `cache`.
|
||||
case n.kind
|
||||
of nkExprColonExpr: result = n[0].kind == nkIdent and n[0].ident.s in ["raises", "tags", "extern"]
|
||||
of nkIdent: result = n.ident.s in ["gcsafe"]
|
||||
else: result = false
|
||||
|
||||
proc gcommaAux(g: var TSrcGen, n: PNode, ind: int, start: int = 0,
|
||||
theEnd: int = - 1, separator = tkComma) =
|
||||
let inPragma = g.inPragma == 1 # just the top-level
|
||||
var inHideable = false
|
||||
for i in start..n.len + theEnd:
|
||||
var c = i < n.len + theEnd
|
||||
var sublen = lsub(g, n[i]) + ord(c)
|
||||
if not fits(g, g.lineLen + sublen) and (ind + sublen < MaxLineLen): optNL(g, ind)
|
||||
let oldLen = g.tokens.len
|
||||
if inPragma:
|
||||
if not inHideable and isHideable(g.config, n[i]):
|
||||
inHideable = true
|
||||
put(g, tkHideableStart, "")
|
||||
elif inHideable and not isHideable(g.config, n[i]):
|
||||
inHideable = false
|
||||
put(g, tkHideableEnd, "")
|
||||
gsub(g, n[i])
|
||||
if c:
|
||||
if g.tokens.len > oldLen:
|
||||
|
|
@ -601,6 +618,9 @@ proc gcommaAux(g: var TSrcGen, n: PNode, ind: int, start: int = 0,
|
|||
if shouldRenderComment(g) and hasCom(n[i]):
|
||||
gcoms(g)
|
||||
optNL(g, ind)
|
||||
if inHideable:
|
||||
put(g, tkHideableEnd, "")
|
||||
inHideable = false
|
||||
|
||||
proc gcomma(g: var TSrcGen, n: PNode, c: TContext, start: int = 0,
|
||||
theEnd: int = - 1) =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue