Skip to content

Commit

Permalink
Add as HTML attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
yawaramin committed Dec 28, 2024
1 parent c911427 commit dcedb71
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
11 changes: 6 additions & 5 deletions pure-html/pure_html.ml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ module Indent_level = struct
let next (t : t) = Option.map succ t

(* The following functions return string that should be inserted before or
after the open or closing tag with indent level t. Some of them also need to
know if the next tag is going to be indented one more level. *)
after the open or closing tag with indent level t. Some of them also need to
know if the next tag is going to be indented one more level. *)

let open_prefix (t : t) =
match t with
Expand Down Expand Up @@ -95,9 +95,9 @@ let should_indent_next children =
| children -> not (List.exists is_txt children)

(* Loosely based on https://www.w3.org/TR/DOM-Parsing/. Pretty prints using two
spaces for indentation. On high level, the algorithm indents the children of a
tag if they do not contain a txt node. No newline is inserted if there are no
children nodes. *)
spaces for indentation. On high level, the algorithm indents the children of a
tag if they do not contain a txt node. No newline is inserted if there are no
children nodes. *)
let rec write_tag ~indent_level ~xml p node =
if not (is_null node) then p (Indent_level.open_prefix indent_level);
(match node with
Expand Down Expand Up @@ -263,6 +263,7 @@ module HTML = struct
let align fmt = string_attr "align" fmt
let allow fmt = string_attr "allow" fmt
let alt fmt = string_attr "alt" fmt
let as_ fmt = string_attr "as" fmt
let async = attr "async"

let autocapitalize value =
Expand Down
4 changes: 4 additions & 0 deletions pure-html/pure_html.mli
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ module HTML : sig

val allow : _ string_attr
val alt : _ string_attr

val as_ : _ string_attr
(** @since 3.9.2 *)

val async : attr

val autocapitalize :
Expand Down
5 changes: 4 additions & 1 deletion test/pure-html/html_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ let%expect_test "HTML" =
let open HTML in
html
[lang "en"]
[ head [] [title [] "Dream_html Test"];
[ head []
[ title [] "Dream_html Test";
link [rel "preload"; as_ "style"; href "/app.css"] ];
body
[id "test-content"]
[ main
Expand Down Expand Up @@ -65,6 +67,7 @@ let%expect_test "HTML" =
<html lang="en">
<head>
<title>Dream_html Test</title>
<link rel="preload" as="style" href="/app.css">
</head>
<body id="test-content">
<main spellcheck="true" colspan="1">
Expand Down

0 comments on commit dcedb71

Please sign in to comment.