How to eliminate aria-label, flowRoot and rdf from my SVGs

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to eliminate aria-label, flowRoot and rdf from my SVGs

Steve Litt
Hi all,

I've created a bookwriting format called Stylz, which can be turned
into an HTML doc or ePub by running a program.

I check the ePubs with a very strict program called epubcheck, and the
only errors it still finds are errors in my SVG images, even after I
saved the SVGs as plain-svg. Specifically, it complains about my <rdf>
elements, my <flowRoot> elements, and my aria-label attribute. Can I
just remove the two elements and delete the attribute, or do I need to
do something else to preserve the look of the image while getting rid
of these three?

Thanks,

SteveT

Steve Litt
April 2018 featured book: Troubleshooting Techniques
     of the Successful Technologist
http://www.troubleshooters.com/techniques

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Inkscape-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/inkscape-user
Reply | Threaded
Open this post in threaded view
|

Re: How to eliminate aria-label, flowRoot and rdf from my SVGs

Marc Jeanmougin
Hi,

You can delete the rdf thing, it's just metadata, and probably also the
aria attribute, but for the flowroot thing, you have to select your
(flowing) text elements in inkscape and convert them to real text (Text
-> Convert to text) or you may lose text.

--

Mc


On 04/30/2018 10:53 PM, Steve Litt wrote:

> Hi all,
>
> I've created a bookwriting format called Stylz, which can be turned
> into an HTML doc or ePub by running a program.
>
> I check the ePubs with a very strict program called epubcheck, and the
> only errors it still finds are errors in my SVG images, even after I
> saved the SVGs as plain-svg. Specifically, it complains about my <rdf>
> elements, my <flowRoot> elements, and my aria-label attribute. Can I
> just remove the two elements and delete the attribute, or do I need to
> do something else to preserve the look of the image while getting rid
> of these three?
>
> Thanks,
>
> SteveT
>
> Steve Litt
> April 2018 featured book: Troubleshooting Techniques
>       of the Successful Technologist
> http://www.troubleshooters.com/techniques
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Inkscape-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/inkscape-user


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Inkscape-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/inkscape-user
Reply | Threaded
Open this post in threaded view
|

Re: How to eliminate aria-label, flowRoot and rdf from my SVGs

Steve Litt
On Tue, 1 May 2018 00:28:27 +0200
Marc Jeanmougin <[hidden email]> wrote:

> Hi,
>
> You can delete the rdf thing, it's just metadata, and probably also
> the aria attribute, but for the flowroot thing, you have to select
> your (flowing) text elements in inkscape and convert them to real
> text (Text -> Convert to text) or you may lose text.  
 
Thanks Marc!

It turns out I was able to delete all three without effect I was able
to see on quick inspection.

Because I had several such Inkscape authored SVG files,  I created a
shellscript calling a Python3 program that automatically removes most
of the epubcheck error causers:

SHELLSCRIPT trim_svg.sh:
========================================================================
#!/bin/sh
fname=$1
bakname=$fname.bak
cp -p $fname $bakname
inkscape --vacuum-defs $fname
inkscape --export-plain-svg $fname.2 $fname
./trim_svg.py $fname.2
cp -p $fname.2a $fname
========================================================================

Python3 program trim_svg.py
========================================================================
#!/usr/bin/python3

import sys
import xml.etree.ElementTree as ET
import re

def main():
    # Handle filename and args
    if len(sys.argv) != 2:
        print("USAGE: trim_svg.py infname.")
        print("Aborting.")
        sys.exit(1)
    else:
        infname = sys.argv[1]
   
    # Parse the original file
    parser = ET.XMLParser()
    try:
        tree = ET.parse(infname, parser=parser)
    except Exception as exception:
        print("Parse failure, aborting!",  file=sys.stderr)
        print(exception, file=sys.stderr)
        exit(1)
    root = tree.getroot()

    # Delete the necessary
    to_delete=[]

    for parent in tree.getiterator():
        for child in parent:
            if re.search("RDF$",child.tag) or
    re.search("flowRoot$",child.tag):
                to_delete.append([parent, child])
            elif "aria-label" in child.attrib:
                del(child.attrib["aria-label"])
    for pair in to_delete:
        pair[0].remove(pair[1])

    tree.write(infname + "a",encoding="UTF-8",short_empty_elements=True)

if __name__ == "__main__":
    main()
========================================================================
 
The epubcheck program is a petty diva snowflake that gripes about the
slightest deviation not only in your ePub files, but also in the .svg
files it displays. Getting to zero errors, zero warnings is a pain in
the posterior, but guarantees that your ePub will be readable on any
reasonable device, and will look good on all reasonable devices. It's
overkill for a lot of people, but if you're ever in the position of
widely distributing ePub files, you might use it, and if so, this
shellscript and Python program get rid of the vast majority of
error-triggering Inkscape derived SVG features. Be sure to back up the
original SVGs in case my programs visibly damage them.

SteveT

Steve Litt
April 2018 featured book: Troubleshooting Techniques
     of the Successful Technologist
http://www.troubleshooters.com/techniques

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Inkscape-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/inkscape-user
Reply | Threaded
Open this post in threaded view
|

Re: How to eliminate aria-label, flowRoot and rdf from my SVGs

Chris Tooley
Hi Steve,

You might consider publishing that script on github or something similar (if you haven't already), it'll probably get lost in this mailing list.

I've lost count at the number of annoying things I've been able to fix because of some kind soul out there has published a script that either fixes my problems or gets me half way there. :)


On Tue, May 1, 2018 at 10:11 AM, Steve Litt <[hidden email]> wrote:
On Tue, 1 May 2018 00:28:27 +0200
Marc Jeanmougin <[hidden email]> wrote:

> Hi,
>
> You can delete the rdf thing, it's just metadata, and probably also
> the aria attribute, but for the flowroot thing, you have to select
> your (flowing) text elements in inkscape and convert them to real
> text (Text -> Convert to text) or you may lose text. 

Thanks Marc!

It turns out I was able to delete all three without effect I was able
to see on quick inspection.

Because I had several such Inkscape authored SVG files,  I created a
shellscript calling a Python3 program that automatically removes most
of the epubcheck error causers:

SHELLSCRIPT trim_svg.sh:
========================================================================
#!/bin/sh
fname=$1
bakname=$fname.bak
cp -p $fname $bakname
inkscape --vacuum-defs $fname
inkscape --export-plain-svg $fname.2 $fname
./trim_svg.py $fname.2
cp -p $fname.2a $fname
========================================================================

Python3 program trim_svg.py
========================================================================
#!/usr/bin/python3

import sys
import xml.etree.ElementTree as ET
import re

def main():
    # Handle filename and args
    if len(sys.argv) != 2:
        print("USAGE: trim_svg.py infname.")
        print("Aborting.")
        sys.exit(1)
    else:
        infname = sys.argv[1]

    # Parse the original file
    parser = ET.XMLParser()
    try:
        tree = ET.parse(infname, parser=parser)
    except Exception as exception:
        print("Parse failure, aborting!",  file=sys.stderr)
        print(exception, file=sys.stderr)
        exit(1)
    root = tree.getroot()

    # Delete the necessary
    to_delete=[]

    for parent in tree.getiterator():
        for child in parent:
            if re.search("RDF$",child.tag) or
    re.search("flowRoot$",child.tag):
                to_delete.append([parent, child])
            elif "aria-label" in child.attrib:
                del(child.attrib["aria-label"])
    for pair in to_delete:
        pair[0].remove(pair[1])

    tree.write(infname + "a",encoding="UTF-8",short_empty_elements=True)

if __name__ == "__main__":
    main()
========================================================================

The epubcheck program is a petty diva snowflake that gripes about the
slightest deviation not only in your ePub files, but also in the .svg
files it displays. Getting to zero errors, zero warnings is a pain in
the posterior, but guarantees that your ePub will be readable on any
reasonable device, and will look good on all reasonable devices. It's
overkill for a lot of people, but if you're ever in the position of
widely distributing ePub files, you might use it, and if so, this
shellscript and Python program get rid of the vast majority of
error-triggering Inkscape derived SVG features. Be sure to back up the
original SVGs in case my programs visibly damage them.

SteveT

Steve Litt
April 2018 featured book: Troubleshooting Techniques
     of the Successful Technologist
http://www.troubleshooters.com/techniques

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Inkscape-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/inkscape-user


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Inkscape-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/inkscape-user