namespace Fibble.FibLib open System open System.Xml.Schema module Pandoc = open System.Diagnostics let toHtml (from: string) (markdownText: string) = let startInfo = ProcessStartInfo( FileName = "pandoc", Arguments = $"-f {from} -t html5 --lua-filter strip-p.lua", RedirectStandardInput = true, RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, CreateNoWindow = true) try use proc = Process.Start startInfo // Skriv markdown till Pandoc use stdin = proc.StandardInput stdin.WriteLine markdownText stdin.Close() // Måste stängas så Pandoc vet att texten är slut // Läs ut resultatet let htmlOutput = proc.StandardOutput.ReadToEnd() let errorOutput = proc.StandardError.ReadToEnd() proc.WaitForExit() Console.WriteLine(htmlOutput) if proc.ExitCode = 0 then htmlOutput.Trim() else sprintf "\n
%sand
%s" errorOutput markdownText with ex -> // Fångar upp om Pandoc inte är installerat eller inte finns i PATH sprintf "\n
%sand
%s" ex.Message markdownText let mdToHtml markdownText = let res= toHtml "markdown" markdownText res