[go: up one dir, main page]

Skip to content

Automatically register namespaces when using custom elements

What does the merge request do?

Previous we required extension authors to pre-register their xml namespaces in order to use them in their inkex svg parsing. But this is cumbersom as it required the namespace registeration to happen once before the class is created and then once again after the svg has been created.

We tidy up our registerNS so it handles the etree registration.

Then we allow custom elements to register thier custom namespaces on initalisation.

Finally we make sure our namepspaces are registered with the svg when elements are added to the document allowing namespace prefixes can be renamed if they are in the ns%f format lxml will create sometimes.

Implementation notes

  • New functions in inkex.elements._utils for renaming a namespace prefix
  • Functions in BaseElement to add namespaces to documents and register them when they are being added for the first time.
  • Split out the SvgElement.clean_namespaces from add_namespaces so it can be used by other processes, maybe when writing out to remove tree ns definitions.
  • Better control in SvgElement.add_namespace to be able to clean out an ns%d prefix and rename it.

Summary for release notes

...

Checklist

  • Add unit tests (if applicable)
  • Changes to inkex/ are well documented
  • Clean merge request history
Edited by Martin Owens

Merge request reports

Loading