Skip to content
This repository was archived by the owner on Sep 25, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,23 @@ See this blog post giving example usage: <http://trentm.com/2012/03/google-code-
# wiki conversion

- <http://code.google.com/p/support/wiki/WikiSyntax>


# convert google wiki to creole

install, e.g.:
```
~$ virtualenv --python=python2 wikiconvert
~$ cd wikiconvert/
~/wikiconvert$ source bin/activate
(wikiconvert)~/wikiconvert$ git clone [email protected]:jedie/googlecode2github.git
(wikiconvert)~/wikiconvert$ pip install python-creole markdown
```

usage, e.g:
```
~$ cd wikiconvert/
~/wikiconvert$ source bin/activate
(wikiconvert)~/wikiconvert$ cd googlecode2github
(wikiconvert)~/wikiconvert$ python googlecode2github.py username/project /path/to/wiki /path/to/new_wiki
```
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That example should show running wik2creole.py right?

What is creole? Is it related to Google Code or GitHub at all?

Cheers,
Trent

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, wiki2creole.py should be used ;)

Creole is a markup: https://en.wikipedia.org/wiki/Creole_(markup) and http://www.wikicreole.org/
You can use it in github wiki ;)

64 changes: 64 additions & 0 deletions wiki2creole.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env python

"""
Usage:
python2 /path/to/wiki2creole.py PROJID SRCDIR DSTDIR

where "PROJID" is the github project id, e.g. "trentm/python-markdown2",
"SRCDIR" is a Google Code project wiki Subversion working copy dir and
"DSTDIR" is the git clone dir of the git project's wiki.
"""

__version__ = "1.0.0"

import sys
import os
import glob
import codecs

import markdown
from creole import html2creole

from wikiconvert import log
from wikiconvert import convert_file as wiki2markdown


def convert_dir(proj_id, src_dir, dst_dir):
if not os.path.isdir(dst_dir):
log("Create %r..." % dst_dir)
os.makedirs(dst_dir)

if os.path.isfile(src_dir):
wiki2creole(proj_id, src_dir, dst_dir)
else:
for f in glob.glob(os.path.join(src_dir, "*.wiki")):
wiki2creole(proj_id, f, dst_dir)



def wiki2creole(proj_id, src_path, dst_dir):
log("\nConvert %r..." % src_path)

gh_page_name, md_file_path = wiki2markdown(proj_id, src_path, dst_dir)

with codecs.open(md_file_path, 'r', 'utf-8') as f:
md_content = f.read()

html = markdown.markdown(md_content)
html=html.replace("<pre><code>", "\n<pre>\n")
html=html.replace("</code></pre>", "</pre>\n")

creole_content = html2creole(html)

creole_path = os.path.join(dst_dir, gh_page_name+".creole")
log("write %r..." % creole_path)
with codecs.open(creole_path, 'w', 'utf-8') as f:
f.write(creole_content)



if __name__ == '__main__':
if len(sys.argv) != 4:
print __doc__
sys.exit(1)
convert_dir(sys.argv[1], sys.argv[2], sys.argv[3])
25 changes: 22 additions & 3 deletions wikiconvert.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ def convert_dir(proj_id, src_dir, dst_dir):
for f in glob(join(src_dir, "*.wiki")):
convert_file(proj_id, f, dst_dir)


def convert_code(m):
code = m.group("code")
code = "\n".join([" %s" % line for line in code.splitlines()])
return "\n%s\n" % code


def convert_file(proj_id, src_path, dst_dir):
src = codecs.open(src_path, 'r', 'utf-8').read()
meta_lines = []
Expand All @@ -55,8 +62,18 @@ def convert_file(proj_id, src_path, dst_dir):
text)

# Code blocks
text = re.compile(r'^{{{+ *\n', re.M).sub(r"```\n", text)
text = re.compile(r'^}}}+ *(\n|$)', re.M).sub(r"```\n", text)
text = re.sub(
r'''
^{{{ \s* $
(?P<code>
(.|\n)+?
)
^}}} \s* $
''',
convert_code,
text,
flags=re.VERBOSE | re.UNICODE | re.MULTILINE
)

# Headings.
text = re.compile(r'^===(.*?)===\s*$', re.M).sub(lambda m: "### %s\n"%m.group(1).strip(), text)
Expand Down Expand Up @@ -126,6 +143,8 @@ def sub_link(m):
codecs.open(dst_path, 'w', 'utf-8').write(text)
log("wrote '%s'" % dst_path)

return gh_page_name, dst_path


#---- internal support stuff

Expand All @@ -134,7 +153,7 @@ def _indent(text):

def _gh_page_name_from_gc_page_name(gc):
"""Github (gh) Wiki page name from Google Code (gc) Wiki page name."""
gh = re.sub(r'([A-Z][a-z]+)', r'-\1', gc)[1:]
gh = re.sub(r'([A-Z][a-z]+)', r'-\1', gc).strip("-")
return gh


Expand Down