diff --git a/Fibble.slnx b/Fibble.slnx new file mode 100644 index 0000000..cbf8a5b --- /dev/null +++ b/Fibble.slnx @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/Bif/Bif.fsproj b/src/Bif/Bif.fsproj index 8d26c7e..fb0e0a5 100644 --- a/src/Bif/Bif.fsproj +++ b/src/Bif/Bif.fsproj @@ -7,6 +7,9 @@ + + + diff --git a/src/Bif/Program.fs b/src/Bif/Program.fs index 4f6aa83..2191e84 100644 --- a/src/Bif/Program.fs +++ b/src/Bif/Program.fs @@ -1,84 +1,59 @@ -open System.Net -open System.IO -open System.Runtime.CompilerServices -open FSharp.Compiler.Text +open System.IO open Fibble.FibLib -open Fibble.FibLib.Ast // Ger oss tillgång till Element, Text, RawHtml etc. -open Fibble.FibLib.Pandoc +open Fibble.FibLib.Ast 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 -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)) - ] + "md", fun _ _ _ _ -> Inline(Text "hej") ] -// ========================================== -// 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.FsiEvaluator() - - // Steg 1: Parsa koden - let metadata, rawBlocks = Parser.parse source - + let evaluator = Evaluators.NullEvaluator() - // 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" - - ) + // Parsa koden + let metadata, raewBlocks = Parser.parse source + let rawBlocks = AstUtils.slurpSections raewBlocks - // Steg 3: Be printern skriva ut trädet till HTML - let bodyHtml = HtmlPrinter.render evaluatedBlocks + + let evaluatedBlocks = + CommandEvaluator.evaluateDocument metadata myPrelude evaluator rawBlocks + + // Be printern skriva ut trädet till HTML + let bodyHtml = HtmlWriter.renderDocument 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 new file mode 100644 index 0000000..121840b --- /dev/null +++ b/src/Bif/_page-template @@ -0,0 +1,53 @@ + + + + + + + + {{title}} + + + + + + Home + Up + About and Credits + + + +× + + + +{{title}} + + by {{author}} + {{date}} + + + +{{body}} + + + + + + + +