Module Djot.Attr

type t = (string * string) list

Key/value pairs in source order. "id" holds the identifier; "class" holds every class, space-separated.

val empty : t
val find : string -> t -> string option
val id : t -> string option
val classes : t -> string list
val kvs : t -> (string * string) list

The entries other than "id" and "class".

val is_key : string -> bool

Whether a string can be a key: one or more of a-z, A-Z, 0-9, -, _, :.

val is_class : string -> bool

Whether a string can be one class name: one or more of a-z, A-Z, 0-9, -, _, :.

val is_valid : t -> bool

Whether every key satisfies is_key and none repeats.

Lenient about invalid class names, is_class is not guaranteed

Holds for parsed attributes and the results of set and add_class.

val is_valid_strict : t -> bool

is_valid and every class satisfies is_class.

val set : string -> string -> t -> t option

None if k is not a valid key.

Position: the value is replaced in place if k is already present, otherwise added at the end.

val set_id : string -> t -> t
val add_class : string -> t -> t option

None if not a valid class.

val remove : string -> t -> t
val set_classes : string list -> t -> t option

None if not a valid class.

val set_exn : string -> string -> t -> t
val add_class_exn : string -> t -> t
val set_classes_exn : string list -> t -> t
val to_string : t -> string

The attributes in djot syntax, {#id .class key="value"}; "" for empty.

val of_string : string -> t option

Parses djot attribute syntax, {...}, None if not a valid attribute syntax.