-
Notifications
You must be signed in to change notification settings - Fork 100
Remove tyxml from odoc_html_frontend #1072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,5 +1,90 @@ | ||||||||||||||||||||||||
module Html : sig | ||||||||||||||||||||||||
type t | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
val string_of_list : t list -> string | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
type attr | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
val a_class : string list -> attr | ||||||||||||||||||||||||
val code : a:attr list -> t list -> t | ||||||||||||||||||||||||
val span : a:attr list -> t list -> t | ||||||||||||||||||||||||
val div : a:attr list -> t list -> t | ||||||||||||||||||||||||
val txt : string -> t | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
module Unsafe : sig | ||||||||||||||||||||||||
val data : string -> t | ||||||||||||||||||||||||
end | ||||||||||||||||||||||||
end = struct | ||||||||||||||||||||||||
type t = | ||||||||||||||||||||||||
| Raw of string | ||||||||||||||||||||||||
| Txt of string | ||||||||||||||||||||||||
| Concat of t list | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
let add_escape_string buf s = | ||||||||||||||||||||||||
(* https://discuss.ocaml.org/t/html-encoding-of-string/4289/4 *) | ||||||||||||||||||||||||
let add = Buffer.add_string buf in | ||||||||||||||||||||||||
let len = String.length s in | ||||||||||||||||||||||||
let max_idx = len - 1 in | ||||||||||||||||||||||||
let flush start i = | ||||||||||||||||||||||||
if start < len then Buffer.add_substring buf s start (i - start) | ||||||||||||||||||||||||
in | ||||||||||||||||||||||||
let rec loop start i = | ||||||||||||||||||||||||
if i > max_idx | ||||||||||||||||||||||||
then flush start i | ||||||||||||||||||||||||
else begin | ||||||||||||||||||||||||
match String.get s i with | ||||||||||||||||||||||||
| '&' -> escape "&" start i | ||||||||||||||||||||||||
| '<' -> escape "<" start i | ||||||||||||||||||||||||
| '>' -> escape ">" start i | ||||||||||||||||||||||||
| '\'' -> escape "'" start i | ||||||||||||||||||||||||
| '"' -> escape """ start i | ||||||||||||||||||||||||
| '@' -> escape "@" start i | ||||||||||||||||||||||||
| _ -> loop start (i + 1) | ||||||||||||||||||||||||
end | ||||||||||||||||||||||||
and escape amperstr start i = | ||||||||||||||||||||||||
flush start i ; | ||||||||||||||||||||||||
add amperstr ; | ||||||||||||||||||||||||
let next = i + 1 in | ||||||||||||||||||||||||
loop next next | ||||||||||||||||||||||||
in | ||||||||||||||||||||||||
loop 0 0 | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
let to_string t = | ||||||||||||||||||||||||
let buf = Buffer.create 16 in | ||||||||||||||||||||||||
let rec go = function | ||||||||||||||||||||||||
| Raw s -> Buffer.add_string buf s | ||||||||||||||||||||||||
| Txt s -> add_escape_string buf s | ||||||||||||||||||||||||
| Concat xs -> List.iter go xs | ||||||||||||||||||||||||
in | ||||||||||||||||||||||||
go t ; | ||||||||||||||||||||||||
Buffer.contents buf | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
let string_of_list lst = to_string (Concat lst) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
type attr = t | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
let a_class lst = Concat [ Raw "class=\""; Txt (String.concat " " lst); Raw "\"" ] | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
let attrs = function | ||||||||||||||||||||||||
| [] -> Concat [] | ||||||||||||||||||||||||
| xs -> Concat (Raw " " :: xs) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
let block name ~a body = | ||||||||||||||||||||||||
let name = Raw name in | ||||||||||||||||||||||||
Concat [ Raw "<"; name; attrs a; Raw ">"; Concat body; Raw "</"; name; Raw ">" ] | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
let code = block "code" | ||||||||||||||||||||||||
let span = block "span" | ||||||||||||||||||||||||
let div = block "div" | ||||||||||||||||||||||||
let txt s = Txt s | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
module Unsafe = struct | ||||||||||||||||||||||||
let data s = Raw s | ||||||||||||||||||||||||
end | ||||||||||||||||||||||||
end | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
let of_strings ~kind ~prefix_name ~name ~rhs ~typedecl_params ~doc = | ||||||||||||||||||||||||
let open Tyxml.Html in | ||||||||||||||||||||||||
let open Html in | ||||||||||||||||||||||||
let kind = code ~a:[ a_class [ "entry-kind" ] ] [ txt kind ] | ||||||||||||||||||||||||
and typedecl_params = | ||||||||||||||||||||||||
match typedecl_params with | ||||||||||||||||||||||||
|
@@ -19,9 +104,10 @@ let of_strings ~kind ~prefix_name ~name ~rhs ~typedecl_params ~doc = | |||||||||||||||||||||||
] | ||||||||||||||||||||||||
and prefix_name = | ||||||||||||||||||||||||
match prefix_name with | ||||||||||||||||||||||||
| None -> [] | ||||||||||||||||||||||||
| Some "" -> [] | ||||||||||||||||||||||||
| Some prefix_name -> | ||||||||||||||||||||||||
[ span ~a:[ a_class [ "prefix-name" ] ] [ txt (prefix_name ^ ".") ] ] | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is indeed a bug here. But wouldn't it be better to remove the addition of
Suggested change
and modify There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it is better i agree. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On second thought, no its not better. I believe there a few place where we String.split the prefix name. This would behave very poorly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In sherlodoc or in odoc? Could you provide links to such places? That would maybe mean that the prefix name is turned into a string too early, and we should keep it as a list? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its in sherlodoc. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I went and checked more closely. We do indeed use String.split on the name, but we do not use the name functions provided by odoc.search, we call fullname which is a list, so it does not change anything to switch that around. We could even say that the bug was sherlodoc's fault, we could have given None instead of Some "". |
||||||||||||||||||||||||
| None -> [] | ||||||||||||||||||||||||
and name = | ||||||||||||||||||||||||
match name with | ||||||||||||||||||||||||
| Some name -> [ span ~a:[ a_class [ "entry-name" ] ] [ txt name ] ] | ||||||||||||||||||||||||
|
@@ -31,7 +117,7 @@ let of_strings ~kind ~prefix_name ~name ~rhs ~typedecl_params ~doc = | |||||||||||||||||||||||
| None -> [] | ||||||||||||||||||||||||
| Some rhs -> [ code ~a:[ a_class [ "entry-rhs" ] ] [ txt rhs ] ] | ||||||||||||||||||||||||
in | ||||||||||||||||||||||||
[ | ||||||||||||||||||||||||
Html.string_of_list [ | ||||||||||||||||||||||||
kind; | ||||||||||||||||||||||||
code | ||||||||||||||||||||||||
~a:[ a_class [ "entry-title" ] ] | ||||||||||||||||||||||||
|
@@ -40,26 +126,15 @@ let of_strings ~kind ~prefix_name ~name ~rhs ~typedecl_params ~doc = | |||||||||||||||||||||||
] | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
let kind_doc = "doc" | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
let kind_typedecl = "type" | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
let kind_module = "mod" | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
let kind_exception = "exn" | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
let kind_class_type = "class" | ||||||||||||||||||||||||
let kind_class = "class" | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
let kind_method = "meth" | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
let kind_extension_constructor = "cons" | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
let kind_module_type = "sig" | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
let kind_constructor = "cons" | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
let kind_field = "field" | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
let kind_value = "val" | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
let kind_extension = "ext" |
Uh oh!
There was an error while loading. Please reload this page.