From cfdc23f0baa5b749a2e2ef62c4f8f62a37e2f9ee Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Wed, 23 May 2012 16:10:55 +0000 Subject: Export content as HTML SL #3608 Added HTML files to the bundle so this content can be opened with Browse Activity. The old dita/ditamap files are not removed because they are parsed to generate the new HTML files. Besides, the HTML generation uses these dita files to not be too aggressive with the code in this cycle. We will improve this code in the future and we will remove completely the dita generation. --- diff --git a/article.html b/article.html new file mode 100644 index 0000000..f57266a --- /dev/null +++ b/article.html @@ -0,0 +1,9 @@ + + + + %(title)s + + + + %(body)s + diff --git a/parse.py b/parse.py new file mode 100644 index 0000000..96383ac --- /dev/null +++ b/parse.py @@ -0,0 +1,61 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +from gettext import gettext as _ +from BeautifulSoup import BeautifulSoup + + +def parse_dita(dita_str): + soup = BeautifulSoup(dita_str) + + html = open('article.html', 'r').read().decode('utf-8') + + html_tags = [] + + title = soup.find('title').string.strip() + h1_title = '

%(title)s

' % \ + {'title': title} + index_link = '

' + \ + _('Return to index') + '

' + + html_tags.append(index_link) + html_tags.append(h1_title) + + for section in soup.findAll('section'): + for p in section.findAll('p'): + images = p.findAll('image') + for img in images: + html_tags.append('' % \ + {'src': img.get('href')}) + html_tags.append('

') + for ph in p.findAll('ph'): + html_tags.append(ph.string.strip()) + html_tags.append('

') + + html = html % {'title': title, + 'body': '\n'.join(html_tags)} + return html + + +def parse_ditamap(ditamap_str): + soup = BeautifulSoup(ditamap_str) + html = open('article.html', 'r').read().decode('utf-8') + + html_tags = [] + + title = soup.find('map').get('title') + + h1_title = '

%(title)s

' % \ + {'title': title} + html_tags.append(h1_title) + + html_tags.append('
  • ') + for topic in soup.findAll('topicref'): + dita_path = topic.get('href') + html_tags.append('' % \ + {'href': dita_path.replace('.dita', '.html'), + 'name': topic.get('navtitle')}) + html_tags.append('
  • ') + + html = html % {'title': title, + 'body': '\n'.join(html_tags)} + return html diff --git a/xol.py b/xol.py index b5aa1df..6b2a34f 100644 --- a/xol.py +++ b/xol.py @@ -19,6 +19,7 @@ import gtk import zipfile import uuid import logging +import parse from glob import glob from gettext import gettext as _ @@ -152,6 +153,8 @@ def _dita_management(zip, uid, title): 'href="ditastylesheet.xsl"?>') zipstr(zip, os.path.join(uid, 'slicecontent', '%s.dita' % auid), content.prettify()) + zipstr(zip, os.path.join(uid, 'slicecontent', '%s.html' % auid), + parse.parse_dita(content.prettify())) map.append('' % (auid, atitle)) map.append('') @@ -159,12 +162,14 @@ def _dita_management(zip, uid, title): map.append('') zipstr(zip, os.path.join(uid, 'slicecontent', 'librarymap.ditamap'), "\n".join(map)) + zipstr(zip, os.path.join(uid, 'slicecontent', 'librarymap.html'), + parse.parse_ditamap("\n".join(map))) def _index_redirect(zip, uid): """ Creates the redirecting index.html """ - redirect_loc = 'slicecontent/librarymap.ditamap' + redirect_loc = 'slicecontent/librarymap.html' html = ['',\ '',\ -- cgit v0.9.1