diff options
-rw-r--r-- | lib/packages/docutils/rstgen.nim | 10 | ||||
-rw-r--r-- | lib/pure/uri.nim | 1 | ||||
-rw-r--r-- | nimdoc/testproject/expected/theindex.html | 8 |
3 files changed, 12 insertions, 7 deletions
diff --git a/lib/packages/docutils/rstgen.nim b/lib/packages/docutils/rstgen.nim index 51bb9c757..232da5c93 100644 --- a/lib/packages/docutils/rstgen.nim +++ b/lib/packages/docutils/rstgen.nim @@ -424,11 +424,15 @@ proc sortIndex(a: var openArray[IndexEntry]) = if h == 1: break proc escapeLink(s: string): string = + ## This proc is mostly copied from uri/encodeUrl except that + ## these chars are also left unencoded: '#', '/'. result = newStringOfCap(s.len + s.len shr 2) for c in items(s): case c - of 'a'..'z', '_', 'A'..'Z', '0'..'9', '.', '#', ',', '/': - result.add c + of 'a'..'z', 'A'..'Z', '0'..'9', '-', '.', '_', '~': # same as that in uri/encodeUrl + add(result, c) + of '#', '/': # example.com/foo/#bar (don't escape the '/' and '#' in such links) + add(result, c) else: add(result, "%") add(result, toHex(ord(c), 2)) @@ -444,7 +448,7 @@ proc generateSymbolIndex(symbols: seq[IndexEntry]): string = var j = i while j < symbols.len and keyword == symbols[j].keyword: let - url = symbols[j].link #.escapeLink + url = symbols[j].link.escapeLink text = if symbols[j].linkTitle.len > 0: symbols[j].linkTitle else: url desc = if symbols[j].linkDesc.len > 0: symbols[j].linkDesc else: "" if desc.len > 0: diff --git a/lib/pure/uri.nim b/lib/pure/uri.nim index dd8040928..d296017dd 100644 --- a/lib/pure/uri.nim +++ b/lib/pure/uri.nim @@ -60,6 +60,7 @@ proc encodeUrl*(s: string, usePlus=true): string = let fromSpace = if usePlus: "+" else: "%20" for c in s: case c + # https://tools.ietf.org/html/rfc3986#section-2.3 of 'a'..'z', 'A'..'Z', '0'..'9', '-', '.', '_', '~': add(result, c) of ' ': add(result, fromSpace) else: diff --git a/nimdoc/testproject/expected/theindex.html b/nimdoc/testproject/expected/theindex.html index fc5c0e1c5..106a3be1d 100644 --- a/nimdoc/testproject/expected/theindex.html +++ b/nimdoc/testproject/expected/theindex.html @@ -1227,9 +1227,9 @@ function main() { </ul></dd> <dt><a name="bar" href="#bar"><span>bar:</span></a></dt><dd><ul class="simple"> <li><a class="reference external" - data-doc-search-tag="testproject: bar[T](a, b: T): T" href="testproject.html#bar,T,T">testproject: bar[T](a, b: T): T</a></li> + data-doc-search-tag="testproject: bar[T](a, b: T): T" href="testproject.html#bar%2CT%2CT">testproject: bar[T](a, b: T): T</a></li> <li><a class="reference external" - data-doc-search-tag="testproject: bar(): untyped" href="testproject.html#bar.m,">testproject: bar(): untyped</a></li> + data-doc-search-tag="testproject: bar(): untyped" href="testproject.html#bar.m%2C">testproject: bar(): untyped</a></li> </ul></dd> <dt><a name="enumValueA" href="#enumValueA"><span>enumValueA:</span></a></dt><dd><ul class="simple"> <li><a class="reference external" @@ -1245,7 +1245,7 @@ function main() { </ul></dd> <dt><a name="foo" href="#foo"><span>foo:</span></a></dt><dd><ul class="simple"> <li><a class="reference external" - data-doc-search-tag="testproject: foo(a, b: SomeType)" href="testproject.html#foo.t,SomeType,SomeType">testproject: foo(a, b: SomeType)</a></li> + data-doc-search-tag="testproject: foo(a, b: SomeType)" href="testproject.html#foo.t%2CSomeType%2CSomeType">testproject: foo(a, b: SomeType)</a></li> </ul></dd> <dt><a name="SomeType" href="#SomeType"><span>SomeType:</span></a></dt><dd><ul class="simple"> <li><a class="reference external" @@ -1253,7 +1253,7 @@ function main() { </ul></dd> <dt><a name="someType" href="#someType"><span>someType:</span></a></dt><dd><ul class="simple"> <li><a class="reference external" - data-doc-search-tag="utils: someType(): SomeType" href="subdir/subdir_b/utils.html#someType,">utils: someType(): SomeType</a></li> + data-doc-search-tag="utils: someType(): SomeType" href="subdir/subdir_b/utils.html#someType%2C">utils: someType(): SomeType</a></li> </ul></dd> </dl> <div class="row"> |