Jean Hollis Weber wrote:
T. J. Frazier wrote:
Jean,
Hope this brightens your day:
* The code to clean up Tips, Notes, and Cautions in the export-to-Wiki
file is working. I'll put it on the shelf, for whenever you have time
to take a look.
A day brightener, indeed! I have 2 or 3 more draft chapters of the
Impress Guide to wikify in the next few days, so if you can send me (or
tell me where to get) your code, that should be helpful.
Try 1: attachment of wiki.bas file, herewith. (If that doesn't work, we'll try something
else.)
I suggest using the Organize Macros > My Macros > Standard dialog to create a new module
(I call mine, "wiki"), edit the new module, select the three created lines, and click the
Import icon on the IDE toolbar.
You might want to assign a keyboard shortcut, or a toolbar or menu item. I always run
from the IDE, but this can lead to a runtime error if the right file isn't on top of
OO.o's collection. (No harm done by this: just jiggle who's on top.) (Sorry, haven't
mastered the skills of installing shortcuts by code. Yet.)
* Save As in Writer, to "Encoded Text (*.txt)", seems to work just
fine; even better, copy-and-paste, directly from Writer, seems to
produce understandable files, too.
I'll try both of those. Thanks.
This is *the* key thing for the future. If it all works, you can use Writer for all your
post-processing, thus having all of Writer's power (including macros! :-) ) available, and
then go to the Wiki.
The one tricky part is opening the Exported file. For a platform-independent
way, I use:
1) from the Quickstarter, choose Open Document...
2) browse and click on the .txt Exported file: name appears in File name box
* 3) (key part) in the File type (bottom) box, select "Text Encoded (*.txt)". It's down a
ways in the list, just below RTF and Text. Click Open.
4) the ASCII Filter Options dialog opens. I've been using Character set Unicode (UTF-8),
and Paragraph break radio-button LF. Click OK when happy.
5) file opens as "Preformatted Text", should look very readable.
This is the stage from which a Save As "Encoded Text" or "RTF" can be used. (Yes, the
wording here is backward from the input side :-) ) The editing, including running the new
macro, isn't WYSIWYG, but it works.
I'll move forward with the automatic-TOC
stuff (big learning curve involved [fun! :-) ]).
For geeky values of fun! :-)
Cheers, Jean
(As a one-time resident of Sunnyvale, CA, I am an official, card-carrying geek from
Silicon Valley. /Ad astra, per aspera!/)
--
T. J. Frazier
Melbourne, FL
(TJFrazier on OO.o)
REM ***** BASIC *****
Option Explicit
Sub TipNoteCautionCleanup
' Cleans up Tips, Notes, and Cautions after "Save to MediaWiki".
' OO.o MsgBox constants
' button types
Const mbOKOnly as integer = 0
Const mbOKCancel as integer = 1
Const mbExclamation as integer = 48
' user responses
Const mbROK as integer = 1
Dim oCursor as Variant 'text cursor
Dim oDoc as Object
Dim enum1, thisPara, enum2, thisPortion
Dim vAnchor as Variant
Dim bBegin as Boolean
Dim bGo as Boolean
Dim iCaution as Integer, iNote as Integer, iTip as Integer
Dim iPara as Integer
Dim iPor as Integer
Dim sFind as String
Dim sRep as String
Dim sText as String
oDoc = ThisComponent
enum1 = oDoc.Text.createEnumeration
bBegin = True
While enum1.hasMoreElements
iPara = iPara + 1
thisPara = enum1.nextElement
enum2 = thisPara.createEnumeration
While enum2.hasMoreElements
thisPortion = enum2.nextElement
iPor = iPor + 1
sText = thisPortion.getString()
sFind = IIf( bBegin, "{|", "|}" )
If Mid(sText, 1, 2) = sFind Then 'found a sentinel
vAnchor = thisPortion.getAnchor
oCursor = thisPortion.Text.createTextCursorByRange(vAnchor)
' bGo = msgBox ( sFind & "Para " & str(iPara) & "." & chr(13) _
' & "por " & str(iPor) & "." & chr(13) _
' & "Cursor " & oCursor.String & "." & chr(13) _
' , mbOKOnly, "Hit " & sFind )
If bBegin Then 'looking for opening delimiter
bBegin = False 'next loop, look for closing delimiter
' expand selection to include next paragraph and its mark.
bGo = oCursor.goRight( 1, True ) '-> next paragraph
bGo = oCursor.gotoEndOfParagraph( True )
bGo = oCursor.goRight( 1, True ) 'include the para mark
' If msgBox( "Go=" & bGo & " Cursor " & oCursor.String, _
' mbOKCancel + mbExclamation, "Danger Ahead - Begin") _
' <> mbROK Then Exit Sub
' the selected string should hold one of the 3 target names.
sRep = "{{Documentation/"
If InStr( oCursor.String, "Note" ) Then
sRep = sRep & "Note"
iNote = iNote + 1
ElseIf InStr( oCursor.String, "Tip" ) Then
sRep = sRep & "Tip"
iTip = iTip + 1
ElseIf InStr( oCursor.String, "Caution" ) Then
sRep = sRep & "Caution"
iCaution = iCaution + 1
bGo = oCursor.goRight( 2, True) 'empty para and into next
bGo = oCursor.gotoEndOfParagraph( True ) 'img: <center> para
bGo = oCursor.goRight( 1, True ) 'include the para mark
' If msgBox (oCursor.String, mbOKCancel, "Caution" ) _
' <> mbROK Then Exit Sub
Else 'error
msgBox "TNC not found: " & oCursor.String
sRep = ""
bBegin = True 'keep looking for beginning, after error
EndIf 'NTC found
If sRep <> "" Then
thisPortion.Text.insertString( oCursor, sRep, True )
End If 'sRep not empty
Else 'bBegin = False, looking for ending delimiter
oCursor.collapseToEnd
bGo = oCursor.goLeft( 4, True ) 'include two para marks
' If msgBox( "Go=" & bGo & " Cursor " & oCursor.String & ".", _
' mbOKCancel + mbExclamation, "Danger Ahead - End") _
' <> mbROK Then Exit Sub
thisPortion.Text.insertString( oCursor, "}}", True )
bBegin = True
EndIf 'bBegin
End If 'hit
Wend
Wend
MsgBox "Paragraphs - " & str(iPara) & chr(13) _
& "Portions - " & str(iPor) & chr(13) _
& "Cautions - " & str(iCaution) & chr(13) _
& "Notes - " & str(iNote) & chr(13) _
& "Tips - " & str(iTip), _
mbOKOnly, "Processing Complete!"
End Sub 'TipNoteCautionCleanup