I just finished my first real-life timesaver script in Perl. I got a bit tired of the WYSIWYG Wordpress editor to markup my blog posts. It does an insufficient job aligning what I intend to display, which in itself is already a time-consuming activity (selecting/clicking). Moreover, I have to peak into the HTML to correct the editor. Time to automate this!


featured image

Write my posts in a text editor with some simpler markup which I defined with some basic rules. The Perl script converts this to HTML that I can paste into the Wordpress editor (HTML tab)

Update 03.07.2012 ) I use the script for every post now for almost a year and it has been a great time saver. The invented markup is really easy and covers about all I need. The HTML generation is then one command and I quickly paste it into the Wordpress HTML editor. Another advantage is that my posts have conistent HTML tags, so if I decide to change CSS rules, the changes should be reflected in all posts.

The rules I use for quick text editor blogging

* headings
>>> preceded by a line means a header 3 (my css is using this for headings in my post)
>>>> same for h4 / headings

* intro text
MORE delimits the intro text that you see on the frontage (teaser)

* links
||Link name group||url
for links in the post (I use only target='_blank')
example: ||link to home||http://bobbelderbos.com

* paragraphs
lines preceded by :: are wrapped in paragraph tags with optional floating

* images
!!ALT text!!image link!!float!!width
for images (manual upload but I can script that, less cumbersome than WP)
(these are exclamation marks as opposed to pipe characters for anchors above)
example: !!featured image!!http://example.com/wp-content/uploads/YYYY/MM/image.jpg!!right!!200

* code samples
content between the CODE and /CODE tags will be wrapped in "pre" tags

* unordered list (ul / li)
are formed by a * (ul), one or more dashes - (li elements) and two stars (closing ul)

* literal lines
as perl I use the pound # sign. these lines are displayed "as is" so no risk of being mutilated by the script

* comments
lines preceded by #! are literal comments and will be ignored by the parser
example in my blog template: http://bobbelderbos.com/src/blog_template.txt

* FB like button
the word "LIKE" on a seperate line converts into fb:like button which you can spread around in your posts

This is the basic stuff I use in blog posts. I can easily memorize this syntax and write my posts in my text editor (a place where I am more effective anyway). Then when the post is done and saved as a text file, for example, blogpost.txt, I can run the perl script like this: $ perl wordpress_parse_post.pl blogpost.txt > blogpost.html && mate blogpost.html

The parser

The parser is available at Github. I couldn't paste it in here because I would get HTML embedding issues. Just check it out at Github and let me know if you have any suggestions ...


Again, the generated html is based on the html I defined in my WP theme and wrote CSS for. But if you understand the search and replace functions (REGEX) of the script, you can easily go in and customize it. You just need to have a system defined.

If you want to use my defined markup, you can download the template here.

Bob Belderbos

I build useful apps and share my learning About me