11module Fable.Helpers.ReactServer
22
3- open System
43open System.IO
54open System.Text .RegularExpressions
65
@@ -467,7 +466,7 @@ let inline objAttr (html:TextWriter) (key: string) (value: obj) = strAttr html k
467466let private renderHtmlAttr ( html : TextWriter ) ( attr : HTMLAttr ) =
468467 match attr with
469468 | DefaultChecked v | Checked v -> boolAttr html " checked" v
470- | DefaultValue v | Value v -> strAttr html " value" v
469+ | DefaultValue v | Value v -> strAttr html " value" ( string v )
471470 | Accept v -> strAttr html " accept" v
472471 | AcceptCharset v -> strAttr html " accept-charset" v
473472 | AccessKey v -> strAttr html " accesskey" v
@@ -700,7 +699,7 @@ let private renderAttrs (html:TextWriter) (attrs: IProp seq) tag =
700699 match tag, attr with
701700 | " textarea" , Value v
702701 | " textarea" , DefaultValue v ->
703- childHtml <- Some v
702+ childHtml <- Some( string v )
704703 | _, _ ->
705704 html.Write ' '
706705 renderHtmlAttr html attr
@@ -726,37 +725,39 @@ let inline private castHTMLNode (htmlNode: ReactElement): HTMLNode =
726725 else
727726 htmlNode :?> HTMLNode
728727
729- let rec writeTo ( html : TextWriter ) ( htmlNode : HTMLNode ) : unit =
730- match htmlNode with
731- | HTMLNode.Text str -> escapeHtml html str
732- | HTMLNode.RawText str -> html.Write str
733- | HTMLNode.Node ( tag, attrs, children) ->
734- html.Write '<'
735- html.Write tag
728+ module Raw =
729+ /// Writes the nodes into a TextWriter. DOESN'T ADD ` reactroot ` attribute.
730+ let rec writeTo ( html : TextWriter ) ( htmlNode : HTMLNode ) : unit =
731+ match htmlNode with
732+ | HTMLNode.Text str -> escapeHtml html str
733+ | HTMLNode.RawText str -> html.Write str
734+ | HTMLNode.Node ( tag, attrs, children) ->
735+ html.Write '<'
736+ html.Write tag
736737
737- let child = renderAttrs html attrs tag
738+ let child = renderAttrs html attrs tag
738739
739- if voidTags.Contains tag then
740- html.Write " />"
741- else
742- html.Write '>'
740+ if voidTags.Contains tag then
741+ html.Write " />"
742+ else
743+ html.Write '>'
743744
744- match child with
745- | Some c -> html.Write c
746- | None ->
747- for child in children do
748- writeTo html ( castHTMLNode child)
745+ match child with
746+ | Some c -> html.Write c
747+ | None ->
748+ for child in children do
749+ writeTo html ( castHTMLNode child)
749750
750- html.Write " </"
751- html.Write tag
752- html.Write '>'
753- | HTMLNode.List nodes ->
754- for node in nodes do
755- writeTo html ( castHTMLNode node)
756- | HTMLNode.Empty -> ()
751+ html.Write " </"
752+ html.Write tag
753+ html.Write '>'
754+ | HTMLNode.List nodes ->
755+ for node in nodes do
756+ writeTo html ( castHTMLNode node)
757+ | HTMLNode.Empty -> ()
757758
758759let renderToString ( htmlNode : ReactElement ): string =
759760 let htmlNode = addReactMark ( castHTMLNode htmlNode)
760761 use html = new StringWriter()
761- htmlNode |> writeTo html
762+ htmlNode |> Raw. writeTo html
762763 html.ToString()
0 commit comments