Closed ZelphirKaltstahl closed 6 years ago
Does the example in the documentation work for you? (I double-checked and it still works, for me.)
toc
takes a list of x-expressions, for example what parse-markdown
returns. It just looks for 'h1
, 'h2
etc. elements and makes a 'div
x-expression with a simple table of contents.
#lang racket
(require markdown
markdown/toc)
(define src (string-join '("# 1" "## 1.1" "# 2" "## 2.1") "\n\n"))
(parse-markdown src)
;; =>
;; '((h1 ((id "1")) "1")
;; (h2 ((id "11")) "1.1")
;; (h1 ((id "2")) "2")
;; (h2 ((id "21")) "2.1"))
(toc (parse-markdown src))
;; =>
;; '(div
;; ((class "toc"))
;; (ol
;; (li (a ((href "#1")) "1") (ul (li (a ((href "#11")) "1.1"))))
;; (li (a ((href "#2")) "2") (ul (li (a ((href "#21")) "2.1"))))))
I got it. The mistake was in how I handled the markdown input with(parse-markdown ...)
. I was using (car ...)
on it, but that is only the first thing in the markdown file. I originally added that, because I thought I'd get a single xexpr
from parse-markdown
and saw in an output, that I got a list with one element (from an even simpler markdown file). To get the first xexpr
I then added the car
thingy.
Thanks for making things clear and helping!
The toc
functionality is great. If it had not been there, I might have implemented it myself in probably much more laborious way.
Glad to hear!
I installed the
markdown
library fromraco pkg install markdown
(2017-11-11).On the documentation page I see a procedure
toc
which shall give anxexpr
with an added table of contents.However, it does not seem to work for me. For the following two markdown examples …
Example 1:
Example 2:
… I only get back
div
(using(display ...)
to print on terminal before further using the value).Here is the code I use:
Where
path
is for example: