Permalink
Browse files

initial release

  • Loading branch information...
0 parents commit 18c16e3166786d5b4dac70b022719e9de93906c8 @claudiosanches committed Dec 16, 2012
@@ -0,0 +1 @@
+*.pyc
@@ -0,0 +1,3 @@
+[
+ { "keys": ["alt+k"], "command": "wordpress_readme_to_markdown" }
+]
@@ -0,0 +1,3 @@
+[
+ { "keys": ["ctrl+super+k"], "command": "wordpress_readme_to_markdown" }
+]
@@ -0,0 +1,3 @@
+[
+ { "keys": ["alt+k"], "command": "wordpress_readme_to_markdown" }
+]
@@ -0,0 +1,6 @@
+[
+ {
+ "caption": "WordPress Readme to Markdown",
+ "command": "wordpress_readme_to_markdown"
+ }
+]
@@ -0,0 +1,10 @@
+[
+ {
+ "id": "edit",
+ "children":
+ [
+ {"id": "wrap"},
+ { "command": "wordpress_readme_to_markdown" }
+ ]
+ }
+]
@@ -0,0 +1,24 @@
+# Sublime Text 2 - Wordpress Readme to Markdown #
+
+Convert WordPress plugin readme files to markdown.
+
+## Features ##
+
+* Converts headings
+* Formats contributors, donate link, etc.
+* Inserts screenshots
+
+## Usage ##
+
+Open the `readme.txt` and press `alt+k` (for Linux or Windows) or `ctrl+super+k` (for Mac).
+
+Is ready, README.md created!
+
+## Sources ##
+
+Inspired by [WP-Readme-to-Github-Markdown](https://github.com/benbalter/WP-Readme-to-Github-Markdown).
+
+## License ##
+
+Licensed under the MIT license.
+[License text](http://opensource.org/licenses/mit-license.php)
@@ -0,0 +1,76 @@
+import sublime
+import sublime_plugin
+import os
+import shutil
+import re
+
+class WordpressReadmeToMarkdownCommand(sublime_plugin.TextCommand):
+
+ def replaceAll(self, search, replace, content):
+ """
+ Finds in all lines and replaces
+ """
+ find = re.compile(search, re.MULTILINE)
+
+ return find.sub(replace, content)
+
+ def getPluginSlug(self, content):
+ """
+ Gets the plugin slug
+ """
+ findName = re.match("""^=== (.+) ===\n""", content)
+ slug = findName.group(1).replace(" ", "-")
+
+ return slug.lower()
+
+ def parseScreenshots(self, content, slug):
+ """
+ Adds link to screenshots
+ """
+ find = re.compile('''== Screenshots ==(.*?)==''', re.MULTILINE|re.DOTALL)
+
+ images = find.search(content)
+
+ if images:
+ for index,line in enumerate(images.group(1).strip().split("""\n""")):
+ content = content.replace(line, \
+ """### %(name)s ###\n![%(name)s](http://s.wordpress.org/extend/plugins/%(slug)s/screenshot-%(index)s.png)\n"""\
+ % {"name": line, "slug": slug, "index": index + 1})
+
+ return content
+
+ def run(self, edit):
+ # Get current file path
+ oldFile = self.view.file_name()
+
+ # Checks if the file is the readme.txt
+ if re.search("""(.+)/readme.txt$""", oldFile):
+
+ # Generate the README.md path
+ newFile = '%s/README.md' % (os.path.dirname(oldFile))
+
+ # Create a new markdown file
+ shutil.copy2(oldFile, newFile)
+
+ getContent = open(newFile, 'r')
+ content = getContent.read()
+
+ # Gets the plugin slug
+ slug = self.getPluginSlug(content)
+
+ content = self.parseScreenshots(content, slug)
+
+ # Replaces the headings
+ content = self.replaceAll("""^(===)+(.+)+(===)\n""", """#\\2#\n""", content)
+ content = self.replaceAll("""^(==)+(.+)+(==)\n""", """##\\2##\n""", content)
+ content = self.replaceAll("""^(=)+(.+)+(=)\n""", """###\\2###\n""", content)
+
+ # Customizes the informations session
+ content = self.replaceAll("""^([^:\n#]+): (.+)$""", """**\\1:** \\2 """, content)
+
+ getContent.close()
+
+ # Write the new content
+ writeContent = open(newFile, 'w')
+ writeContent.write(content)
+ writeContent.close()

0 comments on commit 18c16e3

Please sign in to comment.