Map2wiki-dev.mmbas

' map2wiki 28May07 http://creativecommons.org/licenses/by-sa/2.5/ http://www.activityowner.com/ ' convert a mindmanager map into wiki format ' Adjust the depth of various formatting in slevelstringfun below ' Sub Main Dim level As Integer  'current depth of map, level 1=maintopic Dim doc As Document	 'document being exported Dim f As String		 'filename of destination text file Dim atopic As Topic	 'main topic variable ' Set doc=ActiveDocument level=0 'write output to wiki.txt in default directory f=GetPath(mmDirectoryMyMaps)&"wiki.txt" Open f For Output As #1 'use centraltopic as title Print #1, Chr(39)&Chr(39)&Chr(39) & doc.CentralTopic.Text &Chr(39) & Chr(39) & Chr(39) &Chr(13)&Chr(10); 'Add notes below using notes2wiki procedure note2wiki doc.CentralTopic For Each atopic In doc.CentralTopic.AllSubTopics 'call main subroutine writeit level, atopic, False Next Close #1 'display result in notepad for pasting into wiki Shell("notepad.exe "&f,1)';} End Sub Sub writeit(slevel As Integer, atopic As Topic, ByVal writeHeadings As Boolean) Dim level As Integer Dim stopic As Topic Dim slevelstr As String Dim elevelstr As String 'set outline level one deeper. level=slevel+1 slevelstr=slevelstrfun(level) If InStr(slevelstr,"=") Then elevelstr=slevelstr Else elevelstr="" End If  If atopic.HasHyperlink Then If InStr(atopic.Hyperlink.Address,"http") Then 'add external link Print #1, slevelstr & Chr(91) & atopic.Hyperlink.Address & atopic.Text & Chr(93) & elevelstr Else 'reference another wiki page -- need to match title Print #1, slevelstr &Chr(91) & Chr(91) & atopic.Text & Chr(93) & Chr(93) & elevelstr End If  Else ' Write as either bullets or sub-headings If atopic.AllSubTopics.Count>0 Or writeHeadings Then Print #1, level & atopic.Text & level Else Print #1, "*" & atopic.Text End If  End If   'add notes note2wiki atopic 'recursively follow subtopics If atopic.AllSubTopics.Count>0 Then ' should the next level be written as sub-headings or bullets writeHeadings = False For Each stopic In atopic.AllSubTopics If stopic.AllSubTopics.Count>0 Then writeHeadings=True End If    Next ' if none of the next level topics have child nodes, then write as bullets For Each stopic In atopic.AllSubTopics writeit level,stopic,writeHeadings Next End If End Sub Sub note2wiki(ntopic As Topic) Dim notetext As String 'convert the html markup in the note into wiki format in order to recover hyperlinks usehtml=False If usehtml Then notetext=ntopic.Notes.TextXHTML notetext=Replace(notetext,"<!DOCTYPE html PUBLIC "&Chr(34)&"-//W3C//DTD XHTML 1.0 Transitional//EN"&Chr(34)&Chr(13)&Chr(10),"") notetext=Replace(notetext,"","") notetext=Replace(notetext,"         "&Chr(34)&"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&Chr(34)&">"&Chr(13)&Chr(10),"") notetext=Replace(notetext," ","") notetext=Replace(notetext," ","") notetext=Replace(notetext," ","") notetext=Replace(notetext," ","") notetext=Replace(notetext," ","") notetext=Replace(notetext,""," ") notetext=Replace(notetext,"","]") notetext=Replace(notetext," ","") notetext=Replace(notetext,Chr(13)&Chr(10)&Chr(13)&Chr(10),Chr(13)&Chr(10)) Else notetext=ntopic.Notes.Text End If Print #1, notetext End Sub Function slevelstrfun(level As Integer) As String Dim s As String s="" sectiondepthstart	=1 sectiondepthend 	=1 numberdepthstart 	=0 numberdepthend	=0 bulletdepthstart	=2 bulletdepthend	=50 For i=1 To level If level>=sectiondepthstart And level<=sectiondepthend Then If level=sectiondepstart Then s="=" Else s=s & "=" End If   End If    If level>=numberdepthstart And level<=numberdepthend Then If level=numberdepthstart Then s="#" Else s=s & "#" End If   End If    If level>=bulletdepthstart And level<=bulletdepthend Then If level=bulletdepthstart Then s="*" Else s=s & "*" End If   End If Next slevelstrfun=s End Function