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