package server-reason-react

  1. Overview
  2. Docs
Rendering React components on the server natively

Install

Dune Dependency

Authors

Maintainers

Sources

server-reason-react-0.1.0.tbz
sha256=557e215377660a5c48c0494704d3d149ff249d4a5669f1749b393176b963ea05
sha512=cc3dd53dd21d2564ad031ca74552587f4a8200833ec80392fd190a55d7a7f83bec0fc57d2ec0e262c0c3ef2e78a89914872ea1588921c3cb8836e8e5f67b4cef

doc/src/server-reason-react.html/Html.ml.html

Source file Html.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
(* Based on https://github.com/facebook/react/blob/97d75c9c8bcddb0daed1ed062101c7f5e9b825f4/packages/react-dom-bindings/src/server/escapeTextForBrowser.js#L51-L98 *)
(* https://discuss.ocaml.org/t/html-encoding-of-string/4289/4 *)
let encode s =
  let buffer = Buffer.create (String.length s * 2) in
  s
  |> String.iter (function
       | '&' -> Buffer.add_string buffer "&"
       | '<' -> Buffer.add_string buffer "&lt;"
       | '>' -> Buffer.add_string buffer "&gt;"
       | '"' -> Buffer.add_string buffer "&quot;"
       | '\'' -> Buffer.add_string buffer "&#x27;"
       | c -> Buffer.add_char buffer c);
  Buffer.contents buffer

let is_self_closing_tag = function
  (* Take the list from
     https://github.com/facebook/react/blob/97d75c9c8bcddb0daed1ed062101c7f5e9b825f4/packages/react-dom-bindings/src/shared/omittedCloseTags.js but found https://github.com/wooorm/html-void-elements to be more complete. *)
  | "area" | "base" | "basefont" | "bgsound" | "br" | "col" | "command"
  | "embed" | "frame" | "hr" | "image" | "img" | "input" | "keygen"
  | "link" (* | "menuitem" *) | "meta" | "param" | "source" | "track" | "wbr" ->
      true
  | _ -> false
OCaml

Innovation. Community. Security.