#!/bin/sed -f
#pay attention: this version is for the linux distribution of sed
#the difference is that the | and {} and <> and _ 
#do not have to be escaped to be used as normal chars

#this is a script to convert tiki wiki page 
#source to moinmoin wiki page source


#convert headlines
s/^-\([=]*\)\([^=]*\)\1-$/\1 \2 \1/

#convert boldface
s/__\([^_]*\)__/'''\1'''/g

#convert enumeration
s/^#/ 1. /

#convert list
s/^\*/ \*/

#link conversion: replace "|" by " " in links
/\[/,/\]/ s/\(\[[^|]*\)|\([^]]*\]\)/\1 \2/g


/{/,/}/ {
 #convert local picture files to attachments
 s/{picture file=img\/wiki_up\/\/\([^}]*\)}/attachment:\1 /g
 #convert picture links
 s/{img src=\([^}]*\)}/ \1 /g
}

#remove {SPLIT()} commands
/{SPLIT()}/,/{SPLIT}/ {

  s/^ -//

  s/{SPLIT()}/----/

  s/{SPLIT}/----/

}

#convert ))TikiPage(( to !TikiPage
s/))\([^(]*\)((/\!\1/g

#table conversion
/||/,/||/ {

  #remove || at beginning and end of table
  s/||//g


  #put | at beginning and end of a table row

  s/^\([^|]*\)|/|\1|/
  s/|\([^|]*\)$/|\1|/

  #replace | by ||

  s/|/||/g

}

#convert centered things
s/^::\(.*\)::$/||<tablestyle="width:100%; text-align:center;"> \1 ||/