| |

Exporting Partial HTML for WordPress Posts

I’m a bit eccentric and don’t use the visual editor with WordPress on this blog and several others that I maintain. For a number of posts I write my basic material in OpenOffice Writer and then post it. Up to now I have added the formatting by hand, but today I decided to write myself a macro that included the formatting codes I want to include in my posts, and leaves everything else out.

As usual, this starts from existing code, the simple HTML export from the StarOffice 8 Programming Guide
for BASIC
.

What I want to export are block quotes, italics, bolding, superscript, and subscript. For another type of posts I export some very basic outlining that I present preformatted using the <PRE*GT; tag. Any paragraph that carries the “Quotations” style will be surrounded by <blockquote> tags.

I’m a little eccentric on the outlining. Any outlining will be of one type, and so I just check if there is some sort of a numbering style, and create my numbering accordingly. This macro is mildly eccentric, and has only been given the most basic testing. If that doesn’t scare you, have fun!

Here’s the code:

Sub ParaNumber(level as integer,num as integer) as String
	select Case level
		case 0:
			n = num * 5 + 1
			ParaNumber = Mid("    I   II  III   IV    V   VI  VII VIII   IX    X   XI  XII XIII  XIV   XV  XVI XVIIXVIII  XIX   XX", n, 5)
		case 1:
			n = num + 1
			ParaNumber = "        " & Mid("ABCDEFGHIJKLMNOPQRSTUVWXYZ",n,1)
		case 2:
			n = num * 2 + 1
			ParaNumber = "             " & Mid(" 1 2 3 4 5 6 7 8 9 1011121314151617181920",n,2)
		case 3:
			n = num * 5 + 1
			ParaNumber = "                  " & Mid("    i   ii  iii   iv    v   vi  vii viii   ix    x   xi  xii xiii  xiv   xv  xvi xviixviii  xix   xx", n, 5)
	end select			
End Sub

Sub WordPressHTML()
	Dim FileNo As Integer, Filename As String, CurLine As String
	Dim Doc As Object
	Dim Enum1 As Object, Enum2 As Object
	Dim TextElement As Object, TextPortion As Object
	Dim iParaNums(4) as Integer

	Filename = "c:\oodev\export_test.html"
	FileNo = Freefile
	Open Filename For Output As #FileNo
'	Print #FileNo, ""
	Doc = StarDesktop.CurrentComponent
	Enum1 = Doc.Text.createEnumeration
	' loop over all paragraphs
	While Enum1.hasMoreElements
		TextElement = Enum1.nextElement
		If TextElement.supportsService("com.sun.star.text.Paragraph") Then
			If TextElement.ParaStyleName = "Quotations" Then
				CurLine = "
" Else CurLine = "" ' we no longer need

or

End If if len(TextElement.NumberingStyleName) > 0 Then lvl = TextElement.NumberingLevel Select Case lvl Case 0: iParaNums(1) = 0 iParaNums(2) = 0 iParaNums(3) = 0 case 1: iParaNums(2) = 0 iParaNums(3) = 0 case 2: iParaNums(3) = 0 End Select CurLine = CurLine & ParaNumber(lvl,iParaNums(lvl)) iParaNums(lvl) = iParaNums(lvl) + 1 CurLine = CurLine & ". " End If ' loop over all paragraph portions Enum2 = TextElement.createEnumeration While Enum2.hasMoreElements TextPortion = Enum2.nextElement If TextPortion.CharWeight = com.sun.star.awt.FontWeight.BOLD THEN CurLine = CurLine & "" End If If TextPortion.CharPosture = com.sun.star.awt.FontSlant.ITALIC THEN CurLine = CurLine & "" End If If TextPortion.CharEscapement > 0 THEN CurLine = CurLine & "" ElseIf TextPortion.CharEscapement < 0 THEN CurLine = CurLine & "" EndIf CurLine = CurLine & TextPortion.String If TextPortion.CharWeight = com.sun.star.awt.FontWeight.BOLD THEN CurLine = CurLine & "" End If If TextPortion.CharPosture = com.sun.star.awt.FontSlant.ITALIC THEN CurLine = CurLine & "" End If If TextPortion.CharEscapement > 0 THEN CurLine = CurLine & "" ElseIf TextPortion.CharEscapement < 0 THEN CurLine = CurLine & "" EndIf Wend ' output the line If TextElement.ParaStyleName = "Quotations" Then CurLine = CurLine & "
" End If CurLine = CurLine & CHR(13) if len(TextElement.NumberingStyleName) = 0 Then CurLine = CurLine & CHR(13) End If Print #FileNo, CurLine End If Wend 'write HTML footer ' Print #FileNo, "" Close #FileNo End Sub

Similar Posts

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.