I officially hate WordPress

I have some text that I want to paste verbatim (excerpt from a manpage, and some code) and it’s apparently impossible to get that into this blog. I pasted the content, clicked on « b-quote » (for the manpage) and « code » (for the code) and what I get is below. A huge messed.

Libre office can convert documents from one format to another from command line. Quoting the manpage :

–convert-to output_file_extension[:output_filter_name] [–outdir output_dir] file…
Batch converts files. If –outdir is not specified then the current working directory is used as the output directory for the converted files.

Examples:

–convert-to pdf *.doc

Converts all .doc files to PDFs.

–convert-to pdf:writer_pdf_Export –outdir /home/user *.doc

Converts all .doc files to PDFs using the settings in the Writer PDF export dialog and saving them in /home/user.

The problem is that the list of these filters does not seem to be easily available. However, on http://permalink.gmane.org/gmane.comp.documentfoundation.libreoffice.user/15226 there is a script which does exactly that : list all filters available in your Libre Office.

For convenience, and because the formatting of the macro on the mailing list was a little damaged, here it is :

Sub Main
oFF = createUnoService( "com.sun.star.document.FilterFactory" )
oFilterNames = oFF.getElementNames()

' Now print the filter names.
' For i = LBound( oFilterNames ) To UBound( oFilterNames )
' Print oFilterNames(i)
' Next

' Create a Writer doc and save the filter names to it.
oDoc = StarDesktop.loadComponentFromURL( "private:factory/swriter","_blank", 0, Array() )
oText = oDoc.getText()
oCursor = oText.createTextCursor()
oCursor.gotoEnd( False )

oText.insertString( oCursor, "Filter Names", False )
oCursor.ParaStyleName = "Heading 1"
InsertParaBreak( oText, oCursor )
' oCursor.ParaStyleName = "Default"
InsertParaBreak( oText, oCursor )

' Print the filter names into a Writer document.
For i = LBound( oFilterNames ) To UBound( oFilterNames )
oText.insertString( oCursor, oFilterNames(i), False )
InsertLineBreak( oText, oCursor )
Next
InsertParaBreak( oText, oCursor )

InsertParaBreak( oText, oCursor )
oText.insertString( oCursor, "Filter Names and their Properties", False )
oCursor.ParaStyleName = "Heading 1"
InsertParaBreak( oText, oCursor )
' oCursor.ParaStyleName = "Default"

' Tab stops at:
' 0.25 inch (2.54 cm x 0.25)
' 0.50 inch (2.54 cm x 0.50)
' 2.00 inch (2.54 cm x 2.00)
oCursor.ParaTabStops = Array(_
MakeTabStop( 2540 * 0.25 ),_
MakeTabStop( 2540 * 0.50 ),_
MakeTabStop( 2540 * 2.00 ) )

' Print the filter names and their parameters.
For i = LBound( oFilterNames ) To UBound( oFilterNames )
InsertParaBreak( oText, oCursor )

cFilterName = oFilterNames(i)
aFilterProps = oFF.getByName( cFilterName )

oText.insertString( oCursor, cFilterName, False )

For j = LBound( aFilterProps ) To UBound( aFilterProps )
oFilterProp = aFilterProps(j)

InsertLineBreak( oText, oCursor )
oText.insertString( oCursor, CHR(9)+oFilterProp.Name, False )

nFilterPropValueVarType = VarType( oFilterProp.Value )
If nFilterPropValueVarType = 8201 Then
' VarType 8201 means a sequence of PropertyValue's.
oFilterPropNames = oFilterProp.Value
For k = LBound( oFilterPropNames ) To UBound(oFilterPropNames )
InsertLineBreak( oText, oCursor )
oText.insertString( oCursor,CHR(9)+CHR(9)+oFilterPropNames(k).Name+CHR(9)+CSTR(oFilterPropNames(k).Value),False )
Next k
ElseIf nFilterPropValueVarType = 8200 Then
' VarType 8200 means a sequence of Strings.
oFilterPropNames = oFilterProp.Value
For k = LBound( oFilterPropNames ) To UBound(oFilterPropNames )
InsertLineBreak( oText, oCursor )
oText.insertString( oCursor,CHR(9)+CHR(9)+oFilterPropNames(k), False )
Next k
ElseIf nFilterPropValueVarType > 1 And nFilterPropValueVarType <= 12 Then
oText.insertString( oCursor,CHR(9)+CSTR(oFilterProp.Value), False )
Else
oText.insertString( oCursor, CHR(9)+"?? unknown type ?? - "+CSTR(nFilterPropValueVarType), False )
EndIf
Next j

InsertParaBreak( oText, oCursor )
Next i

InsertParaBreak( oText, oCursor )
End Sub

Sub InsertLineBreak( oText, oCursor )
oText.insertControlCharacter( oCursor,com.sun.star.text.ControlCharacter.LINE_BREAK, False )
End Sub

Sub InsertParaBreak( oText, oCursor )
oText.insertControlCharacter( oCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False )
End Sub

' Create and return a tab stop.
' An array of what this function returns, is used
' to set the tab stops of a paragraph.
'
' Parameters....
' nPosition - position in tab stop, in 1000'th of cm.
' nAlign - optional, if specified, must be one of...
' com.sun.star.style.TabAlign.LEFT = 0
' com.sun.star.style.TabAlign.CENTER = 1
' com.sun.star.style.TabAlign.RIGHT = 2
' com.sun.star.style.TabAlign.DECIMAL = 3
' com.sun.star.style.TabAlign.DEFAULT = 4
' cDecimalChar - optional, if specified, only applies to a DECIMAL tab stop,
' and specified the character which is recognized as
' the decimal point separator.
' cFillChar - optional, if specified, specifies the char that fills the space
' between tab stops.
Function MakeTabStop( ByVal nPosition As Long,_
Optional nAlign,_
Optional cDecimalChar,_
Optional cFillChar _
) As com.sun.star.style.TabStop
If IsMissing( nAlign ) Then
nAlign = com.sun.star.style.TabAlign.LEFT
EndIf

oTabStop = createUnoStruct( "com.sun.star.style.TabStop" )

oTabStop.Position = nPosition
oTabStop.Alignment = nAlign

If Not IsMissing( cDecimalChar ) Then
oTabStop.DecimalChar = cDecimalChar
EndIf
If Not IsMissing( cFillChar ) Then
oTabStop.FillChar = cFillChar
EndIf

MakeTabStop() = oTabStop
End Function

Laisser un commentaire

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:

Logo WordPress.com

Vous commentez à l'aide de votre compte WordPress.com. Déconnexion / Changer )

Image Twitter

Vous commentez à l'aide de votre compte Twitter. Déconnexion / Changer )

Photo Facebook

Vous commentez à l'aide de votre compte Facebook. Déconnexion / Changer )

Photo Google+

Vous commentez à l'aide de votre compte Google+. Déconnexion / Changer )

Connexion à %s


%d blogueurs aiment cette page :