jakearchibald / svgomg

Web GUI for SVGO

Home Page:https://jakearchibald.github.io/svgomg/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing <?xml - SVG files are XML files

szepeviktor opened this issue · comments

Please consider adding <?xml version="1.0" encoding="UTF-8" standalone="no"?> to downloaded files.
The standard says: https://www.w3.org/TR/SVG11/struct.html#NewDocument

SVG-s copied to the clipboard could remain the way they are as people tend to paste them into HTML source code.

Thank you!

@szepeviktor Have you tried to turn off the Remove XML instructions option?

image

@rikapo Thank you!
The downloaded .svg file still does not have the XML header added.

@szepeviktor Oh, I see. You need to add XML instruction to a svg that doesn't have it, right?
Unfortunately, this project is just GUI for SVGO and SVGO doesn't have any plugins about adding XML instruction.
I think you can open this issue at SVGO project if you want to.

SVGO is an Optimizer. xml instruction is not necessary to use .svg files in many environments. If you need to add somethinng use svgo package directly and write custom plugin like this

const addXmlInstructionPlugin = {
  type: 'visitor',
  name: 'add-xml-instruction',
  fn: () => {
    let hasXmlInstruction = false;
    return {
      instruction: {
        enter: node => {
          if (node.name === 'xml') {
            hasXmlInstruction = true;
          }
        }
     },
      root: {
        exit: node => {
          if (hasXmlInstruction === false) {
            node.children.push({
              type: 'instruction',
              name: 'xml',
              value: 'version="1.0" encoding="utf-8"',
            })
          }
        }
      }
    }
  }
}

Thank you.