NLdoc.Spec.Content (NLdoc.Spec v3.1.1)
View SourceThis module provides helper functions for interpreting the content of NLdoc Spec objects.
Summary
Functions
Returns true if the given text is discernible, i.e. consists anything else than whitespace or invisible characters.
If the given text is an NLdoc.Spec
object, this function will recursively check whether any of its children
contain discernible text.
Returns all the text elements in a series of NLdoc Spec objects, concatenated into a single series of texts.
Functions
@spec discernible_text?(NLdoc.Spec.object() | String.t() | nil) :: boolean()
Returns true if the given text is discernible, i.e. consists anything else than whitespace or invisible characters.
If the given text is an NLdoc.Spec
object, this function will recursively check whether any of its children
contain discernible text.
Examples
iex> alias NLdoc.Spec.{Content, Paragraph, Text}
iex> Content.discernible_text?(
...> %Paragraph{children: [
...> %Text{text: "This is"},
...> %Text{text: " "},
...> %Text{text: "an example."},
...> ]}
...> )
true
iex> Content.discernible_text?("")
false
iex> Content.discernible_text?(%Paragraph{children: [%Text{text: " "}]})
false
@spec text(NLdoc.Spec.object() | [NLdoc.Spec.object()]) :: [NLdoc.Spec.Text.t()]
Returns all the text elements in a series of NLdoc Spec objects, concatenated into a single series of texts.
Examples
iex> alias NLdoc.Spec.{Content, Paragraph, Text}
iex> Content.text(
...> %Paragraph{children: [
...> %Text{text: "This is"},
...> %Text{text: " "},
...> %Text{text: "an example."},
...> ]}
...> )
[%Text{text: "This is"}, %Text{text: " "}, %Text{text: "an example."}]
iex> Content.text([
...> %Paragraph{children: [
...> %Text{text: "This is"},
...> %Text{text: " "},
...> %Text{text: "an example."},
...> ]},
...> %Paragraph{children: [
...> %Text{text: "And this is"},
...> %Text{text: " "},
...> %Text{text: "another example."},
...> ]}
...> ])
[%Text{text: "This is"}, %Text{text: " "}, %Text{text: "an example."}, %Text{text: "And this is"}, %Text{text: " "}, %Text{text: "another example."}]
iex> Content.text(%Text{text: "Just a single text object."})
[%Text{text: "Just a single text object."}]