Benutzer:Yomomo/ Wiki2OO Writer

Zielsetzung Bearbeiten

Entwicklung eines Programms, das Wiki Quellcode in OpenOffice Writer übersetzt. Das bedeutet auch: Tabellen und Formeln in Wiki source werden als Tabellen und Formeln in Writer dargestellt (und NICHT als Bilder oder so). Das Programm ist noch am Anfang und ich bin dabei Erklärungen zu schreiben, die es hoffentlich anderen Entwicklern es ermöglichen werden, das Programm weiter zu entwickeln.

Was das Programm schon machen kann Bearbeiten

  • Ein Buch aus einer Wiki-TOC_Seite erstellen
  • Verschiedene Eigenschaften gleichzeitig erstellen, wie Hyperlinks (zu Wikipedia, Wikibooks und Internet), Fett, Italic, BigFond, Sub- und Superscript, Endnote und Footnote, in beliebiger Reihe.
  • Bilder einbeziehen (Funktion noch nicht vollständig)
  • Formel erstellen (auch komplizierte, mit Integralen)
  • Tabellen erstellen (auch komplizierte, mit verbundenen Zellen) (noch nur mit {| am Anfang) (der Text der Zellen wird auch bearbeitet)

Was das Programm noch nicht machen kann Bearbeiten

  • Kaffee, Wunder und viel anderes, wie z.B.:
  • Schnell sein (ist sehr langsam, also inzwischen meditieren!)
  • Fehlerbehandlung
  • Dokumentation fehlt noch.
  • ...

Grundsätzlich ist doch das Programm fertig (die notwendigen Algorithmen sind vorhanden), es braucht noch Arbeit um alle Fälle einzubeziehen...

Das Programm selber Bearbeiten

REM  *****  BASIC  *****
Sub Main
createBookFromTOCSite
End Sub


'oText.insertControlCharacter(oViewCursor,_com.sun.star.text.ControlCharacter.LINE_BREAK, false)


'!!!! REMARK !!!!
'I created some procedures when I still was inexperienced, so some of them are rather
'primitiv, but they are functioning, so,because of the time needed, I left them like 
'this. If you have fun with it, you are welcome to improve them

sub createBookFromTOCSite

dim tocDoc
dim tocVC
dim tocTC

'dim oodu

dim neon
dim mycunt
dim myctc

dim adressDoc
dim oCuad

dim titstring as string
dim savedir as string
dim titplus as integer
dim tits1 as integer
dim tits2 as integer

dim noArgs()

titplus=1
    savedir = InputBox("give the path where your browser saves files","see your browser and adjust its tools","file:///home/georg/Λήψεις/",1440 *2 , 1440 * 4 )


	tocDoc=thisComponent
    tocVC = tocDoc.CurrentController.getViewCursor 'und erzeugt einen ViewCursor
    tocTC = tocDoc.Text.CreateTextCursor 'der TextCursor kommtamAnfangdesTextes
    tocTC.goToEnd(false)
    tocTC.goToStart(false)
    tocVC.gotoRange(tocTC,false) 'a text cursor can't go to the end of a line
   		   If NOT tocVC.isAtStartOfLine() Then
  		      tocVC.gotoStartOfLine(false) 
   		   EndIf
    tocVC.gotoEndOfLine(true)  'so we have to use the view cursor.
    titstring = tocVC.String 'nimmt den selected Text

neon = StarDesktop.LoadComponentFromUrl("private:factory/swriter", "_blank", 0, noArgs())
    mycunt = neon.CurrentController.getViewCursor 'und erzeugt einen ViewCursor
    myntc = neon.getText().createTextCursor()
   	neon.insertControlCharacter(mycunt,_com.sun.star.text.ControlCharacter.LINE_BREAK, false)

adressDoc = StarDesktop.LoadComponentFromUrl("private:factory/swriter", "_blank", 0, noArgs())
    oCuad = adressDoc.CurrentController.getViewCursor 'und erzeugt einen ViewCursor


    Do While tocVC.goDown(1,true)  'so lang oVC immer noch nach unten gehen kann
				'wird der Text bearbeitet
 	tocVC.goUp(1,True)	'man muss aber doch am Anfang anfangen
  

'for documentation see the first part of this sub
    If Left(titstring,2) ="==" Then
    titstring=Left(titstring,Len(titstring)-2)
    titstring=Right(titstring,Len(titstring)-2)
    titplus=2
    tits1=tits1+1
'    titstring =  tits1 & "."  & titstring
    tits2=0
    mycunt.getText().insertString(mycunt,titstring,true)
    mycunt.gotoStartOfLine(true)  
    mycunt.NumberingLevel = "Level 1"
    mycunt.ParaStyleName = "Heading 1" 
   	mycunt.gotoEndOfLine(false) 
    mycunt.getText().insertString(mycunt,chr$(13),false)
    EndIf


    If Left(titstring,1) ="*" Then
    titstring=Right(titstring,Len(titstring)-1)
    l=instr(titstring,"[[")
    tit2=tit2+1 
'code to change wiki hyperlink in hyperlink and chapter title
'https://de.wikibooks.org/w/index.php?title=	
		   Do While  inStr(titstring,"]]")=0
		   		If inStr(titstring,"]]")<>0 Then
		   		  Exit Do
		   		EndIf  
		        skipLine(tocVC,tocTC)			
 		    	titstring =titstring + tocVC.String 'read the marked text
 		   Loop 
		  k=inStr(titstring,"|")
		  u=inStr(titstring,"]]")
		  wikiAdress= "https://de.wikibooks.org/w/index.php?title="  & Mid(titstring,l+2,k-l-2)&"&action=raw"
		  oCuad.Text.insertString(oCuad,wikiadress,true)
		  oCuad.HyperLinkTarget = wikiAdress
		  oCuad.HyperLinkURL = wikiAdress

	titstring= Mid(titstring, k+1,u-k-1) 		    
'    titstring = tit0 & "." & tit1 & "." & tit2 & "." & titstring
    mycunt.getText().insertString(mycunt,titstring,true)
    mycunt.gotoStartOfLine(true)
    mycunt.NumberingLevel = "Level " & (titPlus) 
    mycunt.ParaStyleName = "Heading " & (titPlus)
   	mycunt.gotoEndOfLine(false) 
    mycunt.getText().insertString(mycunt,CHR$(13),false)
   	callChapterFromInternet(adressDoc,mycunt, savedir)
   	neon.insertControlCharacter(mycunt,_com.sun.star.text.ControlCharacter.LINE_BREAK, false)
   	oodu.dispose()
    EndIf

		
	skipLine(tocVC,tocTC)
	titstring = tocVC.String 'read the marked text	


	DO While NOT instr(titstring,"==")=0 
	If  not instr(titstring,"*")=0 then
	exit do
	endif
	skipLine(tocVC,tocTC)
	titstring = oVC.String 'read the marked text	
	tocVC.goDown(1,false)  'go to next line
   	tocVC.gotoEndOfLine(false)  'go to the end of the next line
	Loop
  
     Loop  

'until hier the whole book is downloaded but with minimal processing
'we must go again to the beginning of the whole text and process it

    mynTC.goToStart(false)
    mycunt.goToStart(false)
    
do    
Wiki2OpOffWr(mycunt, myntc, tits, titplus)
loop while myntc.gotonextparagraph(false)

oIndex = neon.createInstance("com.sun.star.text.ContentIndex")
 oIndex.CreateFromOutline = True
 myntc.gotoStart(False)
neon.getText().insertTextContent(myntc, oIndex, False)
oIndex.update()

dim embed as String
embed = InputBox("embed the images now?","y for yes or something else for no","y",1440 *2 , 1440 * 4 )

If embed="y" then
EmbedLinkedGraphics(neon)
endif

end Sub



sub callChapterFromInternet(Optional addoc,Optional rtc, Optional savedir as string)

dim document   as object
dim dispatcher as object
dim n as Integer
dim m as Integer
dim i as Integer


document   = addoc.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

dispatcher.executeDispatch(document, ".uno:OpenHyperlinkOnCursor", "", 0, Array())

i=0
m=0
'file1= "file:///home/georg/Λήψεις/index.php" 
Do While Not FileExists(savedir &"index.php") 
wait(100)
m=m+100
If m>10000 then
'MsgBox("waited too long for the Internet, link not found!", 0, "Error")
rtc.Text.insertString(rtc,"no link found: " & addoc.CurrentController.getViewCursor.Text.getString  & CHR$(13),false)
exit sub
EndIf
Loop
wait(2000)

n = FreeFile()
Open savedir &"index.php" For Append Access Read Write As #n
seek(#n,1)
rtc.Text.insertString(rtc, s1 & CHR$(13),false)

Do 
Line Input #n, s1
s2=s1
If Left(s1,1)="*" then
s1=s1 & "&&§"
endif
Do while  left(s2,1)="#"
If  EOF(#n) then
s1=s1 & "&&&"
exit do
endif
Line Input #n, s2
s1=s1 & "&&&" & s2
loop
rtc.Text.insertString(rtc, s1 & CHR$(13),false)
Loop until EOF(#n)
close #n

kill(savedir & "index.php")

End sub



'this is a simple replace procedure. At the beginning of the main sub (wiki2opoffwr)
'many of the characteristic characterfollows (eg [[ at the beginning or ]] at the end
'of a wiki hyperlink) are replaced through other symbols (eg <§wl) that make the 
'programming easier. Some keywords will be deleted (replaced through ""), because I 
'didnt find them so important(eg style in a table), but if you want to, you can also 
'change the code and take tham under concern

Sub myReplace(oDescriptor, oDoc, mySearchStr, myReplaceStr)

With oDescriptor
.SearchString = mySearchStr
.ReplaceString = myReplaceStr
End With
oDoc.ReplaceAll(oDescriptor)

End Sub


sub selectParagraph(optional mycunt, optional myntc)

    mynTC.goToStartofParagraph(false)
    mycunt.gotoRange(mynTC,false)
    mynTC.gotoendofparagraph(true)
    mycunt.gotoRange(mynTC,true) 'a text cursor can't go to the end of a line
    
end Sub    


'this procedure moves the cursors to the next line
'the view cursor can read lines but not paragraphs so it goes to the beginning of the next line
'the text cursor can read paragraphs, sentences and words, but not lines
'both cursors can move right and left but only the view cursor can move up and down
'If you write true, then text in the movement will be selected, if there was text already selected
'it will be selected too. so if you do something with the cursor like set string, the whole selected
'text will be replaced
Sub skipLine(Optional oVC,Optional oTC)
 		   oVC.goRight(1,false)  'go to next line
   		   If NOT oVC.isAtStartOfLine() Then
   		      oVC.gotoStartOfLine(false) 
   		   EndIf
   		   oVC.gotoEndOfLine(true)  'go to the end of the next line and mark the line
    	   oTC.gotoNextParagraph(false)  'go to the beginning of the next line
End Sub    	   


sub gotostartofparagraph(Optional cvc, Optional ctc)

ctc.gotostartofparagraph(false)
cvc.gotoRange(cTC,false)

end sub 




function getparagrstr(optional ctc )as string
ctc.gotostartofParagraph(false)
ctc.gotoendofparagraph(true)
if instr(ctc.string,"{|")>0 then
getparagrstr=ltrim(ctc.string)
else
getparagrstr=(ctc.string)
endif 
end function



'this procedure creates the headings of each chapter. In wiki syntax, == === and so on will be used
'this is replaced through numbers, the text remains as it is. At the end of the main procedure is
'also a TOC (Table Of Contents) created, so, everything will be automatic. This means, if you want to
'add a chapter later in your book, you can do it (you have to choose the right parameter for the title)
'the level of the chapter depends on the number of =. so == is the first level. The chapter title (and
'number) is determined through the Hyperlink of the chapter and the order in all chapters
'this is something to do later....

'this procedure will be called in a loop, and every time it is called, the appropriate value will be changed
'eg tit1 for the value of the first level. so if you have in wiki source text a == for a second time,
'then the value of tit1 will change to 2 und the number of all subchapters will begin with 2...

Sub createTOC(Optional oCurs,  tit0 As string, titl1 as Integer, titl2 as Integer, titl3 as Integer, titl4 as Integer, Optional titPlus as Integer)

dim tit1 As Integer
dim tit2 As Integer
dim tit3 As Integer
dim tit4 As Integer
dim sexForm as String

sexForm=oCurs.string
tit1=titl1 : tit2=titl2 : tit3=titl3 : tit4=titl4 
'!!!!! Documentation is for all parts similar !!!!! This is the first part  !!!
    If Left(sexForm,5) ="=====" Then
    sexForm=mid(sexForm,6,Len(sexForm)-10)
    tit4=tit4+1
    sexForm = tit0 & "." & tit1 & "." & tit2 & "." & tit3 & "." & tit4 & "." & sexForm 'four levels
    oCurs.String=sexForm
    oCurs.NumberingLevel = "Level " & (4+titPlus) 'attribute of the text, in order to include it in the TOC
    oCurs.ParaStyleName = "Heading " & (4+titPlus) 'attribute of the text, so that it looks like heading
	oCurs.goleft(1,false) : oCurs.goright(1,false)
    EndIf
  

'for documentation see the first part of this sub
    If Left(sexForm,4) ="====" Then
    sexForm=mid(sexForm,5,Len(sexForm)-8)
    tit3=tit3+1
    sexForm = tit0 & "." & tit1 & "." & tit2 & "." & tit3 & "." & sexForm 'four levels
    tit4=0
    oCurs.String=sexForm
    oCurs.NumberingLevel = "Level " & (3+titPlus)
    oCurs.ParaStyleName = "Heading " & (3+titPlus)
	oCurs.goleft(1,false) : oCurs.goright(1,false)
    EndIf
  

'for documentation see the first part of this sub
    If Left(sexForm,3) ="===" Then
    sexForm=mid(sexForm,4,Len(sexForm)-6)
    tit2=tit2+1    
    sexForm = tit0 & "." & tit1 & "." & tit2 & "." & sexForm
    tit4=0
    tit3=0
    oCurs.String=sexForm
    oCurs.NumberingLevel = "Level " & (2+titPlus) 
    oCurs.ParaStyleName = "Heading " & (2+titPlus)
	oCurs.goleft(1,false) : oCurs.goright(1,false)
    EndIf
  

'for documentation see the first part of this sub
    If Left(sexForm,2) ="==" Then
    sexForm=mid(sexForm,3,Len(sexForm)-4)
    tit1=tit1+1
    sexForm = tit0 & "." & tit1 & "."  & sexForm
    tit4=0
    tit3=0
    tit2=0
    oCurs.String=sexForm
    oCurs.NumberingLevel = "Level " & (1+titPlus) 
    oCurs.ParaStyleName = "Heading " & (1+titPlus)
	oCurs.goleft(1,false) : oCurs.goright(1,false)
    EndIf

sexForm=CHR$(13)'move one line down

titl1=tit1 : titl2=tit2 : titl3=tit3 : titl4=tit4 
    
End Sub




'******* CREATETABLE *********
'this sub creates a table when you find {| in wiki source. Of course there are other tables in wiki
'this is TODO. This sub reads in the first part the number of lines(y) und columnes (x). Then we 
'create a table with x col und y rows. the cursor goes (hopefully) then again to the beginning of 
'the table and reads one line after the other (|- shows a new row, | or ! a  new column, a new element
' in a row). so we know in which column and row we are and the content will be added to the right cell.
'A bug because of the wiki source code (sometimes you have an extra |- at the beginning or the end of the 
'table) was solved with ignoring the first and deleting the last row (which didint contain anything) of 
'the table. This sub is not gut for complex tables (eg with merged and splitted cells)
'for more complicated tables there is code needed, that reads the complex elements almost one after the 
'other and then adds them to the table. this is TODO

'******* CREATETABLE *********

Sub createTable(Optional neon, Optional ovc,Optional otc)

Dim y as Integer 'counts rows
Dim x as Integer 'counts columns of the table
Dim m as Integer 'counts lines of the document and rows ofthe table, used as sign and iterates 
Dim k as Integer 'counts lines of the document and col of the table, used as sign and iterates
Dim p as Integer 'counts lines of the document and col of the table, used as sign and iterates
Dim r as Integer 'counts lines of the document and col of the table, used as sign and iterates
Dim z as Integer 'iterates
Dim w as Integer 'iterates
Dim tabcou as Integer 'iterates
Dim title as String 'for the title of the text or as dummy
dim mTC 'text cursor to mark the position of the title
dim xTC 'text cursor to mark the position of the title
Dim oTable 'creates the table
Dim oInsertPoint 'gets the end of the element
Dim oCellNames 'reads the cells
dim oCursor 'a cell cursor
dim sexForm as String 'the section of the text of the source code
dim sexForm1 as String 'the section of the text of the source code
dim sexForm2 as String 'the section of the text of the source code
dim sexForm5 as String 'the section of the text of the source code
dim s2 as String 'the section of the text of the source code
dim oRows 'for the rows of the table

mTC = otc.text.CreateTextCursor 
xTC = otc.Text.CreateTextCursor 
otc.gotoendofparagraph(false)
xtc.gotorange(otc,false)
otc.gotostartofparagraph(false)
mtc.gotoRange(otc,false)
sexform=getparagrstr(otc)
'print sexform
sexForm1= ""
y=1
x=0
m=0
k=0
z=0
tabcou=0

dim lintc
lintc = otc.text.CreateTextCursor
lintc.gotorange(otc,false)

do 
    If Left(sexForm,2) ="|+" Then 
lintc.gotonextparagraph(false)    
sexform=getparagrstr(lintc)
Ltrim(sexform)
	endif
    If Left(sexForm,2) ="{|" Then
     x=x+1
     If x>1 then
      do 
      lintc.gotonextparagraph(false)
      sexform=getparagrstr(lintc)
      Ltrim(sexform)
'      print sexform
      loop while Left(sexForm,2)<>"|}" 
'     x=x-1
     endif      
    endif 
    If Left(sexForm,2) ="|}" Then x=x-1
	If (Left(sexForm,1) ="|" or "!")and right(left(sexform,2),1)<>"-" then k=1
    If Left(sexForm,2) ="|-" AND k>0 Then m=m+1
lintc.gotonextparagraph(false)    
sexform=getparagrstr(lintc)
loop while x>0
sexform=getparagrstr(otc)
'print sexform & m
r=m+1
'print  m
y=1
x=0
m=0
k=0
z=0

rem READ THE NUMBER OF LINES AND COLUMNS IN THE TABLE
Do  'read the lines of the source code until you find the end of the table |}

'sometimes there is a title in the table after the code |+. This part reads this title and places
'it BEFORE (this means OUTSIDE) the table.
    If Left(sexForm,2)="|+" Then 'if you have the code for the beginning of the title
      title=Right(sexForm, Len(sexForm)-2)
	    otc.gotonextparagraph(false)
	    sexform=getparagrstr(otc)
      Do While  Left(sexForm,1) <> "|" And Left(sexForm,1) <> "!"  'if its not a new row or column which starts with | Or !
        title=title & sexform
	    otc.gotonextparagraph(false)
	    sexform=getparagrstr(otc)
	  Loop 'until you find the next column or line
'	  print "tit " & title
	EndIf    'so you have the whole title unter the string title. This will be added before the table later
	
	
'all rows have the same number	of columns so we need to count them only in the first line y=1   
    If y=1 Then
      If (instr(sexForm,"||")<> 0 OR instr(sexForm,"!!")<> 0)  then
      x=x+1
      sexform2=sexform
       If instr(sexForm,"||")<> 0 then
        Do While  instr(sexform,"||")<>0 
          x=x+1
          sexform=mid(sexform,instr(sexForm,"||")+2)
        Loop
       endif
      sexform=sexform2  
       if  instr(sexForm,"!!")<> 0 then  
        Do While instr(sexForm,"!!")<> 0
          x=x+1
          sexform=mid(sexform,instr(sexForm,"!!")+2)
        Loop
       endif   
      elseIf (Left(sexForm,1) = "|" OR Left(sexForm,1) =  "!") AND  (Right(Left(sexForm,2),1)<>"-" AND Right(Left(sexForm,2),1)<>"}" )Then      '
        x=x+1 
	  EndIf
	  If instr(sexform,"colspan")<>0 then
	    x=x+(ASC(mid(sexform,instr(sexform,"colspan")+9,1))-ASC(0))-1
	  Endif  
	EndIf  
	If  Left(sexForm,2) ="|}"   then y=y+1
    If Left(sexForm,2) ="|-" AND x>0 Then
      y=y+1
    ElseIf Left(sexForm,2) ="|-" AND x=0 Then
    z=2  'in order to ignore a |- at the beginning of the table source code, which actually is no row
    EndIf 'this z =2 will be then used by the creation of the table
	    otc.gotonextparagraph(false)
	    sexform=getparagrstr(otc)
'print sexform & y
	    
Loop While y<2 'Left(sexForm,2) <>"|}" ' ( tabcou>0)' or

 y=r
'so here we have read the number of rows and columns
k=0
m=0
Dim tbor
dim xWid
'create table to insert content
oTable = neon.createInstance( "com.sun.star.text.TextTable" )
oTable.initialize(y,x) 'y rows, x columns
oTable.BackColor=RGB(240,240,240)
xtc.gotorange(mtc,false)
If title<>"" then
mtc.getText().insertString(mtc , title & CHR$(13), false)
xtc.gotorange(mtc,false)
mtc.gotopreviousparagraph(false)
createtextelement(neon,mtc)
endif
xtc.text.insertTextContent(xtc , oTable, False)
otc.gotorange(xtc,false)
sexform=getparagrstr(otc)
		sexForm1=""
'so now we find one cell after the other and insert its content	
if left(sexform,2)="{|" then
otc.gotonextparagraph(false)
sexform=getparagrstr(otc)
endif
	
Do While  Left(sexForm,2) <>"|}" 
   If Left(sexForm,2)="|}" Then 
    exit do
    endif
  If Left(sexForm,2) ="|-" Then 'if you have the code for a line
    If z=0 Then
    m=0
otc.gotonextparagraph(false)'dont do anything with sexform, its no cell content
sexform=getparagrstr(otc)
	  k=k+1 'GO TO NEXT line, k is counting lines
	ElseIf z=2 Then
	oVC.String=""
	  z=0 'ignore a |- at the beginning of the table, it s no row, contains only attributes i didnt need
	EndIf    
  EndIf 


  
'here we need the next column in a row, which means in a not complex table: we have the next cell
'So we read in the source code its content and add it in the table
'The text of the cell can include also attributes. We also deal with them here
'a column begins with | or ! if its not followd by the characters exclluded here
      If (Left(sexForm,1) = "|" OR Left(sexForm,1) = "!") AND  Right(Left(sexForm,2),1)<>"-" And Left(sexForm,2)<>"|+" Then
		If m<x then
		 If  Left(sexForm,2)="|}" Then 'at the end of the table leave the loop
		  Exit Do
		 EndIf
'		 	 print x & " xy " & y &  " " & m & " mk  " & k & " sex " & sexform
		  oCell=oTable.getCellByPosition(m, k)'open the m column k row cell,WARNING: it s the opposite from initialise table
		  oCelTC = oCell.Text.createTextCursor 'create a text cursor in the text of the cell
		  oCelTC.CharHeight=9 'determine the general fontsize of the text in the cells (i prefer it small)

		  if  instr(sexform,"||")<>0 OR  instr(sexform,"!!")<>0 then
		    If (instr(sexform,"||")> instr(sexform,"!!") And instr(sexform, "!!")<>0) Or instr(sexform,"||")=0  then
		    sexform2=sexform
		    sexform = left(sexform2, instr(sexform2,"!!")-1)
		    sexform2 = right(sexform2,len(sexform2)- instr(sexform2,"!!"))
		    else
		    sexform2=sexform
		    sexform = left(sexform2, instr(sexform2,"||")-1)
		    sexform2 = right(sexform2,len(sexform2)- instr(sexform2,"||"))
		    endif
		    otc.string= sexform2
		    If Len(sexform2)<>0 then
		    otc.gotopreviousparagraph(false)
		    endif
		  endif  
		 sexform2=""

'here we deal with the attributes, like class style etc In the most cases i ignore them. Of course
'in all cases we dont need their text, so i remove it

		 IF inStr(sexForm,"style="  )<>0 or inStr(sexForm,"class="  )<>0 or inStr(sexForm,"align=" )<>0 or instr(sexform, "colspan")<>0 or instr(sexform, "rowspan")<>0 then
			sexform2=mid(sexform,2,instr(mid(sexform,2),"|"))
			sexform=left(sexform,1) & mid(sexform,len(sexform2)+2)
		 endif	
'I leave everything about style out...
'		 IF inStr(sexForm2,"style=" & CHR$(34) )<>0  then
'but if you want to, you can do something here!
'		 endIf
		 		 
'I ignore also the class attribute		 
'		 IF inStr(sexForm,"class=" & CHR$(34) )<>0 then
'but if you want to, you can do something here!
'		 EndIf

'But I dont ignore alignment. Later i should add code about left and right alignment: TODO		 
		 If inStr(sexForm2,"align"  )<>0 then
		   If inStr(sexForm2,"center")<>0 Then oCelTC.ParaAdjust = com.sun.star.style.ParagraphAdjust.CENTER
		   If inStr(sexForm2,"right")<>0 Then oCelTC.ParaAdjust = com.sun.star.style.ParagraphAdjust.RIGHT
		   If inStr(sexForm2,"left")<>0 Then oCelTC.ParaAdjust = com.sun.star.style.ParagraphAdjust.LEFT
		 EndIF

'this is a special style for languages, i ignore it too		 
		 Do while inStr(sexForm,"{{lang|" )<>0 
		   oVC.String=""  
		  sexform1=right(sexForm,Len(sexForm)-inStr(sexform,"{{lang|")-8 )
		  w=inStr(sexform1,"|")
		  sexForm=Left(sexForm, inStr(sexform,"{{lang|")-2)& mid(sexform1,w+1)
		  w=inStr(sexForm,"}}")
		  sexform1 = mid(sexForm,w+2)
		  sexForm=Left(sexForm,w-1) 
		  sexForm = sexForm & " " & sexform1
		 Loop 'I do in this case loop, because this {{lang  can show up more than one times in one cell
		 
'I dont ignore the Bold attribute, which is declared through ! instead of | at the beginning of the source code		  
		  If Left(sexForm,1) = "!" Then
		  oCelTC.CharWeight  = com.sun.star.awt.FontWeight.BOLD
		  else 
		  oCelTC.CharWeight  = com.sun.star.awt.FontWeight.NORMAL
		  EndIf	

'the width can also be arranged here
		  if inStr(sexForm2,"width:" )<>0 then
		  dim celpro
		  celpro=otable.TableColumnSeparators
		  Dim colo(ubound(celpro())) As Integer
		  dim bc as integer
		  dim ac as integer
		  dim it as integer
		  dim sexform9 as string

		  if instr(sexform2, "colspan")<>0  then
		  bc=cint(mid(sexform2,instr(sexform2,"colspan")+9,2))-1
		  endif
		  it=m
		  do 
		    If it>0 then
		    colo(it)=celpro(it-1).position+cint(mid(sexform2,inStr(sexForm2,"width:" )+6,2))*100
		    else  'position is giving us the percentage pro 10000 of the distance from the left side
		    colo(it)=cint(mid(sexform2,inStr(sexForm2,"width:" )+6,2))*100
		    endif    'if you move a line more right than the next line, it will not be done
		    ac=it  'so I created an iterating subroutine (movesep) to move the next lines
		    movesep(celpro,colo(ac),ac,x-2)'if this is neseccary
		    if it<x-1 then celpro(it).position=colo(it)
		    it=it+1		  
		  loop while it<m+bc
		  otable.TableColumnSeparators=celpro
		  it=0
		  endif
		  
'Here we actually add the read and cleaned up text of the cell to the cell itsself
'for this we use the sub createtabletextelement, you can find it later
If Len(sexform)>0 then		  
  sexForm=Right(sexForm,Len(sexForm)-1)'remove the | or ! character at the beginning
endif

if instr(sexform2, "colspan")<>0  then
sexform=mid(sexform2,instr(sexform2, "colspan"),11) & sexform
'print sexform
endif

if instr(sexform2, "rowspan")<>0 then
sexform=mid(sexform2,instr(sexform2, "rowspan"),11) & sexform
endif
sexform2=""
		  oceltc.string=sexform
		  oceltc.gotostart(false)
		  Do
		  sexform=getparagrstr(oceltc) 
		  if instr(sexform,"file:")<>0 then createGraph(neon,oVC,oceltc)
		  createTextElement(neon,oceltc)
		  Loop while oceltc.gotonextparagraph(false)
		  Do
		  otc.gotonextparagraph(false)
		  sexform=getparagrstr(otc) : LTrim(sexform) 
 		  If  left(sexform,1)="*" or left(sexform,1)="#" then
 		  oCelTC.CharHeight=7
		  oceltc.text.insertstring(oceltc,sexform ,false)
		  createtextobject(sexform,neon,ovc,oceltc)
		  else
		  otc.gotopreviousparagraph(false)
		  exit do
		  endif
		  loop while left(sexform,1)="*" or left(sexform,1)="#"
		  Do
		  otc.gotonextparagraph(false)
		  sexform=getparagrstr(otc)
		  If left(sexform,2)="{|"  then
		  do  
		  oceltc.text.insertstring(oceltc,sexform & CHR$(13) ,false) 
		  otc.gotonextparagraph(false) : sexform=getparagrstr(otc)
		  loop while left(sexform,2)<>"|}" 
		  oceltc.text.insertstring(oceltc,sexform  ,false) 
		  oceltc.gotostart(false)
		  sexform=getparagrstr(oceltc)
		  createtextobject(sexform,neon,ovc,oceltc)
		  else
		  otc.gotopreviousparagraph(false)
		  exit do
		  endif
		  loop while left(sexform,2)<>"|}" 

'if the last row has no content (bug) remove it:Here we read what is in the last row		  
          If sexForm<>"|}" Then
        If k=y-1 then 
		  sexForm5=sexForm5 & sexForm
        EndIf
		  EndIf

		  
		  
        EndIf
        m=m+1 'GO TO NEXT COLUMN AND CELL
	  EndIf
	    
otc.gotonextparagraph(false)
sexform=getparagrstr(otc)
   If Left(sexForm,2)="|}" Then 
    exit do
    endif
	  
Loop

'If the last line doesnt contain anything (bug) then remove it
        If sexForm5="" Then
		oRows=oTable.getRows()
        oRows.removeByIndex(k,1) 
        EndIF

dim tabc

k=0

do 
oCellNames = oTable.getCellNames()
if k>UBound(oCellNames()) then
exit do
endif
tabc = oTable.createCursorByCellName(oCellNames(k))
ocell=oTable.getcellbyname(oCellNames(k))
sexform2=ocell.string
oCelTC = oCell.Text.createTextCursor 'create a text cursor in the text of the cell

if instr(sexform2, "colspan")<>0 and instr(sexform2, "rowspan")=0 then
w=ASC(mid(sexform2,instr(sexform2,"colspan")+9,1))-ASC(0)-1
oceltc.gotostartofparagraph(false) : oceltc.goright(instr(sexform2, "colspan")-1,false) 
oceltc.goright(11,true) : oceltc.string="" : oceltc.gotostartofparagraph(false)
IF tabc.goright(w,true) then
tabc.mergeRange() 
endif
endif

if instr(sexform2, "colspan")=0 and instr(sexform2, "rowspan")<>0 then
w=ASC(mid(sexform2,instr(sexform2,"rowspan")+9,1))-ASC(0)-1
oceltc.gotostartofparagraph(false) : oceltc.goright(instr(sexform2, "rowspan")-1,false) 
oceltc.goright(11,true) : oceltc.string="" : oceltc.gotostartofparagraph(false)
IF tabc.godown(w,true) then
tabc.mergeRange() 
endif
endif


if instr(sexform2, "colspan")<>0 and instr(sexform2, "rowspan")<>0 then
w=ASC(mid(sexform2,instr(sexform2,"colspan")+9,1))-ASC(0)-1
m=ASC(mid(sexform2,instr(sexform2,"rowspan")+9,1))-ASC(0)-1
oceltc.gotostartofparagraph(false) : oceltc.goright(instr(sexform2, "rowspan")-1,false) 
oceltc.goright(11,true) : oceltc.string="" : oceltc.gotostartofparagraph(false) : oceltc.gotoendofparagraph(true)
sexform2=oceltc.string : oceltc.gotostartofparagraph(false) : oceltc.goright(instr(sexform2, "colspan")-1,false)
oceltc.goright(11,true) : oceltc.string="" : oceltc.gotostartofparagraph(false) 
IF tabc.goright(w,true) And tabc.godown(m,true) then
tabc.mergeRange() 
endif
endif
k=k+1
loop while k<UBound(oCellNames())+1

tbor = oTable.TableBorder
xWid = tbor.LeftLine : xWid.OuterLineWidth = 15 : xWid.InnerLineWidth = 15 : xWid.LineDistance=60 : tbor.LeftLine = xWid 
xWid = tbor.RightLine : xWid.OuterLineWidth = 15 : xWid.InnerLineWidth = 15 : xWid.LineDistance=60 : tbor.RightLine = xWid 
xWid = tbor.TopLine : xWid.OuterLineWidth = 15 : xWid.InnerLineWidth = 15 : xWid.LineDistance=60 : tbor.TopLine = xWid 
xWid = tbor.BottomLine : xWid.OuterLineWidth = 15 : xWid.InnerLineWidth = 15 : xWid.LineDistance=60 : tbor.BottomLine = xWid 
oTable.TableBorder=tbor

'Delete the text for the table:
		  otc.gotonextparagraph(false)
		  otc.gotorange(xtc,true)'select the text
		  otc.string=""'delete it
		  otc.gotorange(xtc,false)'move the cursor right after the table
		  otc.gotostartofparagraph(false) : otc.gotoendofparagraph(true)

End Sub



sub movesep(optional celpro , optional colon as integer, optional j as integer, optional k as integer)

dim h,t  as integer
if j<k then
h=j
if celpro(j).position<colon then
j=j+1 : t=t+1
movesep(celpro,colon,j,k) 
celpro(h).position=colon+26*t
endif
endif

end sub



'this is to insert media from Wiki.
'The picture is  adjusted to the document with a steady width and the respective height.
'the loading of the graph doesnt work in OO 3.1 but the right URL is created

sub createGraph(Optional neon, Optional evc,Optional etc)

Dim oInsertPoint 'Where the graph will be inserted in the auxiliary doc
Dim oInsertPoin 'Where the table will be inserted in the target doc
Dim oGraph 'the graphic object
dim sexForm3 as String
dim sexForm4 as String
dim sexForm5 as String
dim sexForm8 as String

sexForm3=getparagrstr(etc)

etc.string="" 'delete the text
Do While inStr(sexForm3, "file:")<>0 'see if there is a media file in the string
  If  inStr(sexForm3, "file:")=0 Then
    etc.string=sexform3
    createtextelement(neon,etc)
    exit Do
  EndIf
  If   inStr(sexForm3, "[!")<>0 then 'by gallery there is no [! and there is only one file per paragraph
  sexForm4= Left(sexForm3,inStr(sexForm3, "[!")-1)'get the part of the string before the title of the graph
  endif
  sexForm3=Mid(sexForm3,inStr(sexForm3, "file:")+5)'the name of the Wikimedia file (yet not the URL)
  etc.text.insertstring(etc,sexform4,false)'if there is text before the name of the graph, insert it


  'now find the mediawiki URL of the graph. We need MD5 crypto code to create the full wikimedia name
  Dim strFullPathName as String
  Dim objDecrypt
  dim texthash

  objDecrypt = CreateUnoService("org.openoffice.Cryptographic.CryptographicService")
  sexForm8=Ltrim(rtrim(Left(sexForm3,inStr(sexForm3, "|")-1))) 'take the title of the graph
  'the following is necessary to create the right md5 signature
  Do While inStr(sexForm8," ")<>0 'in case there is gap instead of _ in the name, replace it with _
    sexForm8=left(sexForm8,inStr(sexForm8," ")-1) & "_" & mid(sexForm8,inStr(sexForm8," ")+1)
  Loop 'this is necessary to create the right md5 signature
   
  TextHash = objDecrypt.GetTextHash(sexForm8 , "MD5") 'hier is created the full wikimedia URL of the file
'  sexform5="http://www.massachusetts-prenuptial-agreements.com/wp-content/uploads/2011/05/Sunset-1.jpg"
  sexForm5="https://upload.wikimedia.org/wikipedia/commons/" & Left(TextHash,1) & "/" & Left(TextHash,2) & "/" & sexForm8 
  sexForm4= ltrim(Mid(sexForm3,inStr(sexForm3, "|")+1,inStr(sexForm3, "]]")-inStr(sexForm3, "|")-1 ))'get the caption of the graph
  if instr(sexform4,"!?&")<>0 then 
    sexForm4= Mid(sexForm4,inStr(sexForm4, "!?&")+3)'remove upright if there
    sexForm4= Mid(sexForm4,inStr(sexForm4, "|")+1)'remove upright if there
  endif  
  sexForm3= Mid(sexForm3,inStr(sexForm3, "]]")+2 )'get the rest of the string (if any) after the name of the graph 

'so, up to here: sexform5 is the URL, sexform4 the caption, sexform3 the rest (if any) of the string
oframe = neon.createInstance("com.sun.star.text.TextFrame")'crate a frame for the picture
oframe.width=7200 'with a suitable width for two columns
oframe.height=4200

dim frm
dim frmtc

frm=oframe.gettext() 'in order to create a text cursor in the frame

oGraph = neon.createInstance("com.sun.star.text.GraphicObject")'create a graph object
oGraph.GraphicURL =  sexForm5 'give the right URL
oGraph.width=7000 'with a suitable width for two columns
oGraph.height=4000
oGraph.AnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER
oframe.AnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER

etc.getText().insertTextContent(etc , oframe, false)'insert the frame in the text
'etc.Text.insertstring(etc, CHR$(13),false)
frmtc=frm.createTextCursor()'this is the frame text cursor, but you must first insert the frame!
'etc.HyperLinkTarget = sexForm5
'etc.HyperLinkURL = sexForm5

frmtc.gotostart(false)
frmtc.getText().insertTextContent(frmtc , oGraph, true)
If len(sexform4)=0 then 'if there is no caption
sexform4="Link" 'make a caption with the word link
endif 'we need it just in case the graph will not be downloaded

frmtc.text.insertstring(frmtc, sexform4,true)'the mediawiki URL is added here,in case the image is
frmtc.HyperLinkTarget = sexForm5 'not downloaded (then you can call it manually and insert it)
frmtc.HyperLinkURL = sexForm5

etc.goleft(1,false)
If len(sexform3)>0 then 'if there is more text, work with it
etc.gotoendofparagraph(false)
endif
Loop

createtextelement(neon,etc)
'etc.gotoendofparagraph(false)
'etc.Text.insertstring(etc, CHR$(13),false)

End Sub

sub embedlinkedGraphics(Optional neon)

dim oDP
dim s1 as String
dim s2 as string

s1 = "com.sun.star.drawing.GraphicObjectShape"
s2 = "com.sun.star.text.TextGraphicObject"
oDP = neon.getDrawPage()

For i=0 To oDP.getCount()-1
  oGraph = oDP.getByIndex(i)
  If oGraph.supportsService(s1) OR oGraph.supportsService(s2) Then
    If InStr(oGraph.GraphicURL, "vnd.sun") = 0 Then


If oGraph.supportsService(s1) Then
REM Convert a GraphicObjectShape.
oAnchor = oGraph.getAnchor()
oText = oAnchor.getText()
oGraph_2 = neon.createInstance("com.sun.star.graphic.GraphicObject")
oGraph_2.GraphicObjectFillBitmap = oGraph.GraphicObjectFillBitmap
oGraph_2.Size = oGraph.Size
oGraph_2.Position = oGraph.Position
oText.insertTextContent(oAnchor, oGraph_2, False)
oText.removeTextContent(oGraph)
EmbedLinkedGraphic = True

ElseIf oGraph.supportsService(s2) Then
REM Convert a TextGraphicObject.
Dim oBitmaps
Dim sNewURL$
Dim sName$

sName$ = oGraph.LinkDisplayName
oBitmaps = neon.createInstance( "com.sun.star.drawing.BitmapTable" )
oBitmaps.insertByName( sName, oGraph.GraphicURL )
sNewURL$ = oBitmaps.getByName( sName )
oGraph.GraphicURL = sNewURL
EndIf
    
	End If
  End If
Next

end sub

sub createNumbering(optional neon, Optional cvc,Optional ctc)

dim onumrules
dim sexform
dim sexform1

	oNumRules = neon.createInstance("com.sun.star.text.NumberingRules") 'create numbering rules
'	print "number"
	sexform=getparagrstr(ctc)
    ctc.string=""


    do While instr(sexForm,"&&&")<>0
    sexForm1=mid(sexForm,instr(sexForm,"&&&"))
    sexForm1=right(sexForm1,Len(sexForm1)-3)
    
    sexForm=left(sexForm,instr(sexForm,"&&&")-1)
    ctc.NumberingRules = oNumRules
    if Left(sexform,5)="#####" then
    ctc.NumberingLevel=4
    sexform=right(sexForm,Len(sexform)-5)
    elseif Left(sexform,4)="####" then
    ctc.NumberingLevel=3
    sexform=right(sexForm,Len(sexform)-4)
    elseif Left(sexform,3)="###" then
    ctc.NumberingLevel=2
    sexform=right(sexForm,Len(sexform)-3)
    elseif Left(sexform,2)="##" then
    ctc.NumberingLevel=1
    sexform=right(sexForm,Len(sexform)-2)
    else
    ctc.NumberingLevel=0
    sexform=right(sexForm,Len(sexform)-1)
    endif
    ctc.text.insertString(ctc,right(sexForm,len(sexform)),false)
	createTextElement( neon, cTC)
	ctc.gotoendofparagraph(false)
    ctc.text.insertString(ctc, CHR$(13),false)
    sexForm=sexform1
    If Len(sexForm1)<4 then
    sexForm=""
    exit do
    endif
    Loop 
    
    ctc.gotostartofparagraph(false)
    ctc.gotoendofparagraph(true)
    ctc.NumberingRules = NONE
    ctc.gotoendofparagraph(false)

end sub




sub createBullets(Optional neon, Optional cvc,Optional ctc)

dim onumrules

	oNumRules = neon.createInstance("com.sun.star.text.NumberingRules") 'create numbering rules
'	print "bullet"
	sexform=getparagrstr(ctc)
    ctc.string=""
  Do While Left(sexForm,1)= " " 'remove empty spaces left ....
    sexForm=Right(sexForm,Len(sexForm)-1)
  Loop 

oRule1 = oNumRules.getByIndex(0)
oRule2 = oNumRules.getByIndex(1)
oRule3 = oNumRules.getByIndex(2)
oRule4 = oNumRules.getByIndex(3)
oRule5 = oNumRules.getByIndex(4)

for i = 0 to UBOUND(oRule1)
   if oRule1(i).Name = "NumberingType" Then
      oRule1(i).Value = com.sun.star.style.NumberingType.CHAR_SPECIAL  
   End If
   if oRule2(i).Name = "NumberingType" Then
      oRule2(i).Value = com.sun.star.style.NumberingType.CHAR_SPECIAL 
   End If
   if oRule3(i).Name = "NumberingType" Then
      oRule3(i).Value = com.sun.star.style.NumberingType.CHAR_SPECIAL 
   End If
   if oRule4(i).Name = "NumberingType" Then
      oRule4(i).Value = com.sun.star.style.NumberingType.CHAR_SPECIAL 
   End If
   if oRule5(i).Name = "NumberingType" Then
      oRule5(i).Value = com.sun.star.style.NumberingType.CHAR_SPECIAL 
   End If
next i

oNumRules.replaceByIndex(0, oRule1)
oNumRules.replaceByIndex(1, oRule2)
oNumRules.replaceByIndex(2, oRule3)

	sexForm=Left(sexForm,Len(sexform)-3)
'print sexform
    ctc.NumberingRules = oNumRules
    if Left(sexform,5)="*****" then
    ctc.NumberingLevel=2
    sexform=right(sexForm,Len(sexform)-5)
    elseif Left(sexform,4)="****" then
    ctc.NumberingLevel=2
    sexform=right(sexForm,Len(sexform)-4)
    elseif Left(sexform,3)="***" then
    ctc.NumberingLevel=2
    sexform=right(sexForm,Len(sexform)-3)
    elseif Left(sexform,2)="**" then
    ctc.NumberingLevel=1
    sexform=right(sexForm,Len(sexform)-2)
    elseif Left(sexform,1)="*" then
    ctc.NumberingLevel=0
    sexform=right(sexForm,Len(sexform)-1)
    endif
    ctc.TExt.insertString(ctc,sexform,true)
	if instr(sexform,"File:")<>0 then creategraph(neon,cvc,ctc)
	createTextElement( neon, cTC)
'	createtextobject(getparagrstr(ctc),neon,cvc,ctc)
    ctc.gotostartofparagraph(false)
    ctc.gotoendofparagraph(false)
    ctc.TExt.insertString(ctc,CHR$(13),false)
    ctc.gotostartofparagraph(false)
    ctc.gotoendofparagraph(true)
    ctc.NumberingRules = NONE
    ctc.gotoendofparagraph(false)
    sexform=""

end sub




'the following subroutine is editing strings. It s finding out if there is a mathematical formula or 
'a reference, a subscript, a fontsize etc. Because this method is using a loop reading "<" in the string
'all relative code should begin with "<". This is why in the beginning of the main routine all relavent
'code is changed if needed (with myreplace), for example [[w: is changed to <§wl, which should mean hyperlinkwikipedia.
'I have created another subroutine for tables or other fields, because the treatment is not the same
'I use endnotes for references. Footnotes are not used yet, but I suppose there will be something for them too!

Sub createTextElement(Optional neon,Optional ctC)'Optional cVC,

dim i as Integer
dim j as Integer
dim k as Integer
dim sexForm0 as String
dim sexForm1 as String
dim sexForm2 as String
dim vInsertPoin
dim sform() as string
dim cvc 
dim ntc

REM FIND WHERE A SPECIFIC EXPRESSION STARTS (MATH OR SUPER AND SUBSCRIPT OR HYPERLINK ect.)
sexform=getparagrstr(ctc)

Do While InStr(sexForm, "<§") <>0 

REM SPOT AND TRANSLATE A FOOTNOTE REFERENCE IN OPEN OFFICE FORM	
		If InStr(sexForm, "<§fn")<>0 Then
		   createFootnote(ctc)
		EndIf


REM SPOT AND TRANSLATE A ENDNOTE REFERENCE IN OPEN OFFICE FORM	
		If InStr(sexForm, "<§rf")<>0 Then
		   createEndnote(neon,ctc)
		EndIf


REM SPOT AND TRANSLATE THE WIKIPEDIA HYPERLINK IN OPEN OFFICE FORM	
		If InStr(sexForm, "<§wl")<>0 Then
		   createWikipediaHyperlink(ctc)
		EndIf

REM SPOT AND TRANSLATE THE WIKIBOOKS HYPERLINK IN OPEN OFFICE FORM	
		If InStr(sexForm, "<§wb")<>0 Then
		   createWikibookHyperlink(ctc)
		EndIf

REM SPOT AND TRANSLATE GENERAN INTERNET HYPERLINK IN OPEN OFFICE FORM	
		If InStr(sexForm, "<§nl")<>0 Then
		   createInternetLink(ctc)
		EndIf

REM SPOT AND FORM THE WIKI BIG CHARACTERS	
		If InStr(sexForm, "<§bf")<>0 Then
		   createBigFont(ctc)
		EndIf

REM SPOT AND FORM THE WIKI BIG CHARACTERS	
		If InStr(sexForm, "<§bl")<>0 Then
		   createBold(ctc)
		EndIf

REM SPOT AND FORM THE WIKI BIG CHARACTERS	
		If InStr(sexForm, "<§it")<>0 Then
		   createItalic(ctc)
		EndIf

REM SPOT AND TRANSLATE THE SUBSCRIPT IN OPEN OFFICE FORM	
		If InStr(sexForm, "<§sb")<>0 Then
		   createSubscript(ctc)
		EndIf

REM SPOT AND TRANSLATE THE SUPERSCRIPT IN OPEN OFFICE FORM	
		If InStr(sexForm, "<§sp")<>0 Then
		   createSuperscript(ctc)
		EndIf
		
		'IN MANY CASES THE LOOP DOESNT WORK RIGHT, SO I PUT AN END TO IT!:
		i=i+1
		If i>42 Then
'		  vComp.Text.insertString(vInsertPoint, "!!! IF YOU SEE THIS MESSAGE, THEN YOU PROBABLY HAVE AN UNEXPECTED ELEMENT THAT BEGINS WITH < IN STRING: " & sexForm & " !!!",false)
'		  vComp.Text.insertString(vInsertPoint,  "	SEE THE INSTRUCTIONS, MAYBE YOU CAN ELIMINATE THIS BUG YOURSELF!",false)
'		vInsertPoint = vComp.Text.getEnd()
		Exit Do
		EndIf
		If befor=3 then
		Exit Do
		EndIf
sexform=getparagrstr(ctc)


Loop

k=0
Do While InStr(sexForm, "<§mt") <>0 
REM SPOT AND TRANSLATE THE FORMULA IN OPEN OFFICE FORM	
		sexForm0=cutFormula(cTC,k)
		k=k+1

		oObj = neon.CreateInstance("com.sun.star.text.TextEmbeddedObject")'CREATE IN THE TARGET DOC A FORMULA OBJECT
  		oObj.CLSID = "078B7ABA-54FC-457F-8551-6147e776a997"
  		oObj.AnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER'ANCHOR THE FORMULA AS A CHARACTER, YOU CAN FIND IT INSIDE A SENTENCE!
		cvc=neon.CurrentController.getViewCursor
		ntc=neon.Text.createtextcursor()
		ntc.gotorange(cvc,false)
		cvc.gotorange(ctc,false) 
		cvc.Text.insertTextContent(cvc , oObj, False)'AND THEN THE FORMULA BOX

Dim tbor
		If Len(sexform)<(len(sexform0)+15) then 'if the formula is not part of a paragraph, then put it in a box
		tbor = oObj.LeftBorder : tbor.OuterLineWidth = 40 : oObj.LeftBorder=tbor
		tbor = oObj.RightBorder : tbor.OuterLineWidth = 40 : oObj.RightBorder=tbor
		tbor = oObj.TopBorder : tbor.OuterLineWidth = 40 : oObj.TopBorder=tbor
		tbor = oObj.BottomBorder : tbor.OuterLineWidth = 40 : oObj.BottomBorder=tbor
		Endif
		
  		oObj.EmbeddedObject.Component.Formula = createFormula(sexForm0)
		sexform=getparagrstr(ctc)
		cvc.gotorange(ntc,false) 
Loop
		
End Sub

        	 		          

'this sub creates an Endnote
Sub createEndnote(Optional neon, Optional etc)' Optional evc,

Dim endnot 'endnote object
Dim sexForm0 As String 'auxiliary string
Dim sexForm4 As String 'auxiliary string
Dim sexForm5 As String 'auxiliary string
Dim l As Integer 'used to mark the end position of the reference
Dim f As Integer
Dim k As Integer
Dim u As Integer
Dim ftC 'cursor controller of the endnote

		 endnot=neon.createInstance("com.sun.star.text.Endnote")'create the endnote object
		 

		   sexform0=getparagrstr(etc)
		   f=instr(sexForm0,"<§rf")
		   etc.gotostartofparagraph(false)
		   etc.goright(f-1,false)
   		   neon.Text.insertTextContent(etc, endnot, false)
   		   ftC=endnot.getText().createTextCursor
		   ftC.gotoEnd(false)
   		   
   		   l= instr(mid(sexform0,f+4),">")
		   sexForm4=mid(sexform0,f+4,l)
		   
  		   k=inStr(sexForm0, "</ref")
   		   sexForm5=mid(sexForm0,f+l+4, k-f-l-4) 'the reference
		   ftC.getText().insertString(ftC , sexForm5, true)
		   createTExtElement(endnot,ftc)
		   If inStr(sexForm4, "name=" & CHR$(34)) Then
		   sexForm4=(Mid(sexForm4, inStr(sexForm4,"name=" & CHR$(34))+6,inStr(Mid(sexForm4, inStr(sexForm4,"name=" & CHR$(34))+7),CHR$(34))))
		   EndIf
		   
   		   etc.goright(k-f+6,true)
   		   etc.string=""
   		   etc.goleft(1,false) : etc.goright(1,false)
   		   
	       etc.getText().insertString(etc,"(" & sexForm4 & ")",true)
	       etc.CharPosture=com.sun.star.awt.FontSlant.ITALIC
	       etc.CharEscapement=25
	       etc.CharEscapementHeight=65
	       etc.goright(Len(sexForm4)+2,false)
	       etc.goleft(1,false) : etc.goright(1,false)
	       etc.CharPosture=com.sun.star.awt.FontSlant.NONE
	       etc.CharEscapement=0
	       etc.CharEscapementHeight=100

End Sub



        	 		          


Sub createFootnote(Optional neon,Optional etc)' Optional evc,
Dim footnot 'endnote object
Dim sexForm0 As String 'auxiliary string
Dim sexForm4 As String 'auxiliary string
Dim sexForm5 As String 'auxiliary string
Dim l As Integer 'used to mark the end position of the reference
Dim f As Integer
Dim k As Integer
Dim u As Integer
Dim ftC 'cursor controller of the endnote

		 footnot=neon.createInstance("com.sun.star.text.Footnote")'create the endnote object
		 

		   sexform0=getparagrstr(etc)
		   f=instr(sexForm0,"<§rf")
		   etc.gotostartofparagraph(false)
		   etc.goright(f-1,false)
   		   neon.Text.insertTextContent(etc, footnot, false)
   		   ftC=footnot.getText().createTextCursor
		   ftC.gotoEnd(false)
   		   
   		   l= instr(mid(sexform0,f+4),">")
		   sexForm4=mid(sexform0,f+4,l)
		   
  		   k=inStr(sexForm0, "</ref")
   		   sexForm5=mid(sexForm0,f+l+4, k-f-l-4) 'the reference
		   ftC.getText().insertString(ftC , sexForm5, true)
		   createTExtElement(footnot,ftc)
		   If inStr(sexForm4, "name=" & CHR$(34)) Then
		   sexForm4=(Mid(sexForm4, inStr(sexForm4,"name=" & CHR$(34))+6,inStr(Mid(sexForm4, inStr(sexForm4,"name=" & CHR$(34))+7),CHR$(34))))
		   EndIf
		   
   		   etc.goright(k-f+6,true)
   		   etc.string=""
   		   etc.goleft(1,false) : kvc.goright(1,false)
   		   
	       etc.getText().insertString(etc,"(" & sexForm4 & ")",true)
	       etc.CharPosture=com.sun.star.awt.FontSlant.ITALIC
	       etc.CharEscapement=25
	       etc.CharEscapementHeight=65
	       etc.goright(Len(sexForm4)+2,false)
	       etc.goleft(1,false) : etc.goright(1,false)
	       etc.CharPosture=com.sun.star.awt.FontSlant.NONE
	       etc.CharEscapement=0
	       etc.CharEscapementHeight=100

End Sub

        	 		          


Sub createWikipediaHyperlink(Optional etc)' Optional evc,

Dim wikiAdress As String
Dim sexForm0 As String
Dim sexForm1 As String
Dim l As Integer
Dim k As Integer
Dim u As Integer
k=0
l=0
u=0
sexform0=getparagrstr(etc)

		     l= InStr(sexForm0, "<§wl")
		     sexform1=mid(sexForm0,l+4)
		     k=inStr(sexform1,"|")-1
			 u=inStr(sexform1,"]]")
		         wikiAdress= "https://de.wikipedia.org/wiki/"  & Left(sexForm1,k)
	      etC.goToStartofParagraph(false)
		  etC.goright(l-1,false)
		  etC.goright(k+5,true)
		  etC.String= ""
		  etC.goright(u-k-2,true)
		  etC.HyperLinkTarget = wikiAdress
		  etC.HyperLinkURL = wikiAdress
		  etC.goleft(1,false) : etC.goright(1,false)
		  etC.goright(2,true)
		  etC.String= ""
		  etC.goleft(1,false) : etC.goright(1,false)
		  		  

End Sub


        	 		          


Sub createWikibookHyperlink(Optional etc)'Optional evc,

'print "wiki"
Dim wikiAdress As String
Dim sexForm0 As String
Dim sexForm1 As String
Dim l As Integer
Dim k As Integer
Dim u As Integer
k=0
l=0
u=0
sexform0=getparagrstr(etc)
		     l= InStr(sexForm0, "<§wb")
		     sexform1=mid(sexForm0,l+4)
		     k=inStr(sexform1,"|")-1
			 u=inStr(sexform1,"]]")
		         wikiAdress= "https://de.wikibooks.org/wiki/"  & Left(sexForm1,k)
	      etC.goToStartofParagraph(false)
'	      evc.gotorange(etc,false)
		  etC.goright(l-1,false)
		  etC.goright(k+5,true)
'		  Print evc.string
		  etC.String= ""
		  etC.goright(u-k-2,true)
		  etC.HyperLinkTarget = wikiAdress
		  etC.HyperLinkURL = wikiAdress
		  etC.goleft(1,false) : etC.goright(1,false)
		  etC.goright(2,true)
		  etC.String= ""
		  etC.goleft(1,false) : etC.goright(1,false)
		  
		  
End Sub



        	 		          


Sub createInternetlink(Optional etc)'Optional evc,
Dim wikiAdress As String
Dim sexForm0 As String
Dim sexForm1 As String
Dim l As Integer
Dim k As Integer
Dim u As Integer
k=0
l=0
u=0
sexform0=getparagrstr(etc)
		     l= InStr(sexForm0, "<§nl")
		     sexform1=mid(sexForm0,l+4)
		     If instr(sexform1,"|")=0 then
		     k=inStr(sexform1," ")
		     else
		     k=inStr(sexform1,"|")
			 endif
			 u=inStr(sexform1,"]")
		         wikiAdress=    Left(sexForm1,k-1)
	      etC.goToStartofParagraph(false)
		  etc.goright(l-1,false)
		  etc.goright(k+4,true)
		  etc.String= ""
		  etc.goright(u-k-1,true)
		  etc.HyperLinkTarget = wikiAdress
		  etc.HyperLinkURL = wikiAdress
		  etc.goleft(1,false) : etc.goright(1,false)
		  etc.goright(1,true)
		  etc.String= ""
		  

End Sub






Sub createBigFont(Optional etc)'Optional evc,

Dim sexForm0 As String
Dim l As Integer
Dim k As Integer
k=0
l=0
sexform0=getparagrstr(etc)
		     k=inStr(sexForm0,"<§bf>")
		     l= InStr(mid(sexForm0,inStr(sexForm0,"<§bf>")+5),"§&")
	      etC.goToStartofParagraph(false)
		  etc.goright(k-1,false)
		  etc.goright(5,true)
		  etc.String= ""
		  etc.goright(l-1,true)
		  k=etc.CharHeight
		  etc.CharHeight =15
		  etc.goleft(1,false) : etc.goright(1,false)
		  etc.goright(2,true)
		  etc.String= ""
		  etc.CharHeight =k
		  etc.goleft(1,false) : etc.goright(1,false)

End Sub






Sub createBold(Optional etc)'Optional evc,

Dim wikiAdress As String
Dim sexForm0 As String
Dim l As Integer
Dim k As Integer
k=0
l=0
sexform0=getparagrstr(etc)
		     k=inStr(sexForm0,"<§bl>")
		     l= InStr(mid(sexForm0,inStr(sexForm0,"<§bl>")+5),"<§bl>")
	      etC.goToStartofParagraph(false)
		  etc.goright(k-1,false)
		  etc.goright(5,true)
		  etc.String= ""
		  etc.goright(l-1,true)
		  etc.CharWeight = com.sun.star.awt.FontWeight.BOLD
		  etc.goright(1,false)
		  etc.goleft(1,false)
		  etc.goright(5,true)
		  etc.String= ""
		  etc.CharWeight = com.sun.star.awt.FontWeight.NORMAL
		  etc.goright(0,false)

End Sub






Sub createItalic(Optional etc)'Optional evc,

Dim sexForm0 As String
Dim l As Integer
Dim k As Integer

k=0
l=0
sexform0=getparagrstr(etc)
		     k=inStr(sexForm0,"<§it>")
		     l= InStr(mid(sexForm0,inStr(sexForm0,"<§it>")+5),"<§it>")
	      etC.goToStartofParagraph(false)
		  etc.goright(k-1,false)
		  etc.goright(5,true)
		  etc.String= ""
		  etc.goright(l-1,true)
	      etc.CharPosture=com.sun.star.awt.FontSlant.ITALIC
		  etc.goleft(1,false) : etc.goright(1,false)
		  etc.goright(5,true)
		  etc.String= ""
	      etc.CharPosture=com.sun.star.awt.FontSlant.NONE
		  etc.goright(0,false)

End Sub




Sub createSubscript (Optional etc)'Optional evc,

Dim sexForm0 As String
Dim l As Integer
Dim k As Integer

k=0
l=0
sexform0=getparagrstr(etc)
		     k=inStr(sexForm0,"<§sb>")
		     l= InStr(mid(sexForm0,inStr(sexForm0,"<§sb>")+5),"§!")
	      etC.goToStartofParagraph(false)
		  etc.goright(k-1,false)
		  etc.goright(5,true)
		  etc.String= ""
		  etc.goright(l-1,true)
		  etc.CharEscapement =-17
		  etc.CharEscapementHeight =76
		  etc.goleft(1,false) : etc.goright(1,false)
		  etc.goright(2,true)
		  etc.String= ""
		  etc.CharEscapement =0
		  etc.CharEscapementHeight =100
		  etc.goright(0,false)

End Sub





Sub createSuperscript(Optional etc)'Optional evc,


Dim sexForm0 As String
Dim l As Integer
Dim k As Integer

k=0
l=0
sexform0=getparagrstr(etc)
		     k=inStr(sexForm0,"<§sp>")
		     l= InStr(mid(sexForm0,inStr(sexForm0,"<§sp>")+5),"§!")
	      etC.goToStartofParagraph(false)
		  etc.goright(k-1,false)
		  etc.goright(5,true)
		  etc.String= ""
		  etc.goright(l-1,true)
		  etc.CharEscapement =17
		  etc.CharEscapementHeight =76
		  etc.goleft(1,false) : etc.goright(1,false)
		  etc.goright(2,true)
		  etc.String= ""
		  etc.CharEscapement =0
		  etc.CharEscapementHeight =100
		  etc.goright(0,false)

End Sub







function cutFormula(Optional etc, optional k as integer) as String

dim sexForm0 as String
dim s1 as String
dim i as Integer
dim j as Integer

		sexForm0=getparagrstr(etc)
		j=instr(sexform0,"<§mt")
        sexForm0=Right(sexForm0,Len(sexForm0)-j-5) 'linken <§mth> Teil weg
     	 i=inStr(sexForm0,"</math>")
     	 etc.gotostartofparagraph(false)
     	 etc.goright(j-1+k,false)
     	 etc.goright(i+12,true)
     	 etc.string=""
     	 etc.goleft(0,false)
         sexForm0=Left(sexForm0,i-1) 'rechten </math> Teil weg
         cutformula=sexform0

End function		
		





Function createFormula(Optional sexForm7 as String)    	as STring

Dim sexForm as String
Dim s1 as String
Dim i as Integer

    	i=0
		sexForm=sexForm7
'print sexform		
		do While instr(sexform, "sqrt[")
		s1=mid(sexform, instr(sexform,"sqrt")+5)
		sexform= left(sexform, instr(sexform,"sqrt")-1) & "nroot" & "{" & Left(s1,instr(s1,"]")-1) & "}" & mid(s1,instr(s1,"]")+1)
		loop
        
     	While  instr(sexform,"\")
     	i= instr(sexform,"\")
         s1=Right(Left(sexForm,i+3),4)

rem FIND AND CREATE MATRIX
         If s1="\bmx" Then
         myMatrix(sexForm,i)

REM FIND AND CREATE UNDERBRACE  (WORKS ALSO FOR UNDERBRACE IN UNDERBRACE)  	 
         ElseIf s1="\und" Then
         myUnderbrace(sexForm, i)

REM FIND AND CREATE OVERBRACE  (WORKS ALSO FOR OVERBRACE IN OVERBRACE)  	       
         ElseIf s1="\ove" Then
         myOverbrace(sexForm, i)   

REM FIND AND CREATE FRACTION
         ElseIf s1="\fra" Then
         sexform=myFraction(sexForm,i)
         
REM FIND AND CREATE LIMITS FOR INTEGRALS SUMS AND SO ON
         ElseIf s1="\lim" or s1="\nol" Then
         sexform=myLimits(sexForm,i)
         
REM FIND AND CREATE NROOT already made at the beginning of this subroutine!!!!
'         ElseIf s1="\sqr"  Then
'         print sexform
'         sexform=myRoots(sexForm,i)
'         print sexform
         
         Else
         sexform=Left(sexform,i-1) & "WARNING: " & s1 & " has not been taken into consider!" & right(sexform,Len(sexform)-i-4)
 		 EndIf
 	  Wend	 
 	  
 		 createFormula=sexForm

End function







sub myMatrix(sexForm as String, i as Integer)

Dim sexForm3 as String
Dim sexForm4 as String
Dim s2 as String
dim k as Integer
k=0

 		       sexForm3= Left(sexForm,i)  & "matrix{"
 		       sexForm= sexForm3 &  Right(sexForm,Len(sexForm)-i-4)
     		While  k < Len(sexForm)
        	s2 = Left(sexForm,i+k+2)
       	 	  If Right(s2,1)="&" Then
       	 	  sexForm3=Left(sexForm,i+k)
       	 	  sexForm=sexForm3 & " # " & Right(sexForm, Len(sexForm)-k-i-2)
       	 	  EndIf
        	  If Right(s2,2)="\\" Then
       	 	  sexForm3=Left(sexForm,i+k)
       	 	  sexForm=sexForm3 & " ## " & Right(sexForm, Len(sexForm)-k-i-2)
       	 	  EndIf
       	 	  If Right(s2,4)="}emx" Then
       	 	  sexForm4=Left(sexForm,i+k-1)
       	 	  sexForm=sexForm4 & Right(sexForm, Len(sexForm)-k-i-2)
       	 	  k=Len(sexForm)+1
       	 	  EndIf
       	 	  k=k+1
       	 	Wend
       	 	k=0
End Sub






REM FIND AND CREATE UNDERBRACE  (WORKS ALSO FOR UNDERBRACE IN UNDERBRACE)  	 
Sub myUnderbrace(Optional sexForm as String, Optional i as Integer)

Dim sexForm3 as String
Dim sexForm4 as String
Dim s1 as String
Dim s2 as String
Dim k as Integer
Dim m as Integer

          k=i+4
     		Do While  k < Len(sexForm)
        	s2 = Left(sexForm,k+4)
       	 	s1= Right(s2,5)
 		       If s1="}}_{{" Then
 		       sexForm3= Left(sexForm,i)
 		       sexForm= sexForm3 & "{" & Right(sexForm,Len(sexForm)-i-11) '\underbrace weg
 		       k=k-9
 		       m=k
 		       Do While  m < Len(sexForm)
 		         s2 = Left(sexForm,m+1)
       	 		 s1= Right(s2,1)
 		         If s1="}" Then
 		         s2 = Left(sexForm,m+2)
       	 		 s1= Right(s2,2)
       	 		 If s1="}}" then
 		         sexForm3= Left(sexForm,k)
 		         sexForm4= Right(sexForm,Len(sexForm)-k-1)
 		         sexForm= sexForm3 & " underbrace " & Left(sexForm4,m-k)  & "}" & Right(sexForm4,Len(sexForm4)-m+k)
 		         m= Len(sexForm)
 		         k= Len(sexForm) 		        
 		         EndIf
 		         EndIf
 		         m=m+1
 		       Loop  
         	   EndIf
         	   k=k+1
         	 Loop
End Sub






REM FIND AND CREATE OVERBRACE  (WORKS ALSO FOR OVERBRACE IN OVERBRACE)  	 
Sub      myOverbrace(Optional sexForm as String, Optional i as Integer)

Dim sexForm3 as String
Dim sexForm4 as String
Dim s1 as String
Dim s2 as String
Dim k as Integer
Dim m as Integer

          k=i+4
     		Do While  k < Len(sexForm)
        	s2 = Left(sexForm,k+4)
       	 	s1= Right(s2,5)
 		       If s1="}}^{{" Then
 		       sexForm3= Left(sexForm,i)
 		       sexForm= sexForm3 & "{" & Right(sexForm,Len(sexForm)-i-10) '\overbrace weg
 		       k=k-8
 		       m=k
 		       Do While  m < Len(sexForm)
       	 		 s1= Right(Left(sexForm,m+1),1)
 		         If s1="}" Then
       	 		 s1= Right( Left(sexForm,m+2),2)
       	 		 If s1="}}" then
 		         sexForm3= Left(sexForm,k)
 		         sexForm4= Right(sexForm,Len(sexForm)-k-1)
 		         sexForm= sexForm3 & " overbrace " & Left(sexForm4,m-k)  & "}" & Right(sexForm4,Len(sexForm4)-m+k)
 		         m= Len(sexForm)
 		         k= Len(sexForm) 		        
 		         EndIf
 		         EndIf
 		         m=m+1
 		       Loop  
         	   EndIf
         	   k=k+1
         	 Loop
End Sub           





function myFraction(Optional sexForm0 as String,Optional l as Integer) as string

Dim sexForm as String
Dim sexForm3 as String
Dim s1 as String
Dim i as Integer
Dim j as Integer
Dim k as Integer
Dim m as Integer
Dim klac as Integer

			sexForm=sexForm0
			i=l
            sexForm3=Left(sexForm,i-1)'save left side of der Formula
            sexForm= Right(sexForm,Len(sexForm)-i-4) 'right side without \frac
            k=instr(sexform,"{")'begin looking for paranthesis in sexform
            klac=1
	Do While k< Len(sexForm)                                              
      s1= Right(Left(sexForm,k+1),1)
      If s1="{" then
        klac=klac+1
      endif  
      if s1="}" then
        klac=klac-1
      endif  
      If  klac=0 then
       	j=k
        exit do
      endif   
	  k=k+1	 
	Loop 
	k=k+instr(mid(sexform,k+1),"{")-1
	Do While k< Len(sexForm)                                              
      s1= Right(Left(sexForm,k+1),1)
      If s1="{" then
        klac=klac+1
      elseif s1="}" then
        klac=klac-1
      endif  
      If  klac=0 then
       	m=k
        exit do
      endif   
	  k=k+1	 
	Loop 
	sexform0=sexForm3 & "{" & Left(sexform,j+1) & " over " & mid(sexform,j+2,m-j-1) & "}" & right(sexform,len(sexform)-m)
	myfraction=sexform0
      	 	   	 
End function     




function myLimits(Optional sexForm as String, Optional i as Integer) as string

dim sexform1 as string
dim sexform2 as string
dim sexform3 as string
dim k%

sexform1=left(sexform,i-1)
If instr(sexform,"\lim")=0 then 
sexform3=ltrim(right(sexform,len(sexform)-instr(sexform,"\nolim")-8))
elseif instr(sexform,"\nolim")=0 then
sexform3=ltrim(right(sexform,len(sexform)-instr(sexform,"\lim")-6))
elseif instr(sexform,"\nolim")>instr(sexform,"\lim") then
sexform3=ltrim(right(sexform,len(sexform)-instr(sexform,"\lim")-6))
else
sexform3=ltrim(right(sexform,len(sexform)-instr(sexform,"\nolim")-8))
endif

If left(sexform3,1)="_" then
  sexform3=ltrim(right(sexform3,len(sexform3)-1))
  if left(sexform3,1)="{" then
    sexform2=left(sexform3,jumpParentPairs(sexform3,"{","}"))
    sexform3=ltrim(right(sexform3,len(sexform3)-len(sexform2)))
    if left(sexform3,1)="^" then
      sexform2=" from " & sexform2 & " to " & right(sexform3,len(sexform3)-1)
    else   
      sexform2=" from " & sexform2 & " " & sexform3
    endif
  else
    if instr(sexform3,"^")=0 or instr(sexform3,"^")>instr(sexform3," ") then 
    sexform2= " from " & mid(sexform3,2)
    else
    sexform2= " from " & mid(sexform3,2,1) & " to " & right(sexform3,len(sexform3)-3) 
    endif
  endif
else  
sexform2= " to " & right(sexform3,len(sexform3)-1) 
endif

myLimits=sexform1+sexform2

end function



function myRoots(Optional sexForm as String, Optional i as Integer) as string

dim sexform1

print "sqr1!  " & sexform
if instr(sexform,"sqrt[")=0 then 
myroots=left(sexform,i-1) & right(sexform, len(sexform)-i-5)
else
sexform1=ltrim(right(sexform, len(sexform)-i-5))
myroots=left(sexform,i-1) & " nroot{" & Left(sexform1,jumpParentPairs(sexform,"[","]") & "}" & right(sexform1, len(sexform1)-len(Left(sexform1,jumpParentPairs(sexform,"[","]")))
endif
print "sqr2!  " & sexform

end function




function jumpParentPairs(Optional sexForm as String, Optional s1 as string, Optional s2 as string) as integer

dim i as integer
dim count as integer
count=0

jumpParentPairs=FALSE

for i=1 to Len(sexform)
  if mid(sexform,i,1) = s1 then count=count+1
  if mid(sexform,i,1) = s2 then count=count-1
  if count=0 then
    jumpParentPairs=i
    exit function
  endif
next    

end function


sub	createTextObject(optional sexform, optional neon,optional cvc,optional ctc)

 	If Left(sexForm,1)="#" Then 
	createNumbering(neon , cVC,ctc)	
	EndIF
	
 	If Left(sexForm,1)="*" Then 
	createBullets(neon, cVC,ctc)	
	EndIF
	
	If inStr(sexForm, "File:") then
	createGraph(neon,cVC,cTC)
	EndIf
	
	If inStr(sexForm, "<Gallery>") then
	selectParagraph(cvc,ctc)
	ctc.string=""
	ctc.gotonextparagraph(false)
	do while inStr(sexForm, "</Gallery>")=0
	createGraph(neon,cVC,cTC)
	ctc.gotonextparagraph(false)
	sexform= getparagrstr(ctc)
	Loop 
	ctc.string=""
	EndIf

REM FIND OUT IF YOU HAVE A TABLE AND THEN CREATE THE TABLE WITH ITS CELL-CONTENTS. 
REM A TABLE BEGINS ALWAYS AT STARTOFLINE
  If inStr(sexForm,"{|" ) <>0 Then
    createTable(neon , cVC, cTC)  
    sexform=""
  EndIf
  
 end sub




Sub Wiki2OpOffWr(optional neon, optional cVC,optional cTC,optional tits as string,optional titplus as integer)


	Dim oObj
	Dim oInsertPoint 'Where the outcome will be inserted
	Dim vInsertPoint 'Where the outcome will be inserted
	Dim vInsertPoint2 'Where the outcome will be inserted
	Dim oVC As Object  'ViewCursor
'	Dim cVC As Object  'ViewCursor
	Dim oTC As Object  'TextCursor
	Dim newText   'wichtig! hier wird der neue Text gespeichert
	Dim wikiAd 
	Dim sexFormU As String  'Hier kommt der Titel der Seite
	Dim sexForm As String  'hier kommen die jeweiligen Formelnabschnitte
	Dim oMasters
	Dim oField
	Dim y As Integer	'entscheidet ob # oder * addiert wird
	Dim oPar
	Dim oSec
	Dim osecEnum
	Dim oEnum
	Dim tit0 As Integer
	Dim tit1 As Integer
	Dim tit2 As Integer
	Dim tit3 As Integer
	Dim tit4 As Integer
	dim oCurs
	dim oIndex
	dim noArgs()
	
sexForm1=""
tit1=0 : tit2=0 : tit3=0 : tit4=0 

     Dim   oDescriptor
    oDescriptor = neon.createReplaceDescriptor()

 myReplace(oDescriptor, neon,  "datei:",  "file:")
 myReplace(oDescriptor, neon,  "image:",  "file:")
 myReplace(oDescriptor, neon,  "[File:",  "!File:")
 myReplace(oDescriptor, neon,  "|mini",  "")
 myReplace(oDescriptor, neon,  "|upright=",  "|!?&upright=")
 myReplace(oDescriptor, neon,  "|thumb",  "")
 myReplace(oDescriptor, neon,  "|left",  "")
 myReplace(oDescriptor, neon,  "|links",  "")
 myReplace(oDescriptor, neon,  "|right",  "")
 myReplace(oDescriptor, neon,  "|rechts",  "")

 myReplace(oDescriptor, neon,  "[[w:",  "<§wl")'wl for wikilink
 myReplace(oDescriptor, neon,  "[[",  "<§wb")'wb for wikibook
 myReplace(oDescriptor, neon,  "[htt",  "<§nlhtt")'nl for netlink
 myReplace(oDescriptor, neon,  "<ref",  "<§rf")'rf for reference

 myReplace(oDescriptor, neon,  "<sup",  "<§sp")'sp for superscript
 myReplace(oDescriptor, neon,  "<sub",  "<§sb")'sb for subscript
 myReplace(oDescriptor, neon,  "<big",  "<§bf")'bf for bigfont
 myReplace(oDescriptor, neon,  "<mat",  "<§mt")'mt for math
 myReplace(oDescriptor, neon,  "'''",  "<§bl>")'bl for Bold
 myReplace(oDescriptor, neon,   "''",  "<§it>")'it for Italics
 myReplace(oDescriptor, neon,  "</sub>",  "§!")
 myReplace(oDescriptor, neon,  "</sup>",  "§!")
 myReplace(oDescriptor, neon,  "</big>",  "§&")
 
 myReplace(oDescriptor, neon,  "__FORCETOC__",  " ")
 myReplace(oDescriptor, neon,  "/<br />",  CHR$(13))
 myReplace(oDescriptor, neon,  "&nbsp;",  " ")
 myReplace(oDescriptor, neon,  "\\ ",  "\\\ ")
 myReplace(oDescriptor, neon,   "\ ",  " ")

 myReplace(oDescriptor, neon,  "\begin{matrix}",  "\bmx")
 myReplace(oDescriptor, neon,  "\end{matrix}",  "}emx")
 myReplace(oDescriptor, neon,  "\div",  " div ")
 myReplace(oDescriptor, neon,  "\dotsm",  " dotsaxis ")
 myReplace(oDescriptor, neon,  "\dotsc",  " dotslow ")
 myReplace(oDescriptor, neon,  "\dotsb",  " dotsaxis ")
 myReplace(oDescriptor, neon,  "\cdot",  " cdot ")
 myReplace(oDescriptor, neon,   "\dot",   " dot ")
 myReplace(oDescriptor, neon,  "\sum",  " sum ")
 myReplace(oDescriptor, neon,  "\int",  " int ")
 myReplace(oDescriptor, neon,  "\iint",  " iint ")
 myReplace(oDescriptor, neon,  "\iiint",  "iiint")
 myReplace(oDescriptor, neon,  "\oint",  "lint")
 myReplace(oDescriptor, neon,  "\sqrt",  "sqrt")
 myReplace(oDescriptor, neon,  "\Leftrightarrow",  " dlrarrow ")
 myReplace(oDescriptor, neon,  "\boldsymbol",  " ")
 myReplace(oDescriptor, neon,  "\bold",  " ")
 myReplace(oDescriptor, neon,  "\mathrm",  " ")
 myReplace(oDescriptor, neon,  "\,",  CHR$(34) & " "  & CHR$(34))

'Greek alphabet in Math 
 myReplace(oDescriptor, neon,  "\alpha"	,  "%alpha")
 myReplace(oDescriptor, neon,  "\beta"	,  "β")
 myReplace(oDescriptor, neon,  "\gamma"	,  "γ")
 myReplace(oDescriptor, neon,  "\delta"	,  "δ")
 myReplace(oDescriptor, neon,  "\epsilon",  "ε")
 myReplace(oDescriptor, neon,  "\rho"	,  "ρ")
 myReplace(oDescriptor, neon,  "\omega"	,  "ω")
 myReplace(oDescriptor, neon,  "\pi"	,  "π")
 myReplace(oDescriptor, neon,  "\phi"	,  "φ")
 myReplace(oDescriptor, neon,  "\theta"	,  "θ")
 

	selectParagraph(cvc,  ctc)
    sexForm = cVC.String 'nimmt den selected Text
    

    Do 

	selectParagraph(cvc,  ctc)
    sexForm = cVC.String 'nimmt den selected Text

 	If instr(sexform," style=")<>0 then
 	sexFormU=Right(sexform, Len(sexform)-instr(sexform," style=")-10)
 	sexFormU=Right(sexform, Len(sexform)-instr(sexform,CHR$(34))-1)
 	sexForm=Left(sexform, instr(sexform," style=")-1) & sexFormU
	selectParagraph(cvc,  ctc)
    cVC.String=sexform 'nimmt den selected Text
 	EndIF
 	
 	
 	If Left(sexForm,2)="==" Then 
	createTOC( cVC,tits,tit1,tit2,tit3,tit4,titplus)
'	Print "1"	
	EndIF

	createTextObject(sexform, neon,cvc,ctc)

REM FIND OUT IF YOU HAVE  SIMPLE TEXT OR A TEXT-ELEMENT THAT BEGINS WITH <, 
REM LIKE, FORMULA,  AND THEN INSERT THE SIMPLE TEXT OR THIS ELEMENT

createTextElement(neon,ctC)
		

y=y+1
If y>1520 Then 
Print("Error2!")
exit Sub
EndIf
  
     Loop  While ctC.gotonextparagraph(false)  'so lang oVC immer noch nach unten gehen kann
				'wird der Text bearbeitet
      

' myReplace(oDescriptor, neon,  "|",  "")


End Sub

Wie man das Programm in Macros installiert Bearbeiten

Man wählt von Menu in LibreOfficeWriter Tools → macros → organise macros → LibreOfficeBasic

Ein neues Fenster kommt vor.

Wähle "Organizer" (unten links) → neues Fenster

und dann Libraries (Oben). Wähle hier new → Box um Name zu geben. Gib einen Name deine Wahl (z.B. MyWiki) und OK

Im Organizer Fenster goto Modules, klicke neu, gib einen Name (z.B. MyWikiTOC), klick OK, vom Unterfensterlinks wähle deine neue Module (MyWikiTOC) und klick EDIT!

Ein neues Fenster kommt vor. KopiePaste das Programm vom vorherigen Abschnitt hier und speichere es.

Fertig!

Wie man das Programm benutzt Bearbeiten

Ziel ist, dass es automatisch wird, wie bei wikibooks Buch erstellen. Bis jetzt, muss man ein Dokument mit den Kapiteln erstellen (gewöhnlich hat jedes Buch ein Inhaltverzeichnis) und dann die Macro aktivieren. Dazu wird nach dem Pfad gefragt, wo Dokumente aus dem Browser automatisch gespeichert werden. Der Browser soll also so eingestellt sein, dass Dokumente automatisch in einem Dir gespeichert werden. Außerdem muss man vorher die Einstellungen von gedit oder das entsprechende Programm (das txt Dokumente öffnet) so einrichten, dass es keine Zeilen ohne (newline) entstehen und auch das Programm, das die MD5 Kodierung erzeugt in OpenOffice installieren. Der Rest geht automatisch (außer wenn bei einem Kapitel weitergeleitet wird).

Programm zum Wikidownload Bearbeiten

REM  *****  BASIC  *****
Sub Main
createBookFromTOCSite
End Sub


'oText.insertControlCharacter(oViewCursor,_com.sun.star.text.ControlCharacter.LINE_BREAK, false)


'!!!! REMARK !!!!
'I created some procedures when I still was inexperienced, so some of them are rather
'primitiv, but they are functioning, so,because of the time needed, I left them like 
'this. If you have fun with it, you are welcome to improve them

sub createBookFromTOCSite

dim tocDoc
dim tocVC
dim tocTC

'dim oodu

dim neon
dim mycunt
dim myctc

dim adressDoc
dim oCuad

dim titstring as string
dim Filenamen as string
dim savedir as string
dim titplus as integer
dim tits1 as integer
dim tits2 as integer
dim v as integer

dim noArgs()
v=0
titplus=1
    savedir = InputBox("give the path where your browser saves files","see your browser and adjust its tools","file:///home/yomomo/Downloads/wiki⁩3",1440 *2 , 1440 * 4 )


	tocDoc=thisComponent
    tocVC = tocDoc.CurrentController.getViewCursor 'und erzeugt einen ViewCursor
    tocTC = tocDoc.Text.CreateTextCursor 'der TextCursor kommtamAnfangdesTextes
    tocTC.goToEnd(false)
    tocTC.goToStart(false)
    tocVC.gotoRange(tocTC,false) 'a text cursor can't go to the end of a line
   		   If NOT tocVC.isAtStartOfLine() Then
  		      tocVC.gotoStartOfLine(false) 
   		   EndIf
    tocVC.gotoEndOfLine(true)  'so we have to use the view cursor.
    titstring = tocVC.String 'nimmt den selected Text

neon = StarDesktop.LoadComponentFromUrl("private:factory/swriter", "_blank", 0, noArgs())
    mycunt = neon.CurrentController.getViewCursor 'und erzeugt einen ViewCursor
    myntc = neon.getText().createTextCursor()

adressDoc = StarDesktop.LoadComponentFromUrl("private:factory/swriter", "_blank", 0, noArgs())
    oCuad = adressDoc.CurrentController.getViewCursor 'und erzeugt einen ViewCursor


    Do While tocVC.goDown(1,true)  'so lang oVC immer noch nach unten gehen kann
				'wird der Text bearbeitet
 	tocVC.goUp(1,True)	'man muss aber doch am Anfang anfangen
  


    If Left(titstring,1) ="*" Then
'code to change wiki hyperlink in hyperlink and chapter title
'https://de.wikibooks.org/w/index.php?title=	
		   Do While  inStr(titstring,"]]")=0
		   		If inStr(titstring,"]]")<>0 Then
		   		  Exit Do
		   		EndIf  
		        skipLine(tocVC,tocTC)			
 		    	titstring =titstring + tocVC.String 'read the marked text
 		   Loop 
		  'Print titstring
		  If inStr(titstring,"|") = 0 then
		  Filenamen=Mid(titstring,inStr(titstring,"[[")+2,inStr(titstring,"]]")-4)
		  else
		  Filenamen=Mid(titstring,inStr(titstring,"[[")+2,inStr(titstring,"|")-4)
		  ENDIf
		  'Print Filenamen
		  wikiAdress= "https://de.wikibooks.org/w/index.php?title="  & Filenamen &"&action=raw"
		  oCuad.Text.insertString(oCuad,wikiadress,true)
		  oCuad.HyperLinkTarget = wikiAdress
		  oCuad.HyperLinkURL = wikiAdress

	titstring= Mid(titstring, k+1,u-k-1) 		    
'    titstring = tit0 & "." & tit1 & "." & tit2 & "." & titstring
    mycunt.getText().insertString(mycunt,titstring,true)
    mycunt.getText().insertString(mycunt,CHR$(13),false)
   	callChapterFromInternet(adressDoc,mycunt, savedir,Filenamen,v)
   	v=v+1
    EndIf

		
	skipLine(tocVC,tocTC)
	titstring = tocVC.String 'read the marked text	

  
     Loop  

'until hier the whole book is downloaded but with minimal processing
'we must go again to the beginning of the whole text and process it

end Sub



sub callChapterFromInternet(Optional addoc,Optional rtc, Optional savedir as string, Optional Fname as string, Optional k as Integer)

dim document   as object
dim dispatcher as object
dim n as Integer
dim m as Integer
dim i as Integer


document   = addoc.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

dispatcher.executeDispatch(document, ".uno:OpenHyperlinkOnCursor", "", 0, Array())
'Print("hier")
i=0
m=0
'file1= "file:///home/georg/Λήψεις/index.php" 
'wait(2000)

Do While instr(Fname, "/")<>0 
Fname=mid(Fname, instr(Fname, "/")+2)
Loop
Do While instr(Fname, ":")<>0 
Fname=mid(Fname, instr(Fname, ":")+2)
'Fname=mid(Fname, instr(Fname, "/")+2)
Loop
'Print fname
wait(4000)
'Print (Fname)
FileCopy("file:///home/yomomo/Downloads/wiki3/index.php", "file:///home/yomomo/Downloads/wiki3/⁩"& k & " " & Fname &".odt" )
kill("file:///home/yomomo/Downloads/wiki3/index.php") 

End sub



'this is a simple replace procedure. At the beginning of the main sub (wiki2opoffwr)
'many of the characteristic characterfollows (eg [[ at the beginning or ]] at the end
'of a wiki hyperlink) are replaced through other symbols (eg <§wl) that make the 
'programming easier. Some keywords will be deleted (replaced through ""), because I 
'didnt find them so important(eg style in a table), but if you want to, you can also 
'change the code and take tham under concern
Sub skipLine(Optional oVC,Optional oTC)
 		   oVC.goRight(1,false)  'go to next line
   		   If NOT oVC.isAtStartOfLine() Then
   		      oVC.gotoStartOfLine(false) 
   		   EndIf
   		   oVC.gotoEndOfLine(true)  'go to the end of the next line and mark the line
    	   oTC.gotoNextParagraph(false)  'go to the beginning of the next line
End Sub

Danksagung Bearbeiten

Danke an den Leuten, die mir mal C++, Java (und früher PASCAL) beigebracht haben.

Danke an Pitonyak für sein Buch über Macros

Danke an [1] und allgemein an openoffice Dokumentationsseite.