This is a HTML extracted using javascript.May I ask how to remove all the spaces between > and < which are disconnected for each line. I would want to combine them as a string as shown below:
This is the expected output :
Current Problem:
let svg_object_alt=document.querySelector('svg').outerHTML;
console.log(svg_object_alt)
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="800pt" height="600pt" viewBox="0 0 800 600">
<path transform="matrix(1,0,0,-1,0,600)" stroke-width=".074" stroke-linecap="round" stroke-linejoin="round" fill="none" stroke="#929292" d="M489.52 144.07 488.76 142.24" />
<path transform="matrix(1,0,0,-1,0,600)" d="M475.72 281.52 475.65 281.29H476.04L475.72 281.52Z" fill="#ff0000" />
<path transform="matrix(1,0,0,-1,0,600)" d="M478.28 281.15 478.34 280.88 478.28 281.43V281.15Z" fill="#ff0000" fill-rule="evenodd " />
</svg>
2
Answers
As a few have mentioned it may be beneficial to understand why you’re trying to achieve this.
Just for some context. Certain bundlers will minify the code for you once you bundle the code.
In case you’re not using a bundler like Webpack – you can do a simple find and replace which will achieve what you’re trying to do.
There are some minifiers online that will do this.
IF you’re not looking to minify the code or are not using a bundler there are other solutions.
If you’re using VS Code – the built-in find and replace accepts regular expressions.
For example – if you’re using VS code or another code editor that allows regex you can insert in the Find field "n" and in the replace with field simply leave it empty.
This will remove all line breaks. Which seems like what you’re trying to do.
Let me know if this helps.