playing with the interface
This commit is contained in:
parent
14697b3dd9
commit
6b952bd6fd
4 changed files with 141 additions and 23 deletions
38
src/FibLib/Pandoc.fs
Normal file
38
src/FibLib/Pandoc.fs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
namespace Fibble.FibLib
|
||||
|
||||
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.Write 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()
|
||||
|
||||
if proc.ExitCode = 0 then
|
||||
htmlOutput.Trim()
|
||||
else
|
||||
sprintf "\n<pre>%s</pre> and <pre>%s</pre>" errorOutput markdownText
|
||||
|
||||
with ex ->
|
||||
// Fångar upp om Pandoc inte är installerat eller inte finns i PATH
|
||||
sprintf "\n<pre>%s</pre> and <pre>%s</pre>" ex.Message markdownText
|
||||
|
||||
let mdToHtml markdownText =
|
||||
toHtml "markdown" markdownText
|
||||
Loading…
Add table
Add a link
Reference in a new issue