Changed name of rawhtml

This commit is contained in:
Linus Björnstam 2026-04-01 08:52:00 +02:00
parent 27a169b30c
commit 6e26f37759

View file

@ -12,7 +12,7 @@ open System.Collections.Generic
module Ast =
type InlineNode =
| Text of string
| RawHtml of string
| RawText of string
| Expr of code: string * result: string option
| Element of tag: string * args: (string * string) list * children: InlineNode list
@ -29,7 +29,7 @@ module Ast =
nodes
|> List.map (function
| Text t -> t
| RawHtml h -> h
| RawText h -> h
| Element(tag, args, children) ->
// Omvandla inre taggar till HTML
let attrs = if args.IsEmpty then "" else " " + String.concat " " (List.map tupleToString args)
@ -248,7 +248,7 @@ module Execution =
prelude.[n] metadata a (c |> List.map (transform metadata prelude eval))
| Element(n, a, c) ->
Element(n, a, c |> List.map (transform metadata prelude eval))
| Expr(c, _) -> RawHtml (eval.Evaluate c)
| Expr(c, _) -> RawText (eval.Evaluate c)
| n -> n
module HtmlPrinter =
@ -261,7 +261,7 @@ module HtmlPrinter =
let rec renderInline =
function
| Text t -> WebUtility.HtmlEncode t
| RawHtml h -> h
| RawText h -> h
| Element(t,a,c) when List.contains t voidElements -> sprintf "<%s %s />" t (renderAttributes a)
| Element(t, a, c) -> sprintf "<%s %s>%s</%s>" t (renderAttributes a) (c |> List.map renderInline |> String.concat "") t
| _ -> ""
@ -269,18 +269,18 @@ module HtmlPrinter =
let render (header, blocks) =
blocks
|> List.map (function
| Paragraph [RawHtml html] ->
| Paragraph [RawText html] ->
html
// 2. (Frivillig) Mer robust guard om parsern råkar lämna kvar
// blanksteg (Text " ") runt ditt @md-block i samma paragraf
| Paragraph nodes when nodes |> List.forall (function
| RawHtml _ -> true
| RawText _ -> true
| Text t when System.String.IsNullOrWhiteSpace(t) -> true
| _ -> false) ->
nodes
|> List.choose (function RawHtml h -> Some h | _ -> None)
|> List.choose (function RawText h -> Some h | _ -> None)
|> String.concat "\n"
| Paragraph c -> sprintf "<p>%s</p>" (c |> List.map renderInline |> String.concat "")
| Section(l, _, c) -> sprintf "<h%d>%s</h%d>" l (c |> List.map renderInline |> String.concat "") l)