Difference between revisions of "WikiExporter"

From Inkscape Wiki
Jump to navigation Jump to search
(* getting path and filename from Inkscape SVG)
 
m (link fix)
 
(7 intermediate revisions by one other user not shown)
Line 1: Line 1:
These are LionKimbro's notes on developing a wiki exporter.
I've written a bunch of little scripts that, together, make it so you can save to and load from an [http://www.oddmuse.org/cgi-bin/wiki [[OddMuse]]] wiki.


Date: 2004-02-12
It renders out both Inkscape .svg and .png versions of the data.
Inkscape version: 0.40
Target: Oddmuse


That is, a system so that you can load from and save to a wiki.
You can load from the wiki, make a few edits, hit "Ctrl-S," and the edited document is sent back to the wiki.


The wiki targetted by this exporter is Oddmuse. We have [http://www.oddmuse.org/cgi-bin/oddmuse/Automatic_Posting_and_Uploading#wikiupload an upload script for it.]
It's fun!


I imagine it should be possible to use the Wiki XML-RPC interfaces as well, in the future, though they are usually turned off.
----


'''odd_output.inx'''
(I believe that means it should work for ''this'' wiki, as well, though I haven't tried it.)


This file goes in: /usr/share/inkscape/extensions
Basically, it goes like this:
* A script is called from Inkscape when the user saves,
* the script reads the SVG document to figure out what directory it was saved to,
* the script reads it to figure out what filename was used as well,
* information about the target wiki is read from the directory the SVG was saved to,
* the Inkscape SVG is uploaded to the wiki,
* and a PNG version is uploaded to the wiki as well.


  <inkscape-extension>
This all requires 4 files:
  <name>Oddwiki Output</name>
* odd_output.inx -- Inkscape extension definition
  <id>org.inkscape.output.odd</id>
* svg2oddmuse.sh -- coordinates most everything
  <dependency type="executable" location="extensions">svg2oddmuse.sh</dependency>
* svgattrs.py  -- scans the SVG file for <svg ...> attributes
  <output>
* wikiupload.py -- oddmuse upload script
      <extension>.odd</extension>
      <mimetype>image/x-svgz</mimetype>
      <filetypename>Oddmuse Wiki POST (*.odd)</filetypename>
      <filetypetooltip>Oddmuse Wiki proxy (SVG, PNG of Drawing)</filetypetooltip>
      <dataloss>FALSE</dataloss>
  </output>
  <script>
      <command reldir="extensions">svg2oddmuse.sh</command>
      <helper_extension>org.inkscape.output.svg.inkscape</helper_extension>
  </script>
  </inkscape-extension>


'''What data am I receiving from Inkscape?'''
Furthermore, the user creates a custom file, "notes.txt".
The file details the username and wiki URL for svg2oddmuse.sh.


To see what you're getting from Inkscape, create the following script, and call it: '''svg2oddmuse.sh'''
The [http://www.emacswiki.org/cw/InkscapeToOddmuse full description of how it works] is on [http://communitywiki.org/ [[CommunityWiki]].]


#!/bin/bash
Next, I intend to write code to ''read'' Inkscape SVG from the wiki as well.
echo "hello, world" > /tmp/eraseme.txt
echo "invocation: $@"
echo
echo "$1:"
cat "$1"
echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - -"
env


It appears that no environment variables are being set. The first (and only) argument is the location of a file in /tmp that contains the Inkscape SVG data.
The process is kind of hacky; I imagine that when one of the [[ExtensionArchitectureProposals]] is chosen and implemented, it'll be a lot nicer.


'''Now what?'''
'''Drawing Area?'''


The strategy is this:
Right now, I've hard coded it to export the ''page.''


* create a directory, representing the wiki
The relevant code looks like this:
* place a file in the directory, "oddmuse.txt", representing necessary details about the wiki
* when the user saves a file to the directory (.odd extension,) do the following:
** push the SVG to the wiki
** render a PNG, and push the PNG to the wiki
** perhaps append the name of the wikipage containing the SVG to a page on the wiki


We don't have command-line access (bash argument, environment variable) to the filename or
inkscape --file="$[[INK_SVG]]" --export-png="$DOCBASE/$DOCNAME.png" --export-area "0:0:595.28:841.89" > /dev/null
directory it was saved in. But we CAN get this data from the Inkscape SVG.


The document has attributes:
I tried removing the --export-area, and all I got were tiny little 123 byte files.
* "sodipodi:docbase" -- path up to the save location
* "sodpodi:docname" -- filaname, including extension (".odd", in this case)


Ideally, my code would send off only the ''drawing,'' not the whole page.


== Inkscape Export process ==
Questions:
* Does the CLI interface support this in version 0.40? (Maybe I'm just missing it.)
* Is there a way I can easily get the information from the SVG? (Maybe I'm just missing it.)


* User hits "Save" in "Save As" dialog
'''Bitmaps to data URLs?'''
* Inkscape writes a file with a random name to /tmp
 
* Inkscape calls export bash script, with /tmp file as only argument
I saw in the examples, that a PNG was turned into a binary64 encoded data URL.
* Whatever bash outputs to /dev/stdout, Inkscape records to the file chosen by the user.
 
I haven't written the code to locate PNG references, and replace them with data URLs.
 
But, this is something that I think should be done with it.
 
Question:
* Is there a way to turn PNG images into data: URLs ''within Inkscape?''
* From the CLI?

Latest revision as of 02:33, 22 January 2006

I've written a bunch of little scripts that, together, make it so you can save to and load from an OddMuse wiki.

It renders out both Inkscape .svg and .png versions of the data.

You can load from the wiki, make a few edits, hit "Ctrl-S," and the edited document is sent back to the wiki.

It's fun!


(I believe that means it should work for this wiki, as well, though I haven't tried it.)

Basically, it goes like this:

  • A script is called from Inkscape when the user saves,
  • the script reads the SVG document to figure out what directory it was saved to,
  • the script reads it to figure out what filename was used as well,
  • information about the target wiki is read from the directory the SVG was saved to,
  • the Inkscape SVG is uploaded to the wiki,
  • and a PNG version is uploaded to the wiki as well.

This all requires 4 files:

  • odd_output.inx -- Inkscape extension definition
  • svg2oddmuse.sh -- coordinates most everything
  • svgattrs.py -- scans the SVG file for <svg ...> attributes
  • wikiupload.py -- oddmuse upload script

Furthermore, the user creates a custom file, "notes.txt". The file details the username and wiki URL for svg2oddmuse.sh.

The full description of how it works is on CommunityWiki.

Next, I intend to write code to read Inkscape SVG from the wiki as well.

The process is kind of hacky; I imagine that when one of the ExtensionArchitectureProposals is chosen and implemented, it'll be a lot nicer.

Drawing Area?

Right now, I've hard coded it to export the page.

The relevant code looks like this:

inkscape --file="$INK_SVG" --export-png="$DOCBASE/$DOCNAME.png" --export-area "0:0:595.28:841.89" > /dev/null

I tried removing the --export-area, and all I got were tiny little 123 byte files.

Ideally, my code would send off only the drawing, not the whole page.

Questions:

  • Does the CLI interface support this in version 0.40? (Maybe I'm just missing it.)
  • Is there a way I can easily get the information from the SVG? (Maybe I'm just missing it.)

Bitmaps to data URLs?

I saw in the examples, that a PNG was turned into a binary64 encoded data URL.

I haven't written the code to locate PNG references, and replace them with data URLs.

But, this is something that I think should be done with it.

Question:

  • Is there a way to turn PNG images into data: URLs within Inkscape?
  • From the CLI?