Skip to content

Instantly share code, notes, and snippets.

@gosoccerboy5
Last active June 6, 2021 15:28
Show Gist options
  • Save gosoccerboy5/795755a753472371f816f426917044aa to your computer and use it in GitHub Desktop.
Save gosoccerboy5/795755a753472371f816f426917044aa to your computer and use it in GitHub Desktop.
Minify XML generated by Blockly.
(function minifyXML(source) {
source.value = source.value.replaceAll(/\n */g, "");
source.select();
})(document.querySelector("#content_xml"));
/*
Blockly {
https://scratch.mit.edu/discuss/topic/491165/
}
Context {
https://scratch.mit.edu/discuss/post/4990156/
}
To test {
Navigate to <https://blockly-demo.appspot.com/static/demos/code/index.html>,
view the "XML" tab,
then paste the code
}
*/
javascript:(function minifyXML(source){source.value=source.value.replaceAll(/\n */g,"");source.select()})(document.querySelector("#content_xml"));
<style>
textarea {
width: 500px;
height: 200px;
}
</style>
<textarea id="content_xml"><xml xmlns="https://developers.google.com/blockly/xml">
<block type="text_print" id="kKf,GaluJo~ApYPxGGjn" x="113" y="163">
<value name="TEXT">
<shadow type="text" id="hL19Vek;njuYt?P7..P`">
<field name="TEXT">abc</field>
</shadow>
<block type="text" id="5xy/0L@a]QqKt]ETW@{6">
<field name="TEXT">Hello, world!</field>
</block>
</value>
</block>
</xml>
</textarea>
<br>
<button id="minify">Minify</button>
import 'dart:html';
void minifyXML(TextAreaElement source) {
source.value = source.value?.replaceAll(RegExp("\n *"), "");
source.select();
}
void main() {
(querySelector("#minify") as ButtonElement).addEventListener("click", (_) {
minifyXML(querySelector("#content_xml") as TextAreaElement);
});
}
@gosoccerboy5
Copy link
Author

gosoccerboy5 commented Jun 1, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment