Permalink
Browse files

[offline-renderer] allow math images to be disabled

Allows the renderer to include the image generated during parsing
mathematical equations or just the TeX source from the '<img>' 'alt' tag.

Signed-off-by: Christopher Hall <hsw@openmoko.com>
  • Loading branch information...
1 parent 5e72be2 commit 83ac3e45ea5aaec3e3d7d8b5c5aa2ca87c713cfb @hxw hxw committed Mar 29, 2010
Showing with 21 additions and 4 deletions.
  1. +3 −0 Makefile
  2. +16 −4 host-tools/offline-renderer/ArticleRenderer.py
  3. +2 −0 host-tools/offline-renderer/Makefile
View
@@ -292,7 +292,9 @@ RENDER_BLOCK ?= 0
TOTAL_HTML_FILES ?= 27
# rendering compression parameters
+# images are the output of the math turning it to NO will show TeX from 'alt'
ENABLE_LANGUAGES_LINKS ?= YES
+ENABLE_IMAGES ?= YES
ARTICLES_PER_BLOCK ?= 32
ARTICLE_BLOCK_SIZE ?= 262144
@@ -359,6 +361,7 @@ render: fonts validate-destdir
XML_FILES="${XML_FILES_PATH}" RENDER_BLOCK="${RENDER_BLOCK}" \
TOTAL_HTML_FILES="${TOTAL_HTML_FILES}" \
ENABLE_LANGUAGES_LINKS="${ENABLE_LANGUAGES_LINKS}" \
+ ENABLE_IMAGES="${ENABLE_IMAGES}" \
ARTICLES_PER_BLOCK="${ARTICLES_PER_BLOCK}" \
ARTICLE_BLOCK_SIZE="${ARTICLE_BLOCK_SIZE}" \
TEMPDIR="${TEMPDIR_PATH}" \
@@ -118,6 +118,7 @@ def usage(message):
print(' --article-index=file Article index dictionary input [articles.db]')
print(' --prefix=name Device file name portion for .dat/.idx-tmp [pedia]')
print(' --languages-links=<YN> Turn on/off inter-wiki links [YES]')
+ print(' --images=<YN> Turn on/off in-line math images [YES]')
print(' --articles=<N> Articles per block [32]')
print(' --block-size=<bytes> Max size for artical block [262144]')
exit(1)
@@ -145,6 +146,7 @@ def main():
'test=',
'font-path=',
'language-links=',
+ 'images=',
'articles=',
'block-size=',
])
@@ -161,6 +163,7 @@ def main():
font_path = "../fonts"
article_db = None
inter_links = True
+ enable_images = True
articles_per_block = 32
block_size = 262144
@@ -189,6 +192,9 @@ def main():
elif opt in ('-l', '--language-links'):
arg = arg.lower()
inter_links = ('yes' == arg)
+ elif opt in ('-l', '--images'):
+ arg = arg.lower()
+ enable_images = ('yes' == arg)
elif opt in ('-a', '--articles'):
try:
articles_per_block = int(arg)
@@ -249,7 +255,7 @@ def main():
for name in args:
f = codecs.open(name, 'r', 'utf-8', 'replace')
- WrProcess(f, inter_links)
+ WrProcess(f, inter_links, enable_images)
f.close()
for item in font_id_values:
@@ -492,14 +498,15 @@ class WrProcess(HTMLParser.HTMLParser):
READ_BLOCK_SIZE = 64 * (1024 * 1024)
- def __init__ (self, f, inter_links = True):
+ def __init__ (self, f, inter_links = True, enable_images = True):
global g_this_article_title, article_count
HTMLParser.HTMLParser.__init__(self)
self.wordwrap = WordWrap.WordWrap(get_utf8_cwidth)
self.local_init()
self.tag_stack = []
self.inter_links = inter_links
+ self.enable_images = enable_images
self.bucket = bucket.Bucket()
block = f.read(self.READ_BLOCK_SIZE)
while block:
@@ -758,8 +765,13 @@ def handle_starttag(self, tag, attrs):
self.in_br = True
elif tag == 'img' and 'src' in attrs:
- (width, height, data) = get_imgdata(attrs['src'], self.indent)
- self.wordwrap.AppendImage(width, height, data, None)
+ # include either image or the 'alt' text
+ if self.enable_images:
+ (width, height, data) = get_imgdata(attrs['src'], self.indent)
+ self.wordwrap.AppendImage(width, height, data, None)
+ elif 'alt' in attrs:
+ self.handle_data(attrs['alt'])
+
self.in_img = True
@@ -48,6 +48,7 @@ WIKI_FILE_PREFIX ?= wiki
WIKI_LANGUAGE ?= en
WIKI_DIR_SUFFIX ?= pedia
ENABLE_LANGUAGES_LINKS ?= YES
+ENABLE_IMAGES ?= YES
ARTICLES_PER_BLOCK ?= 32
ARTICLE_BLOCK_SIZE ?= 262144
@@ -174,6 +175,7 @@ render: pylzma check-dirs check-fonts check-html
--article-index="${ARTICLES}" \
--prefix="${PREFIX}" \
--language-links="${ENABLE_LANGUAGES_LINKS}" \
+ --images="${ENABLE_IMAGES}" \
--articles="${ARTICLES_PER_BLOCK}" \
--block-size="${ARTICLE_BLOCK_SIZE}" \
"${HTML_ARTICLES}"

0 comments on commit 83ac3e4

Please sign in to comment.