This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdoc2markdown.pq
38 lines (38 loc) · 1.5 KB
/
doc2markdown.pq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
(functionName)=>
let
//New-Line
nl = "#(cr)#(lf)",
//Markdown code block
code = nl&"```"&nl,
//Fetching documentation from the metadata of the function type
function = Record.Field(#shared,functionName),
doc = Value.Metadata(Value.Type(function)),
//If the documentation doesn't contain Name field take it from Value.ResourceExpression
MDname = {"# "&functionName},
//Missing fields handling
MDdescription = try doc[Documentation.Description] otherwise "",
MDlongDescrpt = try Text.Trim(doc[Documentation.LongDescription]&nl) otherwise "",
MDcategory = try doc[Documentation.Category] otherwise "Accessing data",
//Examples block which can contain multiple code samples
MDexamples = try Lines.ToText(
List.Transform(doc[Documentation.Examples],
each _[Description]&code
&_[Code]&code
&"> "&_[Result]&nl)
, nl&"***"&nl)
otherwise "",
MDsignature = "> _"&Signature(function)&"_"&nl,
//Stitching the above into a Markdown template
template = MDname & (if doc = [] then {} else
{ MDdescription
, MDsignature
, "# Description "
, MDlongDescrpt
, "# Category "
, MDcategory
, if MDexamples="" then "" else "# Examples "
, MDexamples
}),
out = Lines.ToText(template, nl)
in
out