von openmind » Mo, 08.03.2004 13:59
Ich bin mir nicht sicher, ob ein Export nach HTML wirklich das Gelbe vom Ei ist. Der HTML-Code, den OOo erstellt ist voller Müll, welcher nur gebraucht wird wenn man die HTML-Seite wieder mit OOo öffnet.
Ich sehe zwei Möglichkeiten: Der erste ist, dass du auf dem Internet nach einem Export für XHTML suchst, der nicht dem OOo-Export etnspricht, sondern sauberes (v.a. schlankes) (X)HTML erzeugt. Ich hab auf der Malinglist gelesen, dass es sowas gibt. Habe aber keine Ahnung wo. Die andere Möglichkeit ist den Export selbst zu schreiben, z.B. in Basic. Du kannst durch das ganze Dokument-Loopen und dein HTML-Export-Format nach belieben selbst schneidern. ALs kleiner Einstieg eine Basic Funktion, welche ein Writer-Dikument nach Wiki-Code formatiert:
Code: Alles auswählen
Function selection2Wiki
Dim selection as Object, oText as Object
Dim writerDoc as Object
Dim wiki as String
Dim elementCount as Integer
Dim oElement as Object
Dim oParagraphEnum as Object
Dim oParagraph as Object
Dim i as Integer
Dim sStyleName as String
' textportions variables
Dim oEnumeration as Object
Dim oPortion as Object
Dim sUrl as String
Dim sPortionString as String
Dim sElementString as String
' tables variables
Dim nRow as Integer
Dim sRow as String
Dim nIndex as Integer
Dim oCell as Object
Dim aCellNames as Variant
Dim bFirstInRow as Boolean
wiki = ""
writerDoc = ThisComponent
selection = writerDoc.getCurrentSelection()
' screen updates ausschalten
ThisComponent.lockControllers()
if ( Not IsNull( selection ) ) Then
elementCount = selection.count
oText = ThisComponent.Text
For i=0 to elementCount-1
oElement = selection.getByIndex( i )
If oElement.hasElements Then
oParagraphEnum = oElement.createEnumeration
while oParagraphEnum.hasMoreElements
oParagraph = oParagraphEnum.nextElement
' process paragraphs
if oParagraph.supportsService( "com.sun.star.text.Paragraph" ) Then
sStyleName = oParagraph.paraStyleName
if ( sStyleName = "Heading 1" AND oParagraph.getString() <> "" ) Then
wiki = wiki & "=" & oParagraph.getString() & chr(13) & chr(13)
Elseif ( sStyleName = "Heading 2" AND oParagraph.getString() <> "" ) Then
wiki = wiki & "==" & oParagraph.getString() & chr(13) & chr(13)
Elseif ( sStyleName = "Heading 3" AND oParagraph.getString() <> "" ) Then
wiki = wiki & "===" & oParagraph.getString() & chr(13) & chr(13)
Elseif ( sStyleName = "Heading 4" AND oParagraph.getString() <> "" ) Then
wiki = wiki & "====" & oParagraph.getString() & chr(13) & chr(13)
Elseif ( sStyleName = "Heading 5" AND oParagraph.getString() <> "" ) Then
wiki = wiki & "=====" & oParagraph.getString() & chr(13) & chr(13)
Elseif ( sStyleName = "Heading 6" AND oParagraph.getString() <> "" ) Then
wiki = wiki & "======" & oParagraph.getString() & chr(13) & chr(13)
Elseif ( sStyleName = "Heading 7" AND oParagraph.getString() <> "" ) Then
wiki = wiki & "=======" & oParagraph.getString() & chr(13) & chr(13)
Elseif ( sStyleName = "Heading 8" AND oParagraph.getString() <> "" ) Then
wiki = wiki & "========" & oParagraph.getString() & chr(13) & chr(13)
Elseif ( sStyleName = "Heading 9" AND oParagraph.getString() <> "" ) Then
wiki = wiki & "=========" & oParagraph.getString() & chr(13) & chr(13)
Elseif ( ( sStyleName = "Text body" OR sStyleName = "Standard" ) AND oParagraph.getString() <> "" ) Then
' list or paragraph?
if oParagraph.NumberingIsNumber then
wiki = wiki & "*" & oParagraph.getString() & chr(13) & chr(13)
Else
'----------------------------------------------------------------------------------------
oEnumeration = oParagraph.createEnumeration
while ( oEnumeration.hasMoreElements )
oPortion = oEnumeration.nextElement
sUrl = oPortion.HyperlinkURL
sPortionString = oPortion.String
if sUrl <> "" AND sPortionString <> "" Then
wiki = wiki & "[" & sUrl & "|" & oPortion.getString() & "]"
Elseif sPortionString <> "" Then
wiki = wiki & oPortion.getString()
End If
Wend
wiki = wiki & chr(13) & chr(13)
'----------------------------------------------------------------------------------------
End if
Elseif ( sStyleName = "Code" ) Then
wiki = wiki & " " & oParagraph.getString() & chr(13)
Elseif ( oParagraph.getString() <> "" ) Then
MsgBox "unbekannter Style " & sStyleName
End if
Else oParagraph.supportsService( "com.sun.star.text.TextTable" )
' theres a bloody table
' we need variables !!
' init some stuff
nRow = 1
sRow = "0"
bFirstInRow = true
wiki = wiki & "||--" & chr(13)
aCellNames = oparagraph.getCellNames
for nIndex = LBound( aCellNames ) to UBound( aCellNames )
oCell = oParagraph.getCellByName( aCellNames( nIndex ) )
' be aware of new row!
sRow = Right( oCell.CellName, Len( oCell.CellName ) -1 )
if nRow < CInt(sRow) Then
' current cell is on new row
nRow = CInt(sRow)
' next row
wiki = wiki & chr(13)
bFirstInRow = true
Else
bFirstInRow = false
End If
' insert cell cell in wicki
if nRow = 1 Then
if Not( bFirstInRow ) Then
wiki = wiki & "-||-"
End If
wiki = wiki & oCell.String
else
wiki = wiki & "||" & oCell.String
End If
Next nIndex
wiki = wiki & chr( 13 ) & "--||" & chr( 13 ) & chr( 13 )
End If
Wend
End If
Next i
End If
' screen updates wieder einschalten
ThisComponent.unlockControllers()
selection2Wiki = wiki
End Function
Achja, colspans von Zellen werden ignoriert, genauso wie Rowspans und die unterstützten Formatvorlagen des obigen Skipts sind dünn geät, erweitern aber ziemlich einfach.
Ich bin mir nicht sicher, ob ein Export nach HTML wirklich das Gelbe vom Ei ist. Der HTML-Code, den OOo erstellt ist voller Müll, welcher nur gebraucht wird wenn man die HTML-Seite wieder mit OOo öffnet.
Ich sehe zwei Möglichkeiten: Der erste ist, dass du auf dem Internet nach einem Export für XHTML suchst, der nicht dem OOo-Export etnspricht, sondern sauberes (v.a. schlankes) (X)HTML erzeugt. Ich hab auf der Malinglist gelesen, dass es sowas gibt. Habe aber keine Ahnung wo. Die andere Möglichkeit ist den Export selbst zu schreiben, z.B. in Basic. Du kannst durch das ganze Dokument-Loopen und dein HTML-Export-Format nach belieben selbst schneidern. ALs kleiner Einstieg eine Basic Funktion, welche ein Writer-Dikument nach Wiki-Code formatiert:
[code]Function selection2Wiki
Dim selection as Object, oText as Object
Dim writerDoc as Object
Dim wiki as String
Dim elementCount as Integer
Dim oElement as Object
Dim oParagraphEnum as Object
Dim oParagraph as Object
Dim i as Integer
Dim sStyleName as String
' textportions variables
Dim oEnumeration as Object
Dim oPortion as Object
Dim sUrl as String
Dim sPortionString as String
Dim sElementString as String
' tables variables
Dim nRow as Integer
Dim sRow as String
Dim nIndex as Integer
Dim oCell as Object
Dim aCellNames as Variant
Dim bFirstInRow as Boolean
wiki = ""
writerDoc = ThisComponent
selection = writerDoc.getCurrentSelection()
' screen updates ausschalten
ThisComponent.lockControllers()
if ( Not IsNull( selection ) ) Then
elementCount = selection.count
oText = ThisComponent.Text
For i=0 to elementCount-1
oElement = selection.getByIndex( i )
If oElement.hasElements Then
oParagraphEnum = oElement.createEnumeration
while oParagraphEnum.hasMoreElements
oParagraph = oParagraphEnum.nextElement
' process paragraphs
if oParagraph.supportsService( "com.sun.star.text.Paragraph" ) Then
sStyleName = oParagraph.paraStyleName
if ( sStyleName = "Heading 1" AND oParagraph.getString() <> "" ) Then
wiki = wiki & "=" & oParagraph.getString() & chr(13) & chr(13)
Elseif ( sStyleName = "Heading 2" AND oParagraph.getString() <> "" ) Then
wiki = wiki & "==" & oParagraph.getString() & chr(13) & chr(13)
Elseif ( sStyleName = "Heading 3" AND oParagraph.getString() <> "" ) Then
wiki = wiki & "===" & oParagraph.getString() & chr(13) & chr(13)
Elseif ( sStyleName = "Heading 4" AND oParagraph.getString() <> "" ) Then
wiki = wiki & "====" & oParagraph.getString() & chr(13) & chr(13)
Elseif ( sStyleName = "Heading 5" AND oParagraph.getString() <> "" ) Then
wiki = wiki & "=====" & oParagraph.getString() & chr(13) & chr(13)
Elseif ( sStyleName = "Heading 6" AND oParagraph.getString() <> "" ) Then
wiki = wiki & "======" & oParagraph.getString() & chr(13) & chr(13)
Elseif ( sStyleName = "Heading 7" AND oParagraph.getString() <> "" ) Then
wiki = wiki & "=======" & oParagraph.getString() & chr(13) & chr(13)
Elseif ( sStyleName = "Heading 8" AND oParagraph.getString() <> "" ) Then
wiki = wiki & "========" & oParagraph.getString() & chr(13) & chr(13)
Elseif ( sStyleName = "Heading 9" AND oParagraph.getString() <> "" ) Then
wiki = wiki & "=========" & oParagraph.getString() & chr(13) & chr(13)
Elseif ( ( sStyleName = "Text body" OR sStyleName = "Standard" ) AND oParagraph.getString() <> "" ) Then
' list or paragraph?
if oParagraph.NumberingIsNumber then
wiki = wiki & "*" & oParagraph.getString() & chr(13) & chr(13)
Else
'----------------------------------------------------------------------------------------
oEnumeration = oParagraph.createEnumeration
while ( oEnumeration.hasMoreElements )
oPortion = oEnumeration.nextElement
sUrl = oPortion.HyperlinkURL
sPortionString = oPortion.String
if sUrl <> "" AND sPortionString <> "" Then
wiki = wiki & "[" & sUrl & "|" & oPortion.getString() & "]"
Elseif sPortionString <> "" Then
wiki = wiki & oPortion.getString()
End If
Wend
wiki = wiki & chr(13) & chr(13)
'----------------------------------------------------------------------------------------
End if
Elseif ( sStyleName = "Code" ) Then
wiki = wiki & " " & oParagraph.getString() & chr(13)
Elseif ( oParagraph.getString() <> "" ) Then
MsgBox "unbekannter Style " & sStyleName
End if
Else oParagraph.supportsService( "com.sun.star.text.TextTable" )
' theres a bloody table
' we need variables !!
' init some stuff
nRow = 1
sRow = "0"
bFirstInRow = true
wiki = wiki & "||--" & chr(13)
aCellNames = oparagraph.getCellNames
for nIndex = LBound( aCellNames ) to UBound( aCellNames )
oCell = oParagraph.getCellByName( aCellNames( nIndex ) )
' be aware of new row!
sRow = Right( oCell.CellName, Len( oCell.CellName ) -1 )
if nRow < CInt(sRow) Then
' current cell is on new row
nRow = CInt(sRow)
' next row
wiki = wiki & chr(13)
bFirstInRow = true
Else
bFirstInRow = false
End If
' insert cell cell in wicki
if nRow = 1 Then
if Not( bFirstInRow ) Then
wiki = wiki & "-||-"
End If
wiki = wiki & oCell.String
else
wiki = wiki & "||" & oCell.String
End If
Next nIndex
wiki = wiki & chr( 13 ) & "--||" & chr( 13 ) & chr( 13 )
End If
Wend
End If
Next i
End If
' screen updates wieder einschalten
ThisComponent.unlockControllers()
selection2Wiki = wiki
End Function[/code]
Achja, colspans von Zellen werden ignoriert, genauso wie Rowspans und die unterstützten Formatvorlagen des obigen Skipts sind dünn geät, erweitern aber ziemlich einfach.