Skip to content

Commit

Permalink
fixes wrong indentation (#23145)
Browse files Browse the repository at this point in the history
4 spaces => 2 spaces
  • Loading branch information
ringabout authored Dec 31, 2023
1 parent 9483b11 commit 9659da9
Showing 1 changed file with 104 additions and 104 deletions.
208 changes: 104 additions & 104 deletions lib/packages/docutils/rst.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3652,114 +3652,114 @@ proc preparePass2*(s: var PRstSharedState, mainNode: PRstNode, importdoc = true)
loadIdxFile(s, origFilename)

proc resolveLink(s: PRstSharedState, n: PRstNode) : PRstNode =
# Associate this link alias with its target and change node kind to
# rnHyperlink or rnInternalRef appropriately.
var desc, alias: PRstNode
if n.kind == rnPandocRef: # link like [desc][alias]
desc = n.sons[0]
alias = n.sons[1]
else: # n.kind == rnRstRef, link like `desc=alias`_
desc = n
alias = n
type LinkDef = object
ar: AnchorRule
priority: int
tooltip: string
target: PRstNode
info: TLineInfo
externFilename: string
# when external anchor: origin filename where anchor was defined
isTitle: bool
proc cmp(x, y: LinkDef): int =
result = cmp(x.priority, y.priority)
if result == 0:
result = cmp(x.target, y.target)
var foundLinks: seq[LinkDef]
let refn = rstnodeToRefname(alias)
var hyperlinks = findRef(s, refn)
for y in hyperlinks:
foundLinks.add LinkDef(ar: arHyperlink, priority: refPriority(y.kind),
target: y.value, info: y.info,
tooltip: "(" & $y.kind & ")")
let substRst = findMainAnchorRst(s, alias.addNodes, n.info)
template getExternFilename(subst: AnchorSubst): string =
if subst.kind == arExternalRst or
(subst.kind == arNim and subst.external):
getFilename(s, subst)
else: ""
for subst in substRst:
var refname, fullRefname: string
if subst.kind == arInternalRst:
refname = subst.target.anchor
fullRefname = refname
else: # arExternalRst
refname = subst.refnameExt
fullRefname = s.idxImports[getFilename(s, subst)].linkRelPath &
"/" & refname
let anchorType =
if subst.kind == arInternalRst: subst.anchorType
else: subst.anchorTypeExt # arExternalRst
# Associate this link alias with its target and change node kind to
# rnHyperlink or rnInternalRef appropriately.
var desc, alias: PRstNode
if n.kind == rnPandocRef: # link like [desc][alias]
desc = n.sons[0]
alias = n.sons[1]
else: # n.kind == rnRstRef, link like `desc=alias`_
desc = n
alias = n
type LinkDef = object
ar: AnchorRule
priority: int
tooltip: string
target: PRstNode
info: TLineInfo
externFilename: string
# when external anchor: origin filename where anchor was defined
isTitle: bool
proc cmp(x, y: LinkDef): int =
result = cmp(x.priority, y.priority)
if result == 0:
result = cmp(x.target, y.target)
var foundLinks: seq[LinkDef]
let refn = rstnodeToRefname(alias)
var hyperlinks = findRef(s, refn)
for y in hyperlinks:
foundLinks.add LinkDef(ar: arHyperlink, priority: refPriority(y.kind),
target: y.value, info: y.info,
tooltip: "(" & $y.kind & ")")
let substRst = findMainAnchorRst(s, alias.addNodes, n.info)
template getExternFilename(subst: AnchorSubst): string =
if subst.kind == arExternalRst or
(subst.kind == arNim and subst.external):
getFilename(s, subst)
else: ""
for subst in substRst:
var refname, fullRefname: string
if subst.kind == arInternalRst:
refname = subst.target.anchor
fullRefname = refname
else: # arExternalRst
refname = subst.refnameExt
fullRefname = s.idxImports[getFilename(s, subst)].linkRelPath &
"/" & refname
let anchorType =
if subst.kind == arInternalRst: subst.anchorType
else: subst.anchorTypeExt # arExternalRst
foundLinks.add LinkDef(ar: subst.kind, priority: subst.priority,
target: newLeaf(fullRefname),
info: subst.info,
externFilename: getExternFilename(subst),
isTitle: isDocumentationTitle(refname),
tooltip: "(" & $anchorType & ")")
# find anchors automatically generated from Nim symbols
if roNimFile in s.options or s.nimFileImported:
let substNim = findMainAnchorNim(s, signature=alias, n.info)
for subst in substNim:
let fullRefname =
if subst.external:
s.idxImports[getFilename(s, subst)].linkRelPath &
"/" & subst.refname
else: subst.refname
foundLinks.add LinkDef(ar: subst.kind, priority: subst.priority,
target: newLeaf(fullRefname),
info: subst.info,
externFilename: getExternFilename(subst),
isTitle: isDocumentationTitle(refname),
tooltip: "(" & $anchorType & ")")
# find anchors automatically generated from Nim symbols
if roNimFile in s.options or s.nimFileImported:
let substNim = findMainAnchorNim(s, signature=alias, n.info)
for subst in substNim:
let fullRefname =
if subst.external:
s.idxImports[getFilename(s, subst)].linkRelPath &
"/" & subst.refname
else: subst.refname
foundLinks.add LinkDef(ar: subst.kind, priority: subst.priority,
target: newLeaf(fullRefname),
externFilename: getExternFilename(subst),
isTitle: isDocumentationTitle(subst.refname),
info: subst.info, tooltip: subst.tooltip)
foundLinks.sort(cmp = cmp, order = Descending)
let aliasStr = addNodes(alias)
if foundLinks.len >= 1:
isTitle: isDocumentationTitle(subst.refname),
info: subst.info, tooltip: subst.tooltip)
foundLinks.sort(cmp = cmp, order = Descending)
let aliasStr = addNodes(alias)
if foundLinks.len >= 1:
if foundLinks[0].externFilename != "":
s.idxImports[foundLinks[0].externFilename].used = true
let kind = if foundLinks[0].ar in {arHyperlink, arExternalRst}: rnHyperlink
elif foundLinks[0].ar == arNim:
if foundLinks[0].externFilename == "": rnNimdocRef
else: rnHyperlink
else: rnInternalRef
result = newRstNode(kind)
let documentName = # filename without ext for `.nim`, title for `.md`
if foundLinks[0].ar == arNim:
changeFileExt(foundLinks[0].externFilename.extractFilename, "")
elif foundLinks[0].externFilename != "":
s.idxImports[foundLinks[0].externFilename].title
else: foundLinks[0].externFilename.extractFilename
let linkText =
if foundLinks[0].externFilename != "":
s.idxImports[foundLinks[0].externFilename].used = true
let kind = if foundLinks[0].ar in {arHyperlink, arExternalRst}: rnHyperlink
elif foundLinks[0].ar == arNim:
if foundLinks[0].externFilename == "": rnNimdocRef
else: rnHyperlink
else: rnInternalRef
result = newRstNode(kind)
let documentName = # filename without ext for `.nim`, title for `.md`
if foundLinks[0].ar == arNim:
changeFileExt(foundLinks[0].externFilename.extractFilename, "")
elif foundLinks[0].externFilename != "":
s.idxImports[foundLinks[0].externFilename].title
else: foundLinks[0].externFilename.extractFilename
let linkText =
if foundLinks[0].externFilename != "":
if foundLinks[0].isTitle: newLeaf(addNodes(desc))
else: newLeaf(documentName & ": " & addNodes(desc))
else:
newRstNode(rnInner, desc.sons)
result.sons = @[linkText, foundLinks[0].target]
if kind == rnNimdocRef: result.tooltip = foundLinks[0].tooltip
if foundLinks.len > 1: # report ambiguous link
var targets = newSeq[string]()
for l in foundLinks:
var t = " "
if s.filenames.len > 1:
t.add getFilename(s.filenames, l.info.fileIndex)
let n = l.info.line
let c = l.info.col + ColRstOffset
t.add "($1, $2): $3" % [$n, $c, l.tooltip]
targets.add t
rstMessage(s.filenames, s.msgHandler, n.info, mwAmbiguousLink,
"`$1`\n clash:\n$2" % [
aliasStr, targets.join("\n")])
else: # nothing found
result = n
rstMessage(s.filenames, s.msgHandler, n.info, mwBrokenLink, aliasStr)
if foundLinks[0].isTitle: newLeaf(addNodes(desc))
else: newLeaf(documentName & ": " & addNodes(desc))
else:
newRstNode(rnInner, desc.sons)
result.sons = @[linkText, foundLinks[0].target]
if kind == rnNimdocRef: result.tooltip = foundLinks[0].tooltip
if foundLinks.len > 1: # report ambiguous link
var targets = newSeq[string]()
for l in foundLinks:
var t = " "
if s.filenames.len > 1:
t.add getFilename(s.filenames, l.info.fileIndex)
let n = l.info.line
let c = l.info.col + ColRstOffset
t.add "($1, $2): $3" % [$n, $c, l.tooltip]
targets.add t
rstMessage(s.filenames, s.msgHandler, n.info, mwAmbiguousLink,
"`$1`\n clash:\n$2" % [
aliasStr, targets.join("\n")])
else: # nothing found
result = n
rstMessage(s.filenames, s.msgHandler, n.info, mwBrokenLink, aliasStr)

proc resolveSubs*(s: PRstSharedState, n: PRstNode): PRstNode =
## Makes pass 2 of RST parsing.
Expand Down

0 comments on commit 9659da9

Please sign in to comment.