module Jekyll_tags: sig
.. end
Parse Jekyll-format delimited tags from message bodies
General tag parsing
: ?start:int ->
start_tag:string -> stop_tag:string -> string -> (int * string * int) option
extract_tag ?start ~start_tag ~stop_tag s
will extract the indices that
represents the text
in "<start><ws><text><ws><stop>"
. Whitespace
is trimmed, and None
is returned if non-empty text could not
be parsed.
Returns starting index of the tag within the string, the tag contents
with whitespace trimmed, and the index of the first character after
the end tag (which may be out of bounds of the string)
: ?start:int ->
start_tag:string -> stop_tag:string -> string -> (int * string * int) list
extract_tags ?start ~start_tag ~stop_tag s
will extract the list of
indices that represent the text
in "<start_Tag><ws><text><ws><stop_tag>"
.
Whitespace is trimmed from the text
body.
Returns list of tuples of the starting index of the tag within the string,
the tag contents with whitespace trimmed, and the index of the first character after
the end tag (which may be out of bounds of the string)
val map_tag : sub:Astring.String.sub ->
int * string * int -> Astring.String.sub -> Astring.String.sub
map_tag ~sub tag_info body
will substitute the tag_info (typically
returned by
Jekyll_tags.extract_tag
with the value of
sub
val map_tags : start_tag:string ->
stop_tag:string ->
f:(string -> string option) -> Astring.String.sub -> Astring.String.sub
map_tags ~start_tag ~stop_tag ~f body
will apply the function
f
to all the tags found that match
start_tag
and
stop_tag
. The scanning
is done via
Jekyll_tags.extract_tags
and covers all occurrences in
body
.
f
should return
None
if the tag is to be skipped, and
Some sub
where
sub
is the string to substitute into the tag body.
val map_tag_bodies : start_tag:string ->
stop_tag:string ->
f_start:(string -> 'a option) ->
f_stop:(string -> bool) ->
f_map:('a option -> Astring.String.sub -> Astring.String.sub) ->
Astring.String.sub -> Astring.String.sub
map_tag_bodies ~start_tag ~stop_tag ~f_start ~f_stop ~f_map body
searches
for tags delimited by start_tag
and stop_tag
. The tags are pattern
matched using f_start
to find the starting tag, and f_stop
for the
end tag. When a matching tag pair is found, a substitution is generated
using f_map
, and the resulting substitution is returned with the rest
of the string unchanged. f_start
can pass Some args
(parsed from the
start tag body to the f_map
function so that tag arguments can be
handled by the processor.
Jekyll liquid tag parsing functions
: ?start:int -> string -> (int * string * int) option
extract_liquid_tag
behaves as
Jekyll_tags.extract_tag
but is specialised
to parse Jekyll liquid tags of the form
{% ... %}
.
: ?start:int -> string -> (int * string * int) list
extract_liquid_tags
behaves as
Jekyll_tags.extract_tags
but is specialised
to parse Jekyll liquid tags of the form
{% ... %}
.
val map_liquid_tags : f:(string -> string option) -> Astring.String.sub -> Astring.String.sub
map_liquid_tags ~f body
behaves as
Jekyll_tags.map_tags
but is specialised
to parse Jekyll liquid tags of the form
{% ... %}
.
val map_liquid_tag_bodies : f_start:(string -> 'a option) ->
f_stop:(string -> bool) ->
f_map:('a option -> Astring.String.sub -> Astring.String.sub) ->
Astring.String.sub -> Astring.String.sub
map_liquid_tag_bodies
operates as
Jekyll_tags.map_tag_bodies
but is specialised
to parse Jekyll liquid tags of the form
{% ... %}
.