Skip to content

Commit

Permalink
Fix #39: fix link when var is named multiple times in docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Jul 4, 2024
1 parent 5715af8 commit 7e41f33
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
34 changes: 34 additions & 0 deletions scratch/API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Table of contents
- [`user`](#user)
- [`+and`](#user/+and) - Logical AND of heavy-bools which evaluates to a <code>heavy-bool</code>.
- [`heavy-bool`](#user/heavy-bool)

-----
# <a name="user">user</a>






## <a name="user/+and">`+and`</a><a name="user/+and"></a>
``` clojure

(+and & rest)
```
Macro.

Logical AND of heavy-bools which evaluates to a [`heavy-bool`](#user/heavy-bool).
Expands to code which evaluates to the left-most [`heavy-bool`](#user/heavy-bool) value
in the argument list, otherwise evaluates to the right-most
value. If the argument list is empty, evaluates explicitly to
`+true`
<p><sub><a href="/blob/main/src/scratch.clj#L3-L18">Source</a></sub></p>

## <a name="user/heavy-bool">`heavy-bool`</a><a name="user/heavy-bool"></a>
``` clojure

(heavy-bool)
```
Function.
<p><sub><a href="/blob/main/src/scratch.clj#L1-L1">Source</a></sub></p>
1 change: 1 addition & 0 deletions scratch/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:deps {io.github.borkdude/quickdoc {:local/root ".."}}}
18 changes: 18 additions & 0 deletions scratch/src/scratch.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(defn heavy-bool [])

(defmacro +and
"Logical AND of heavy-bools which evaluates to a `heavy-bool`.
Expands to code which evaluates to the left-most `heavy-bool` value
in the argument list, otherwise evaluates to the right-most
value. If the argument list is empty, evaluates explicitly to
`+true`"
[& rest]
(case (count rest)
(0) true
(1) (first rest)
(let [v (gensym)
[head & tail] rest]
`(let [~v ~head]
(+if ~v
(+and ~@tail)
~v)))))
8 changes: 4 additions & 4 deletions src/quickdoc/impl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,22 @@
;; Looks qualified
(str/includes? inner "/")
(let [split (str/split inner #"/")]
(if (and (= (count split) 2)
(if (and (= 2 (count split))
(get-in ns->vars [(symbol (first split))
(symbol (second split))]))
(str/replace docstring raw (format "[`%s`](#%s)" inner inner))
docstring))
;; Not qualified, maybe a namespace
(contains? ns->vars (symbol inner))
(str/replace docstring raw (format "[`%s`](#%s)" inner inner))
;; Not qualified, maybe a var in the current namespace
;; Not qualified, maybe a var in the current namespace
(get-in ns->vars [current-ns (symbol inner)])
(str/replace docstring raw (format "[`%s`](#%s/%s)" inner current-ns inner))
;; Just regular markdown backticks
;; Just regular markdown backticks
:else
docstring))
docstring
(re-seq var-regex docstring))
(distinct (re-seq var-regex docstring)))
docstring)))

(defn print-var [ns->vars ns-name var _source {:keys [collapse-vars] :as opts}]
Expand Down

0 comments on commit 7e41f33

Please sign in to comment.