On Fri, 27 Feb 2015 15:18:46 +0200
Peter Brooks <peter.h.m.brooks@...155...> wrote:
Thank you very much for that pointer. Yes, I know they're text
files.
I've been editing them with awk, but it's a bit of a fiddle getting
the context right - you have to find the text, then work back to the
object that it's contained in. Not impossible, but it looks as if an
inkscape extension might be a more sensible solution since it knows
about the objects.
I don't think Inkscape extensions know about the objects, they just
know about the XML. But what you're trying to do is very easy with
XPath, an XML addressing scheme any worth while XML library should
provide. Aside - I think XML gets unfairly criticized for being heavy
and difficult - there are some far too heavy formats written in XML, but
that's not XML's fault. With a good library, XML's not that hard to
use.
This python code:
import sys
from lxml import etree
ns_xlink = "http://www.w3.org/1999/xlink"
dom = etree.parse(sys.stdin)
anchors = dom.xpath("//a[text]") # all 'a' elements with 'text'
children
for a in anchors:
h = a.get('{%s}href' % ns_xlink).split("?title=")
if len(h) > 1: # => ?title= in h
t = a.xpath('.//text/text()')[0]
a.set('{%s}href' % ns_xlink, ''.join([h[0], "?title=",
t]))
print(etree.tostring(dom, pretty_print=True))
can be invoked like this:
python txt2adr.py <test.xml >test2.xml
to perform the translation I think you want. It seems to work on the
attached test.xml.
Cheers -Terry
On 27 February 2015 at 14:18, Vasco <vasco+python@...3082...>
wrote:
> Dear Peter,
>
> SVG files are plain text files. You mention in your explanation
> that you only have to replace a certain string (one url with
> another one). This can be done with any editor, for example with sed
>
(
http://stackoverflow.com/questions/10309968/sed-search-and-replace-string...).
>
> If you have to do more logic, it is better to write an inkscape
> extension. This is just a script, that reads a svg file and outputs
> the converted svg file. I have good experiences writing extensions
> in python.
>
> A relevant resource is:
>
http://wiki.inkscape.org/wiki/index.php/PythonEffectTutorial
>
> Here the inkex class does all the reading/writing of the files. I
> wrote:
https://bitbucket.org/vascotenner/inkscape-fix_text_boxes
>
> Kind regards,
> Vasco
>
>
> On 26-02-15 06:31, Peter Brooks wrote:
>> I've been trying to do this for a while now, and I hoped that it'd
>> be possible with the inkscape command line, but I'm new to this,
>> so I can't see how.
>>
>> I've got a .svg file that's from the OpenGroup's Archi application.
>> It's got boxes and links with names.
>>
>> What I'd like to do is make the names clickable. So, for example,
>> the box:
>>
>>
>> ----------------------
>> | |
>> | my_label |
>> | |
>> ----------------------
>>
>> Would be clickable, as a box, and go to:
>>
>>
http://mywebsite.com/my_label
>>
>> This will work because I'm using a wiki, so the 'my_label' will
>> become a page on the wiki.
>>
>> Is there a way to get inkscape to add the link:
>>
>> <a
xlink:href="http://mywebsite.com/my_label"> box </a>
>>
>> Or, in other words, to translate:
>>
>> <a
>>
xlink:href="http://takingserviceforward.org/wiki/index.php?title=Ser...
>>
>> <text
>> fill="black"
>> x="332"
>> xml:space="preserve"
>> y="159"
>> clip-path="url(#clipPath8)"
>> stroke="none"
>> id="text88738">My_Label</text>
>> <rect
>> x="1356"
>> y="370"
>> clip-path="url(#clipPath5)"
>> fill="none"
>> width="246"
>> rx="27.5"
>> ry="27.5"
>> height="54"
>> stroke="rgb(255,255,181)"
>> id="rect88726" />
>>
>> To:
>> <a
>>
xlink:href="http://takingserviceforward.org/wiki/index.php?title=My_...
>> <text fill="black"
>> x="332"
>> xml:space="preserve"
>> y="159"
>> clip-path="url(#clipPath8)"
>> stroke="none"
>> id="text88738">My_Label</text>
>> <rect
>> x="1356"
>> y="370"
>> clip-path="url(#clipPath5)"
>> fill="none"
>> width="246"
>> rx="27.5"
>> ry="27.5"
>> height="54"
>> stroke="rgb(255,255,181)"
>> id="rect88726" />
>> </a>
>>
>> I'd be grateful for any suggestions - if there's something else
>> that manipulates .svg files that could do this, it'd be good to
>> know!
>>
>> ------------------------------------------------------------------------------
>> Dive into the World of Parallel Programming The Go Parallel
>> Website, sponsored by Intel and developed in partnership with
>> Slashdot Media, is your hub for all things parallel software
>> development, from weekly thought leadership blogs to news, videos,
>> case studies, tutorials and more. Take a look and join the
>> conversation now.
http://goparallel.sourceforge.net/
>> _______________________________________________ Inkscape-user
>> mailing list Inkscape-user(a)lists.sourceforge.net
>>
https://lists.sourceforge.net/lists/listinfo/inkscape-user
>>
>
> ------------------------------------------------------------------------------
> Dive into the World of Parallel Programming The Go Parallel
> Website, sponsored by Intel and developed in partnership with
> Slashdot Media, is your hub for all things parallel software
> development, from weekly thought leadership blogs to news, videos,
> case studies, tutorials and more. Take a look and join the
> conversation now.
http://goparallel.sourceforge.net/
> _______________________________________________ Inkscape-user
> mailing list Inkscape-user(a)lists.sourceforge.net
>
https://lists.sourceforge.net/lists/listinfo/inkscape-user