Skip to main content

Sends (offline) articles written in MarkDown to WordPress via the XML-RPC API, and loads the draft articles from WordPress to the local machine. Works with proxies too.

Project description

This is a simple module meant to convert Markdown files to XML (XHTML) and send them to WordPress.com via XML-RPC.

The idea behind this all is to make the base of an open-source offline WordPress.com blog entry editor.

The first part converts the text written in a specific MarkDown language to XML (or XHTML).
Because I write currently my books for LeanPub I align the main conversion to the LeanPub MarkDown.
However MD to XML conversion is a bit bothersome and there are many libraries which do this, I'll stick to <b>Markdown</b> a Python library for converting MarkDown files to X(HT)ML.

The <i>mdxml.conf</i> file contains custom configuration which is not available in markdown. For example the <i>[sourcecode]</i> block for WordPress. For this behavior I skip the markdown conversion for these lines of code.
Currently language and other options cannot be added for source codes.

If you have other configuration extensions (for example if you want to override the <i>~~~~~~~~</i> for source-codes, you can define it in your own conversion file and provide it as an argument to the application.

Each configuration element has a starting and ending tag (although currently I am thinking about another way to solve this problem because XML files should be valid in the end...).

One problem with Markdown is, that you have to parse the whole text if you have multi-line elements (for example lists). If you do not do this, you'll end up with a bunch of lists.

Feel free to create issues and change requests.

The application looks for the configuration file (containing wordpress endpoint, username, password and optional proxy configuration) in your home folder under the name *wpedit.conf*. Optionally you can provide it per commandline argument.


<h2>Usage</h2>
<pre>
wpedit.py [-h] [-c CONFIG] [-m MDCONF] [-l] [-n NUMBER] [-U] [-V] post_file

positional arguments:
post_file The full path of the input file to send to WordPress.
If used with the '-l' option it is the full path of
the folder to save the drafts from WordPress.

optional arguments:
-h, --help show this help message and exit
-c CONFIG, --config CONFIG
The full path of the configuration file storing the
XML-RPC endpoint, username and password. Per default
the application looks at your home folder and searches
for wpedit.conf
-m MDCONF, --mdconf MDCONF
The full path of the md-to-xml conversion-extension
file
-l, --load Loads all draft posts into the folder where the
'post_file' resides. The 'post_file' will not be sent
to WordPress.
-n NUMBER, --number NUMBER
The number of draft posts to load. Works only in
combination with the '-l' argument.
-U, --update Forces update of every draft loaded, the check for
local modifications is disabled. Works only in
combination with the '-l' argument.
-V, --verify Enables verification of tags. If the blog post
contains tags which are not defined, the article will
not be sent to WordPress.
</pre>
<h2>File structure</h2>
The markdown file is parsed and you can place special lines at the beginning of the text. These special lines have to start with **[** (square bracket). Once the parser encounters a line which does not start with <b>[</b> the resulting text is treated as the content of the article.

<h3>Accepted special lines</h3>
[id] 1001 -- the ID of the blog post, if you create a new post, you do not have to provide an ID, <b>Note</b> if you provide an ID, the application attempts to edit the post with this ID.

[title] Some title -- you can specify the post's title here, in the example "Some title" will be the title of the article. If you do not provide a title and the post does not have a title, the title will be set to "My post".

[categories] Category 1, Category 2 -- a comma separated list of categories for your post. Optional, if not provided there will be no categories set. Starting with Version 0.3.1 categories are verified: if a category does not exist in the blog, you cannot post the entry.

[tags] tag 1, tag 2, tag 3 -- a comma separated list for your post. Optional, if not provided there will be no tags set. Starting with Version 0.3.1 optional tag-verification is enabled. If you have the option enabled you can use only defined tags in your post.

<h2>Extra markdown</h2>
Currently these extra markdonw symbols are configured for wpedit:
<dl>
<dt>~~~~~~~~ (tilde symbol 8 times)</dt> <dd>Surrounds code blocks which will be presented as *[sourcecode]* in WordPess. Source code blocks can be enriched with key-value pairs to represent parameters of <b>[sourcecode]</b> blocks.
~~~~~~~~{'language':'python', 'title':'Python source code example'} This line will be converted to: <b>[sourcecode language="python" title="Python source code example"]</b></dd>

<dt>-------- (dash 8 times)</dt> <dd>Adds a read more tag to your article which will be presented as *<!--more-->* in WordPress.</dd>

<dt>@@@ ("at" symbol 3 times)</dt> <dd>Makes the surrounded text preformatted which will be presented as <i>&lt;pre&gt;</i> in WordPRess.</dd>
</dl>
<h2>Changes</h2>
<h3>Version 0.4.5</h3>
<ul><li>fixed starting app as Python module after installation using <b>pip</b></li></ul>
<h3>Version 0.4.1</h3>
<ul>
<li>fixed category and tag validation bug</li>
</ul>
<h3>Version 0.4</h3>
<ul>
<li>added proxy to the configuration file to enable working from proxied network</li>
</ul>
<h3>Version 0.3.4</h3>
<ul>
<li>fixed installation error (issue #1) with removing disttest from the setup</li>
</ul>
<h3>Versions 0.3.2 and 0.3.3</h3>
<ul>
<li>fixed README displayed in PyPI -- I ended up with an HTML version</li>
<ul>
<h3>Version 0.3.1</h3>
<ul>
<li>force parameter added to update every draft even if it was changed locally later than on the server</li>
<li>number of fetched drafts is defineable from the command line as an argument, the default stays as 25</li>
<li>categories are always verified when posting to WordPress: if a category is not defined in the blog, the post won't be sent to the blog</li>
<li>optional tag-verification can be enabled: if enabled and a new tag is defined in the post, the post will be rejected and not sent to WordPress</li>
</ul>

<h3>Version 0.3</h3>
<ul>
<li>Starting with version 0.3 you can download your draft posts (currently the latest 25 in reverse-chronological order (based on their publish date)) (I plan to add an option to configure the maximum number to load)</li>
<li><i>tags</i> and <i>categories</i> are loaded with your posts</li>
<li>If you altered the draft locally it will not get overwritten (I plan to add a command line argument to force updates)</li>
<li>downloading of source code and "more"-tags work properly</li>
</ul>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wpedit-0.4.5.tar.gz (18.2 kB view details)

Uploaded Source

File details

Details for the file wpedit-0.4.5.tar.gz.

File metadata

  • Download URL: wpedit-0.4.5.tar.gz
  • Upload date:
  • Size: 18.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for wpedit-0.4.5.tar.gz
Algorithm Hash digest
SHA256 e4594d369a2e469ea5c4b729164ede3b5ef36218053f988082c3a55e896f9328
MD5 7e9376e9f48855957546fe5444f3c043
BLAKE2b-256 1d37173efcd48741c18a0f17d0650d23a582b86723bcd4b37d460a3f7c72a88a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page