fsprojects / FSharp.Formatting

F# tools for generating documentation (Markdown processor and F# code formatter)
https://fsprojects.github.io/FSharp.Formatting/
Other
462 stars 155 forks source link

Output markdown from variable #777

Closed dburriss closed 1 year ago

dburriss commented 1 year ago

I am trying to output the content of a variable as markdown. As an example:

let content = someFunctionThatReturnsYamlString()
let md = $"
```yaml
{content}
```"
(*** include-value: md ***)

Current

Then for documentation I can output styled yaml instead of a "string" as seen below. image

If this is not possible, I am more than happy to try to pick it up as a feature if maintainers think it is worth adding. Maybe something like this:

Desired (or similar)

let k8sOutput' = KubeCtlWriter.toYaml k8sConfig
(*** hide ***)
let md = $"
{k8sOutput'.content}
"
(*** include-markdown: md ***)

image

nhirschey commented 1 year ago

There is no yaml syntax highlighter (people have proposed adding support for things like highlight.js, but it isn't added yet).

Not sure if this is close to what you want, but here's some relatively simple options below. If this doesn't work, you could look more at the embedding output examples here, which show how to make a custom formatter.

image code:

(**
Some markdown text
*)

(***hide***)
let md = "
apiVersion: apps/v1
kind: Deployment
"
printfn "%s" md
(***include-output ***)

(***hide***)
let makeMd text = $"""
<pre class="fssnip highlighted">
    <code lang="fsharp">
    {text}
    </code>
</pre>
"""

makeMd md
(***include-it-raw***)

(**
Some more text

    [yaml]
    apiVersion: apps/v1
    kind: Deployment
*)

Or maybe this?

image

(***hide***)
let md = 
    ["apiVersion: apps/v1"
     "kind: Deployment"]

md 
|> List.map (fun line -> sprintf "<span>%s</span><br>" line)
|> String.concat ""
(***include-it-raw ***)
dburriss commented 1 year ago

Thanks @nhirschey I reckon this will get me what I want.