fennel-ls/tools/get-docs/tic80.fnl
2024-06-09 17:36:19 -05:00

35 lines
1.0 KiB
Fennel
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(local fennel (require :fennel))
(fn remove-html-escape-codes [x]
(-> x
(: :gsub " " " ")
(: :gsub "–" "")
(: :gsub "—" "—")
(: :gsub ">" ">")
(: :gsub "&lt;" "<")
(: :gsub "&amp;" "<")
(: :gsub "&pi;" "π")))
(fn markdown->arglist [markdown]
(case (markdown:match "%(([^%)]*)%)")
signature
(icollect [arg (signature:gmatch "%S+")]
(case (arg:match "(.*)=")
argname (.. "?" argname)
_ arg))))
(fn markdown->data [html]
(let [api-markdown (html:match "## API functions.-### (.*)## Button IDs")
api-markdown (remove-html-escape-codes api-markdown)]
(collect [(name args docs) (api-markdown:gmatch
"([_%w]+)%s+`([^`]+)`%s(.-)\n### ")]
(let [arglist (markdown->arglist args)]
(values name {:metadata {:fnl/arglist arglist
:fnl/docstring docs}
:binding name})))))
(fn convert [contents]
(fennel.view (markdown->data contents)))
{: convert}