+28
src/xmleam/xml_builder.gleam
+28
src/xmleam/xml_builder.gleam
···
103
103
}
104
104
}
105
105
106
+
pub fn cdata_tag(document: XmlBuilder, label: String, contents: String) {
107
+
let label_empty = string.is_empty(label)
108
+
use <- bool.guard(when: label_empty, return: Error(LabelEmpty))
109
+
let contents_empty = string.is_empty(contents)
110
+
use <- bool.guard(when: contents_empty, return: Error(ContentsEmpty))
111
+
112
+
case result.is_error(document) {
113
+
True -> Error(result.unwrap_error(document, NOTAPPLICABLE))
114
+
115
+
False ->
116
+
string_builder.new()
117
+
|> append("<")
118
+
|> append(label)
119
+
|> append("> \n")
120
+
|> append("<![CDATA[\n \t")
121
+
|> append(contents)
122
+
|> append("\n]]> \n")
123
+
|> append("</")
124
+
|> append(label)
125
+
|> append("> \n")
126
+
|> append_builder(
127
+
to: result.unwrap(document, string_builder.new()),
128
+
suffix: _,
129
+
)
130
+
|> Ok
131
+
}
132
+
}
133
+
106
134
/// Tag with options and content
107
135
/// ie. <hello world="hi"> ?? <hello>
108
136
pub fn option_content_tag(