Commit Graph

111 Commits

Author SHA1 Message Date
ringabout
4eaecfe59e fixes #25027; nim doc uses doc comment from private field for public field (#25239)
fixes #25027

(cherry picked from commit b8ce11dd9d)
2025-10-27 08:51:12 +01:00
Amjad Ben Hedhili
1b49765122 [Docs] Improve scrollbars (#24971)
Follow dark/light modes.

(cherry picked from commit 9d0c0b89f2)
2025-06-10 06:31:39 +02:00
Amjad Ben Hedhili
7d6695b51f Fix docs sidebar truncated (#24970)
* Regression after #24927

(cherry picked from commit f80a076588)
2025-06-03 07:35:02 +02:00
Amjad Ben Hedhili
39757d421e Remove horizontal scrolling on mobile (#24927)
(cherry picked from commit 8b82f5de38)
2025-05-06 16:04:37 +02:00
Jake Leahy
3c71429eca Doc search improvements (#24567)
- `/` is now a hotkey to jump to the search
- Search results now are in line with the page (previously on small
screens it would be off centre)
- Jumping to a search result inside the page or via TOC will now hide
the search results (previously the results got in the way)

Example site here: https://tranquil-scone-c159b6.netlify.app/main.html

(cherry picked from commit 86d6f71f5a)
2025-01-15 10:21:11 +01:00
Jake Leahy
6a5aa00701 Fix CSS for number-lines code blocks (#24081)
Adds a few fixes for when using code blocks with lines numbered

- Use CSS variables for the colours so that it works in dark mode
- Don't turn on normal table effects like hover and smaller font when
its a line number table
- With dochack.nim, don't add a clipboard copy button for the line
numbers at the side

[Example page showing the
changes](https://66dcde6e4a655efb70771d9a--dazzling-kitten-6c3419.netlify.app/)
2024-09-09 09:42:45 +02:00
Nils Lindemann
ce85b819ff Prevent font flashing in the docs (#23622)
... by moving the Google font includes near the top of the head. By
including them as early as possible, they are known, when the browser
starts rendering the body.

Test it by making the change manually in `doc/html/system.html` and then
press ctrl+f5 (reload without cache). This removes the font flashing.

Tested in Chrome and Firefox.
2024-05-27 11:00:25 +02:00
ringabout
be0b847213 closes #15176; adds a test case (#23248)
closes #15176
2024-01-22 22:32:10 +08:00
Jake Leahy
1855f67503 Make data-theme default to "auto" in HTML (#23222)
Makes docs default to using browser settings instead of light mode

This should fix #16515 since it doesn't require the browser to run the
JS to set the default

Also means that dark mode can be used without JS if the browser is
configured to default to dark mode
2024-01-19 21:04:30 +08:00
metagn
fc49c6e3ba fix spurious indent and newlines in rendering of nkRecList (#23121)
Rendering of `nkRecList` produces an indent and adds a new line at the
end. However for things like case object `of`/`else` branches or `when`
branches this is already done, so this produces 2 indents and an extra
new line. Instead, just add an indent in the place where the indent that
`nkRecList` produces is needed, for the rendering of the final node of
`nkObjectTy`. There doesn't seem to be a need to add the newline.

Before:

```nim
case x*: bool
of true:
    y*: int

of false:
  nil
```

After:

```nim
case x*: bool
of true:
  y*: int
of false:
  nil
```
2023-12-24 15:22:10 +01:00
Hamid Bluri
a26ccb3476 fix #22492 (#22511)
* fix #22492

* Update nimdoc.css

remove scroll-y

* Update nimdoc.out.css

* Update nimdoc.css

* make it sticky again

* Update nimdoc.out.css

* danm sticky, use fixed

* Update nimdoc.out.css

* fix margin

* Update nimdoc.out.css

* make search input react to any change (not just keyboard events) according to https://github.com/nim-lang/Nim/pull/22511#issuecomment-1685218787
2023-08-22 18:31:21 +02:00
Bung
d2b197bdcd Stick search result (#22394)
* nimdoc: stick search result inside browser viewport

* fix nimdoc.out.css

---------

Co-authored-by: Locria Cyber <74560659+locriacyber@users.noreply.github.com>
2023-08-06 19:07:36 +08:00
Jake Leahy
17915d93bf Fix non-toplevel fields in objects not getting rendered (#22266)
* Add example object into testproject

The proc is there to check the case of an identDef being inside an identDef (We do want to render those even if they are not exported)

* Add `inside` set to `TSrcGen` which allows us to see what context we are in

This is done instead of adding another inXyz bool parameter

We then use this to know if we are inside an object when rendering an nkIdentDefs (To know if we need to skip rendering it)

* Update test files
2023-07-16 19:46:18 +02:00
ringabout
8e0f336f6d fixes #21483; fixes nim doc skips documentation of annotated elements of objects (#21743)
* fixes #21483; skipPragmaExpr

* add a test case for #21483

* fixes HTML
2023-04-29 15:30:44 +02:00
Andrey Makarov
63b4b3c5b8 Fix nim doc crash with group referencing & include (#21600)
This fixes a regression introduced in #20990 . When a group referencing
is used and one of the overloaded symbols is in `include`d file, then
`nim doc` crashes. The fix is in distinguishing (the index of) module
and file where the symbol is defined, and using only module as the
key in hash table for group referencing.
2023-04-02 10:32:36 +02:00
ringabout
38f876dd48 fixes #19795; fixes #11852; fixes #19974; remove parsing pipeline, Nim now parses the whole module at one time (#21379)
* fixes #19795; remove parse pipeline

* isScript

* fixes nimscriptapi

* don't touch reorder

* check script

* fixes tests

* it seems implicit imports of system cause troubles

* access the first child of `nkStmtList`

* ignore comments

* minor messages

* perhaps increases hloLoopDetector

* the module is a stmtList, which changes the errors

* fixes nimdoc

* fixes tlinter

* fixes nim  secret tests

* fixes arc_misc

* fixes nim secret tests again

* safe; fixes one more test

* GlobalError is the root cause too

* fixes parsing errors

* put emit types to the cfsForwardTypes section

* fixes #11852; `{.push checks:off}` now works in procs

* disable navigator

* fixes nimdoc

* add tests for JS

* fixes nimsuggest
2023-02-22 20:34:20 +01:00
ringabout
ff8ab06720 fixes #19396; Nimdoc hide nonexported fields (#21305)
* suppresses non-exported fields of types and adds command-line option to re-enable this if desired

* corrected the doctest that produced a CI error

* an embarrassingly bad error in reasoning

* modified a nimdoc test to reflect updated behavior

* needed another change to bring utils.html doctest in sync with update

* add info

* fix nimdoc

* lint

* render postfix

* fixes a problem

* fixes nimdoc

* fix nimdoc

---------

Co-authored-by: johnperry-math <john.perry@usm.edu>
Co-authored-by: johnperry-math <devotus@yahoo.com>
2023-02-01 08:13:40 +01:00
Andrey Makarov
2620da9bf9 docgen: implement cross-document links (#20990)
* docgen: implement cross-document links

Fully implements https://github.com/nim-lang/RFCs/issues/125
Follow-up of: https://github.com/nim-lang/Nim/pull/18642 (for internal links)
and https://github.com/nim-lang/Nim/issues/20127.

Overview
--------

Explicit import-like directive is required, called `.. importdoc::`.
(the syntax is % RST, Markdown will use it for a while).

Then one can reference any symbols/headings/anchors, as if they
were in the local file (but they will be prefixed with a module name
or markup document in link text).
It's possible to reference anything from anywhere (any direction
in `.nim`/`.md`/`.rst` files).

See `doc/docgen.md` for full description.

Working is based on `.idx` files, hence one needs to generate
all `.idx` beforehand. A dedicated option `--index:only` is introduced
(and a separate stage for `--index:only` is added to `kochdocs.nim`).

Performance note
----------------

Full run for `./koch docs` now takes 185% of the time before this PR.
(After: 315 s, before: 170 s on my PC).
All the time seems to be spent on `--index:only` run, which takes
almost as much (85%) of normal doc run -- it seems that most time
is spent on file parsing, turning off HTML generation phase has not
helped much.
(One could avoid it by specifying list of files that can be referenced
and pre-processing only them. But it can become error-prone and I assume
that these linke will be **everywhere** in the repository anyway,
especially considering https://github.com/nim-lang/RFCs/issues/478.
So every `.nim`/`.md` file is processed for `.idx` first).

But that's all without significant part of repository converted to
cross-module auto links. To estimate impact I checked the time for
`doc`ing a few files (after all indexes have been generated), and
everywhere difference was **negligible**.
E.g. for `lib/std/private/osfiles.nim` that `importdoc`s large
`os.idx` and hence should have been a case with relatively large
performance impact, but:

* After: 0.59 s.
* Before: 0.59 s.

So Nim compiler works so slow that doc part basically does not matter :-)

Testing
-------

1) added `extlinks` test to `nimdoc/`
2) checked that `theindex.html` is still correct
2) fixed broken auto-links for modules that were derived from `os.nim`
   by adding appropriate ``importdoc``

Implementation note
-------------------

Parsing and formating of `.idx` entries is moved into a dedicated
`rstidx.nim` module from `rstgen.nim`.

`.idx` file format changed:

* fields are not escaped in most cases because we need original
  strings for referencing, not HTML ones
  (the exception is linkTitle for titles and headings).
  Escaping happens later -- on the stage of `rstgen` buildIndex, etc.
* all lines have fixed number of columns 6
* added discriminator tag as a first column,
  it always allows distinguish Nim/markup entries, titles/headings, etc.
  `rstgen` does not rely any more (in most cases) on ad-hoc logic
  to determine what type each entry is.
* there is now always a title entry added at the first line.
* add a line number as 6th column
* linkTitle (4th) column has a different format: before it was like
  `module: funcName()`, now it's `proc funcName()`.
  (This format is also propagated to `theindex.html` and search results,
  I kept it that way since I like it more though it's discussible.)
  This column is what used for Nim symbols resolution.
* also changed details on column format for headings and titles:
  "keyword" is original, "linkTitle" is HTML one

* fix paths on Windows + more clear code

* Update compiler/docgen.nim

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>

* Handle .md and .nim paths uniformly in findRefFile

* handle titles better + more comments

* don't allow markup overwrite index title for .nim files

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2023-01-04 15:19:01 -05:00
Bung
b2328b44ba make it printer friendly (#21218) 2023-01-04 15:10:44 -05:00
Jake Leahy
d88f46df38 Make async stacktraces less verbose (#21091)
* Name iterators something human readable

Remove intermediate async procs from stacktraces

Clean async traceback message from reraises message

* Remove unused import/variable

* Fix failing tests

Don't add {.stackTrace: off.} to anonymous procs (They already don't appear in stacktrace)

* Fix failing tests in pragma category

Now check that the nim is a routine type first so we don't run into any assertion defects

* Hide stack trace pragma in docs and update doc tests

User doesn't need to know if something won't appear so this more becomes verbose noise

If this is a bad idea we can always add a `when defined(nimdoc)` switch so we don't add {.stackTrace: off.} to the Future[T] returning proc for docs
2022-12-15 16:05:34 +01:00
Jake Leahy
cbeefc877c Docs expand using parameters (#21076)
* Trying to fix by changing renderer

* add renderExpandUsing flag

This flag makes the renderer expand parameters that use using statement to have their full type

* Update docs

* Make comment better explain why checking for nkSym

* Fix nil access when macro/template has parameter with no type

* Fix nil access when node is not semmed yet
2022-12-12 07:44:17 +01:00
Jake Leahy
753868f16c Fix #14476 (#20878)
* Use link from webpage. Closes #14476

* Update doc generation tests

* Update RST test
2022-11-21 14:59:06 -05:00
ringabout
7394587217 move google fonts to the last part (#20541)
* move google fonts to the last part

* fixes tests

* fix rst2html
2022-10-11 19:42:02 +02:00
ringabout
0c0b086d58 fixes #20524; add forbids pragmas to hideable lists (#20525)
* fixes #20524; add forbids pragmas to hideable lists

* fixes nimdoc
2022-10-09 12:13:45 -04:00
Andrey Makarov
cde6b2aab8 Implement Pandoc Markdown concise link extension (#20304)
* Implement Pandoc Markdown concise link extension

This implements https://github.com/nim-lang/Nim/issues/20127.
Besides reference to headings we also support doing references
to Nim symbols inside Nim modules.

Markdown:
```
Some heading
------------

Ref. [Some heading].
```

Nim:
```
proc someFunction*() ...

... ## Ref. [someFunction]
```

This is substitution for RST syntax like `` `target`_ ``.
All 3 syntax variants of extension from Pandoc Markdown are supported:
`[target]`, `[target][]`, `[description][target]`.

This PR also fixes clashes in existing files, particularly
conflicts with RST footnote feature, which does not work with
this PR (but there is a plan to adopt a popular [Markdown footnote
extension](https://pandoc.org/MANUAL.html#footnotes) to make footnotes work).

Also the PR fixes a bug that Markdown links did not work when `[...]`
section had a line break.

The implementation is straightforward since link resolution did not
change w.r.t. RST implementation, it's almost only about new syntax
addition. The only essential difference is a possibility to add a custom
link description: form `[description][target]` which does not have an
RST equivalent.

* fix nim 1.0 gotcha
2022-09-04 14:52:21 -04:00
Amjad Ben Hedhili
70a8e0d65c Docs auto dark mode (#20188)
* Implement auto dark mode

* Rename class

* Fix borders cutout

* Apply suggestions from code review

* Apply suggestions from code review

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
2022-08-21 16:56:12 -04:00
Lancer11211
efd5c571bf .forbids pragma: defining forbidden tags (#20050)
* .forbids pragma: defining illegal effects for proc types

This patch intends to define the opposite of the .tags pragma: a way to define effects which are not allowed in a proc.

* updated documentation and changelogs for the forbids pragma

* renamed notTagEffects to forbiddenEffects

* corrected issues of forbids pragma

the forbids pragma didn't handle simple restrictions properly and it also had issues with subtyping

* removed incorrect character from changelog

* added test to cover the interaction of methods and the forbids pragma

* covering the interaction of the tags and forbids pragmas

* updated manual about the forbids pragma

* removed useless statement

* corrected the subtyping of proc types using the forbids pragma

* updated manual for the forbids pragma

* updated documentations for forbids pragma

* updated nim docs

* updated docs with rsttester.nim

* regenerated documentation

* updated rst docs

* Update changelog.md

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>

* updated changelog

* corrected typo

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
2022-07-26 07:40:49 +02:00
Jake Leahy
c43a377057 Make imports/exports not be a dropdown in sidebar (#19907)
* Don't make a section be a dropdown if it has no child links

* - Cleaned up code

- Updated tests

* Document what the 'if' is checking
2022-07-16 17:41:18 -04:00
Jake Leahy
dd4cc266cd Fixes #19900 (#19906)
Fixed tocRoot placement
2022-06-19 07:36:33 +02:00
JJ
e7e8f437c4 Keep the doc sidebar on the screen while scrolling (#19851)
* [docgen] Group sidebar sections into <details> (open by default)

* [docgen] Consistent indentation in generated HTML

(this is a boon for working on docgen's html/css output)

* [docgen] Move Source/Edit buttons inside main div

This makes styling the documentation significantly easier.

* [docgen] Somewhat consistent CSS formatting

* [docgen] Keep the sidebar onscreen while scrolling

* [docgen] Tweak CSS for the sticky sidebar

* [docgen] search type=text ==> type=search

* [docgen] Update expected doc output

* [docgen] Fix Group by Type sidebar placement bug

* [docgen] Curse you, whitespace (fix tests)

* [docgen] Fix rst2html tests

Co-authored-by: sandytypical <43030857+xflywind@users.noreply.github.com>
2022-06-15 15:40:56 +02:00
flywind
ded8b0e541 rewrite docs JS in Nim (#19701)
* rewrite docs JS in Nim

* fixup

* fix nimdoc/rsttester
2022-04-09 17:50:57 +02:00
Andrey Makarov
19898e1225 Fix group reference (with capital letters (#19196)
in group name)
2021-12-20 15:10:15 -05:00
Andrey Makarov
040d23e799 implement RST & Markdown quote blocks (#19147)
* implement RST & Markdown quote blocks

* compile with nim 1.0

* Fix indentation
2021-11-23 13:02:03 +01:00
Andrey Makarov
7ba2659f73 docgen: implement doc link resolution in current module (#18642) 2021-10-28 19:20:52 +02:00
Abishek PY
d634587423 feat: copy to clipboard (#18963)
* feat: copy to clipboard

* fix: CI failure related issue

* fix: CI failure issue

* fix: copy to clipboard button bug

* feat: copy pragmadots value to clipboard
2021-10-22 12:10:32 +02:00
Andreas Rumpf
e0ef859130 strict effects (#18777)
* fixes #17369
* megatest is green for --cpu:arm64
* docgen output includes more tags/raises
* implemented 'effectsOf' 
* algorithm.nim: uses new effectsOf annotation
* closes #18376
* closes #17475
* closes #13905
* allow effectsOf: [a, b]
* added a test case
* parameters that are not ours cannot be declared as .effectsOf
* documentation
* manual: added the 'sort' example
* bootstrap with the new better options
2021-09-02 12:10:14 +02:00
Andrey Makarov
bbe05c1532 docgen: draw frame around active anchors (#18607) 2021-07-29 13:30:19 +02:00
Timothee Cour
8d2f6bba3a support same-line doc comments in routines (#18595)
* support same-line comments in routines
* remove assert as per review comment
2021-07-27 19:50:59 +02:00
Andrey Makarov
10da888c07 docgen: sort symbols (fix #17910) (#18560)
* docgen: sort symbols (fix #17910)

* add workaround + change naming

* switch to a dedicated sort comparator

* fix numbers with unequal string lengths

* dedicated `sortName` instead of `plainNameEsc`:

* more compact names for non-overloaded symbols
* more predictable Ascii sort (e.g. `<` instead of `&lt;`)
2021-07-25 23:01:19 +02:00
Timothee Cour
488e9c2991 nim doc now correctly renders deprecated pragmas for routines and types (#18515) 2021-07-19 12:42:45 +02:00
Andrey Makarov
590d457631 docgen: move to shared RST state (fix #16990) (#18256)
* docgen: move to shared RST state (fix #16990)

* Update lib/packages/docutils/rst.nim

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>

* Update lib/packages/docutils/rst.nim

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>

* Update lib/packages/docutils/rst.nim

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>

* Update compiler/docgen.nim

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

* Update compiler/docgen.nim

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

* Update compiler/docgen.nim

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

* Update lib/packages/docutils/rst.nim

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

* rename `cmdDoc2` to `cmdDoc`

* fix (P)RstSharedState convention

* new style of initialization

* misc suggestions

* 1 more rename

* fix a regression

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
2021-06-20 09:50:03 +02:00
drtheuns
51ab7ccec1 Fix JS error on index page and detect dark mode (#18191)
* Fix JS error on index page and detect dark mode

The theindex.html page doesn't have a dark mode switch so the main
function will error because `toggleSwitch` is not defined. Checks have
been added to prevent this from happening.

Also add automatic detection of system settings for dark-mode. This
could also be done with pure css, but then the dark mode variable
declarations would have to be duplicated to work with the switch so I
went with this approach.

* Fix nimdoc tests

* Fix rst2html tests
2021-06-07 18:40:09 +02:00
Timothee Cour
0de3d4292f fix #16993, #18054, #17835 runnableExamples now works with templates and nested templates (#18082) 2021-06-02 09:02:14 -07:00
Timothee Cour
e2ab08603d fix warnings/hints in nimdoc/tester.nim (#18083)
* fix warnings/hints in nimdoc/tester.nim

* improve err msg for nimdoc/tester.nim and change flag from fixup to nimTestsNimdocFixup

* address comment: put back quit instead of doAssert
2021-05-30 22:40:42 +02:00
Andrey Makarov
97970d9dcc doc2tex: generate docs to Latex (#17997)
* `doc2tex`: generate docs to Latex

* address some comments
2021-05-14 07:30:47 +02:00
Andrey Makarov
436af88d8c follow-up #17837: add Console for interactive sessions (#17930)
* follow-up #17837: add `Console` for interactive sessions

* fix Latex
2021-05-06 10:58:01 +02:00
Timothee Cour
78e2d299df typo: nonexistant => nonexistent (#17918)
* typo: nonexistant => nonexistent

* fix test (ordering differs because of https://github.com/nim-lang/Nim/issues/17910)
2021-05-02 00:26:41 +02:00
Timothee Cour
a424075b5e improve nimsuggest/tester, minor improvements to koch.nim (#17879)
* improve nimsuggest/tester

* koch improvements
2021-04-29 13:44:53 +02:00
Andrey Makarov
8f79bc5f3d add RST highlighting for command line / shells (also fixes #16858) (#17789) 2021-04-21 16:57:54 +02:00
Andrey Makarov
2150cd1826 restyle RST option lists (#17637)
* WIP: restyle RST option lists

* apply similar style to Latex

* fix tests

* minor visual tweaks

* update tests

* remove leftover comments
2021-04-10 09:49:01 +02:00