aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConley Owens <cco3@android.com>2012-06-13 08:09:30 -0700
committerandroid code review <noreply-gerritcodereview@google.com>2012-06-13 08:09:31 -0700
commiteb9a57f5a4b1c4a746445a3102ab9cd20792fa5e (patch)
tree71928fa79623b5bd33c33cc04f980b8d1feb6eed
parenta9010f7cdee614ccb3c2a63a8e97bab9e75c44de (diff)
parentb63bdee712261bb431a047a4571dfc1d9e3e4615 (diff)
downloadsource.android.com-tools_r20.tar.gz
Merge "Use python markdown library directly"android-sdk-adt_r20tools_r20
-rwxr-xr-xscripts/build.py28
1 files changed, 13 insertions, 15 deletions
diff --git a/scripts/build.py b/scripts/build.py
index 12bcb986..33a1e330 100755
--- a/scripts/build.py
+++ b/scripts/build.py
@@ -14,21 +14,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import os
+import codecs
import glob
+import markdown
+import os
import shutil
import string
import subprocess
-# call markdown as a subprocess, and capture the output
-def markdown(raw_file):
- extensions = '-x tables -x "toc(title=In This Document)" -x def_list'
- command = 'markdown' + ' ' + extensions + ' ' + raw_file
- p = subprocess.Popen(command, stdout = subprocess.PIPE, shell = True)
- return p.communicate()[0]
-
-
# read just the title (first heading) from a source page
def get_title(raw_file):
for line in open(raw_file, 'r'):
@@ -63,6 +57,11 @@ os.mkdir(HTML_DIR)
category = 'home'
parents = {}
for curdir, subdirs, files in os.walk(SRC_DIR):
+ def md(path):
+ text = codecs.open(path, encoding='utf8').read()
+ extensions = ['tables', 'def_list', 'toc(title=In This Document)']
+ return markdown.markdown(text, extensions)
+
print 'Processing %s...' % (curdir,),
# Step A: split path, and update cached category name if needed
curdir = os.path.normpath(curdir)
@@ -86,19 +85,19 @@ for curdir, subdirs, files in os.walk(SRC_DIR):
parent = ('', '', '')
if 'sidebar.md' in files:
- sidebar = markdown(os.path.join(curdir, 'sidebar.md'))
+ sidebar = md(os.path.join(curdir, 'sidebar.md'))
del files[files.index('sidebar.md')]
else:
sidebar = parent[0]
if 'sidebar2.md' in files:
- sidebar2 = markdown(os.path.join(curdir, 'sidebar2.md'))
+ sidebar2 = md(os.path.join(curdir, 'sidebar2.md'))
del files[files.index('sidebar2.md')]
else:
sidebar2 = parent[1]
if 'sidebar3.md' in files:
- sidebar3 = markdown(os.path.join(curdir, 'sidebar3.md'))
+ sidebar3 = md(os.path.join(curdir, 'sidebar3.md'))
del files[files.index('sidebar3.md')]
else:
sidebar3 = parent[2]
@@ -112,15 +111,14 @@ for curdir, subdirs, files in os.walk(SRC_DIR):
absfilename = os.path.join(curdir, f)
if f.endswith('.md'):
- main = markdown(absfilename)
+ main = md(absfilename)
final = template.safe_substitute(main=main, sidebar=sidebar, sidebar2=sidebar2, \
sidebar3=sidebar3, category=category, title=get_title(absfilename))
- html = file(os.path.join(outdir, f.replace('.md', '.html')), 'w')
+ html = codecs.open(os.path.join(outdir, f.replace('.md', '.html')), 'w', encoding="utf8")
html.write(final)
else:
shutil.copy(absfilename, os.path.join(outdir, f))
print
print 'Done.'
-