Skip to content

Commit

Permalink
feat: add std.parseXmlJsonml
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitjangid committed Jun 27, 2023
1 parent 5a9d395 commit bc76b1b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
38 changes: 38 additions & 0 deletions doc/_stdlib_gen/stdlib-content.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,44 @@ local html = import 'html.libsonnet';
},
],
},
{
name: 'parseXmlJsonml',
params: ['str', 'preserveWhitespace=false'],
availableSince: 'upcoming',
description: [
html.p({}, |||
Parses a XML string to <a href="http://www.jsonml.org/">JsonML</a>-encoded value. The XML should only contain
one root node.
|||),
html.p({}, |||
By default, all the boundary whitespace would be trimmed. It could be preserved using <code>preserveWhitespace</code>
argument of the function.
|||),
],
examples: [
{
input: "std.parseXmlJsonml('<svg height=\"100\" width=\"100\"><circle cx=\"50\" cy=\"50\" fill=\"red\" r=\"40\" stroke=\"black\" stroke-width=\"3\"></circle></svg>')",
output: [
"svg",
{
"height": "100",
"width": "100"
},
[
"circle",
{
"cx": "50",
"cy": "50",
"fill": "red",
"r": "40",
"stroke": "black",
"stroke-width": "3"
}
]
],
},
],
},
{
name: 'encodeUTF8',
params: ['str'],
Expand Down
2 changes: 2 additions & 0 deletions stdlib/std.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -1785,4 +1785,6 @@ limitations under the License.
sha3(str):: go_only_function,

trim(str):: std.stripChars(str, ' \t\n\f\r\u0085\u00A0'),

parseXmlJsonml(str):: go_only_function,
}

0 comments on commit bc76b1b

Please sign in to comment.