diff --git a/Fibble.slnx b/Fibble.slnx deleted file mode 100644 index cbf8a5b..0000000 --- a/Fibble.slnx +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/src/Bif/Bif.fsproj b/src/Bif/Bif.fsproj index fb0e0a5..8d26c7e 100644 --- a/src/Bif/Bif.fsproj +++ b/src/Bif/Bif.fsproj @@ -7,9 +7,6 @@ - - - diff --git a/src/Bif/Program.fs b/src/Bif/Program.fs index 2191e84..4f6aa83 100644 --- a/src/Bif/Program.fs +++ b/src/Bif/Program.fs @@ -1,59 +1,84 @@ -open System.IO +open System.Net +open System.IO +open System.Runtime.CompilerServices +open FSharp.Compiler.Text open Fibble.FibLib -open Fibble.FibLib.Ast +open Fibble.FibLib.Ast // Ger oss tillgång till Element, Text, RawHtml etc. +open Fibble.FibLib.Pandoc open Fibble.FibLib.HtmlPrinter +open Fibble.FibLib.Utils open Fibble.FibLib.ConstructionHelpers +// ========================================== +// 1. Prelude (Dina egna taggar) +// ========================================== -let myPrelude: Map = - Map - [ "quotient", - fun _ args _ _ -> - match args with - | [ one; two ] -> Inline(Text(sprintf "%d" (int one / int two))) - | _ -> Inline(Text "[Fel: quotient kräver två argument]") - "bold", fun _ _ _ children -> Inline(Strong(children)) - "kursiv", fun _ _ _ children -> Inline(Emph(children)) - "image", image - "value", value - "link", link - "list", - fun _ _ _ c -> - System.Console.WriteLine(c) - Inline(RawHtml "hej") - "br", linebreak - "table", table - "md", fun _ _ _ _ -> Inline(Text "hej") ] +let myPrelude : Map = + Map [ + "quotient", fun _ args _ _ -> + match args with + | [one; two] -> + Text (sprintf "%d" (int one / int two)) + | _ -> + Text "[Fel: quotient kräver två argument]" + "bold", fun _ _ _ children -> + Strong(children) + "kursiv", fun _ _ _ children -> Emph(children) + "image", image + "value", value + "link", link + "list", fun _ _ _ c -> System.Console.WriteLine(c) + RawHtml "hej" + + // @br har varken argument eller barn, så vi returnerar bara rå HTML direkt + "br", linebreak + "table", fun _ _ _ children -> Text "hej" + "md", fun _ _ _ children -> RawHtml (mdToHtml (stringifyNodes children)) + ] +// ========================================== +// 2. Mall och Evaluator +// ========================================== +// module File = let readFile path = match Path.Exists(path) with - | true -> File.ReadAllText(path) - | _ -> failwith $"{Path.GetFullPath path} does not exist" + | true -> File.ReadAllText(path) + | _ -> failwith $"{Path.GetFullPath path} does not exist" let pageTemplate = File.readFile "_page-template" let sourceCode = File.readFile "document.fib" - - +// ========================================== +// 3. Huvudpipeline +// ========================================== let processDocument (source: string) = - let evaluator = Evaluators.NullEvaluator() + let evaluator = Evaluators.FsiEvaluator() + + // Steg 1: Parsa koden + let metadata, rawBlocks = Parser.parse source + - // Parsa koden - let metadata, raewBlocks = Parser.parse source - let rawBlocks = AstUtils.slurpSections raewBlocks + // Steg 2: Transformera och exekvera trädet + let evaluatedBlocks = + rawBlocks |> List.map (function + | Paragraph children -> + Paragraph (children + |> List.map (Execution.transform metadata myPrelude evaluator)) + | Section(l, a, children) -> + Section(l, a, children + |> List.map (Execution.transform metadata myPrelude evaluator)) + | _ -> failwith "haha" + + ) - - let evaluatedBlocks = - CommandEvaluator.evaluateDocument metadata myPrelude evaluator rawBlocks - - // Be printern skriva ut trädet till HTML - let bodyHtml = HtmlWriter.renderDocument evaluatedBlocks + // Steg 3: Be printern skriva ut trädet till HTML + let bodyHtml = HtmlPrinter.render evaluatedBlocks // Steg 4: Fyll i din HTML-mall let mutable finalHtml = pageTemplate.Replace("{{body}}", bodyHtml) - + finalHtml // Kör programmet diff --git a/src/Bif/_page-template b/src/Bif/_page-template deleted file mode 100644 index 121840b..0000000 --- a/src/Bif/_page-template +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - {{title}} - - - - - - Home - Up - About and Credits - - - -× - - - -{{title}} - - by {{author}} - {{date}} - - - -{{body}} - - - - - - - -