Since I've been busy at the UGM I haven't had the time to really pay
attention to this thread (or the longer one that spawned it). Apologies for
that.

First: I agree that the current situation is "a bit" ugly.

There is certainly a reason the RDKit generates SVG in the form that it
does, but I (not that surprisingly) don't remember what that reason was. At
the time I did this I was testing the output SVG using several different
display systems (multiple browsers, the ipython notebook, the preview tool
in ubuntu, the java-based renderer in KNIME, likely others) and what you
currently see seemed, at the time, to be the best compromise. Revisiting
this is no problem, but I'm going to balk if it breaks rendering with any
of the endpoints I care about.


On Wed, Oct 26, 2016 at 3:07 AM, Peter S. Shenkin <shen...@gmail.com> wrote:

> Indeed, when the file under discussion most recently named "svg2.html" is
> modified so that "xmlns:svg=" is replaced with "xmlns=", and the file is
> renamed "svg2.svg", double-clicking it opens it and correctly correctly
> displays the image in the browser.
>
> But trying this in the Jupyter notebook fails. the original code had the
> lines:
>
> svg = drawer.GetDrawingText().replace('svg:','')
> display(SVG(svg))
>
> This succeeded. If i add Dimitri's latest sugesstion:
>
> svg = drawer.GetDrawingText().replace('svg:','').replace('
> xmlns:svg=','xmlns=')
> display(SVG(svg))
>
> this also succeeds. If I only carry out the second replacement, this fails
> with an error several levels down.
>
> So apparently, SVG() can create an svg object out of the contents of a
> correctly formed svg file, but is insensitive to some constructs that make
> the such a file invalid for direct use in a browser.
>
> I'm still not sure why GetDrawingText() doesn't return a properly
> formatted svg string. Is there some use its output can be put to without
> these .replacements?
>
> -P
>
> On Tue, Oct 25, 2016 at 1:35 PM, Dimitri Maziuk <dmaz...@bmrb.wisc.edu>
> wrote:
>
>> On 10/25/2016 11:21 AM, Peter S. Shenkin wrote:
>> > Hi, Hongbin,
>> >
>> > Thanks. Indeed. svg2.svg, when renamed to svg2.html, shows the correct
>> > image in Chrome. svg.html shows garbage.
>> >
>> > Still, it would be good to be able to create a real .svg file from
>> RDKit.
>>
>> OK, you made me look and I learned something today.
>>
>> Mozilla claims valid SVG must include the namespace declarations
>> (https://developer.mozilla.org/en-US/docs/Web/SVG/FAQ) citing this
>> document: https://jwatt.org/svg/authoring/#namespace-binding
>>
>> There it states
>> """
>> <svg xmlns="http://www.w3.org/2000/svg";
>> ...
>> Be careful not to type xmlns:svg instead of just xmlns when you bind the
>> SVG namespace. This is an easy mistake to make, but one that can break
>> everything. Instead of making SVG the default namespace, it binds it to
>> the namespace prefix 'svg', and this is almost certainly not what you
>> want to do in an SVG file. A standards compliant browser will then fail
>> to recognise any tags and attributes that don't have an explicit
>> namespace prefix (probably most if not all of them) and fail to render
>> your document as SVG.
>> """
>>
>> Sure enough, rdkit's files start with
>> """
>> <svg:svg version='1.1' baseProfile='full'
>>               xmlns:svg='http://www.w3.org/2000/svg'
>> ...
>> """
>>
>> With that declaration any standards-compliant viewer should only
>> recognize tags with "svg:" prefix, and removing svg:'s results in a
>> technically invalid file. Anything that displays it as an image is what
>> we "it professionals" call b0rk3d.
>>
>> According to this, what RDKit writes out is wrong: you actually *want
>> to* remove :svg from the root tag's "xmlns" attribute, then you *may*
>> remove the svg: prefixes from all tags (including the root one).
>>
>> Of course, that was last edited in 2007, maybe something changed in the
>> 10 years since.
>>
>> HTH,
>> --
>> Dimitri Maziuk
>> Programmer/sysadmin
>> BioMagResBank, UW-Madison -- http://www.bmrb.wisc.edu
>>
>>
>> ------------------------------------------------------------
>> ------------------
>> The Command Line: Reinvented for Modern Developers
>> Did the resurgence of CLI tooling catch you by surprise?
>> Reconnect with the command line and become more productive.
>> Learn the new .NET and ASP.NET CLI. Get your free copy!
>> http://sdm.link/telerik
>> _______________________________________________
>> Rdkit-discuss mailing list
>> Rdkit-discuss@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>>
>>
>
> ------------------------------------------------------------
> ------------------
> The Command Line: Reinvented for Modern Developers
> Did the resurgence of CLI tooling catch you by surprise?
> Reconnect with the command line and become more productive.
> Learn the new .NET and ASP.NET CLI. Get your free copy!
> http://sdm.link/telerik
> _______________________________________________
> Rdkit-discuss mailing list
> Rdkit-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>
>
------------------------------------------------------------------------------
The Command Line: Reinvented for Modern Developers
Did the resurgence of CLI tooling catch you by surprise?
Reconnect with the command line and become more productive. 
Learn the new .NET and ASP.NET CLI. Get your free copy!
http://sdm.link/telerik
_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to