Skip to content

Commit

Permalink
mbw/xml: Add setTextContent (#1484)
Browse files Browse the repository at this point in the history
This adds feature to change text content of XML tags to XML extension.
  • Loading branch information
Procybit authored May 23, 2024
1 parent 051b271 commit 5d4d4fd
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions extensions/mbw/xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@
},
},
},
{
opcode: "setTextContent",
blockType: Scratch.BlockType.REPORTER,
text: Scratch.translate("set text of [XML] to [VALUE]"),
arguments: {
XML: {
type: Scratch.ArgumentType.STRING,
defaultValue: "<hello>world</hello>",
},
VALUE: {
type: Scratch.ArgumentType.STRING,
defaultValue: "world!",
},
},
},
"---",
{
opcode: "attributes",
Expand Down Expand Up @@ -342,6 +357,20 @@
return xml.textContent;
}

/**
* @param {object} args
* @param {unknown} args.XML
* @param {unknown} args.VALUE
*/
setTextContent({ XML, VALUE }) {
const { xml } = this.stringToXml(Scratch.Cast.toString(XML));
if (xml === null) {
return "";
}
xml.textContent = VALUE;
return this.xmlToString(xml);
}

/**
* @param {object} args
* @param {unknown} args.XML
Expand Down

0 comments on commit 5d4d4fd

Please sign in to comment.