You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(44) |
Jul
|
Aug
(6) |
Sep
(1) |
Oct
(1) |
Nov
(1) |
Dec
|
2008 |
Jan
(4) |
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2009 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(5) |
Dec
|
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
2011 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
(4) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(2) |
From: <sto...@us...> - 2011-12-16 22:02:35
|
Revision: 71 http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=71&view=rev Author: storchaka Date: 2011-12-16 22:02:28 +0000 (Fri, 16 Dec 2011) Log Message: ----------- Porting to Python 3. Minimal supporting version is Python 2.6. Modified Paths: -------------- trunk/fb2-python-tools/fb2clean.py trunk/fb2-python-tools/fb2fixtr.py trunk/fb2-python-tools/fb2format.py trunk/fb2-python-tools/fb2maketree.py trunk/fb2-python-tools/progress_display.py Modified: trunk/fb2-python-tools/fb2clean.py =================================================================== --- trunk/fb2-python-tools/fb2clean.py 2011-12-10 21:19:05 UTC (rev 70) +++ trunk/fb2-python-tools/fb2clean.py 2011-12-16 22:02:28 UTC (rev 71) @@ -1,5 +1,5 @@ #!/usr/bin/python -# -*- coding: UTF-8 -*- +# -*- coding: utf-8 -*- '''\ Usage: @@ -14,91 +14,92 @@ File name '-' means standard input. ''' +from __future__ import division, print_function, unicode_literals __author__ = 'Serhiy Storchaka <sto...@us...>' __version__ = '0.2' __all__ = [] import re -import sys, getopt, os, os.path, xml.dom.minidom, codecs +import sys, getopt, os, os.path, xml.dom.minidom, codecs, io -fix_h2_re = re.compile( ur'<h2 xmlns="">Taken: \w*, 1</h2>', re.UNICODE ) -# fix_style_re = re.compile( ur'(<style name="\w*">)|(</style>)' ) -empty_style_re = re.compile( u'|'.join( - ur'<%s/>|</%s><%s>|<%s></%s>' % (tag, tag, tag, tag, tag) +fix_h2_re = re.compile( r'<h2 xmlns="">Taken: \w*, 1</h2>', re.UNICODE ) +# fix_style_re = re.compile( r'(<style name="\w*">)|(</style>)' ) +empty_style_re = re.compile( '|'.join( + r'<%s/>|</%s><%s>|<%s></%s>' % (tag, tag, tag, tag, tag) for tag in ('emphasis', 'strong', 'sub', 'sup') - ) + ur'<style [^>]*/>|<style [^>]*></style>', re.DOTALL ) -start_emphasis = ur'<emphasis>|<strong>|<style [^>]*>|<a [^>]*>' -end_emphasis = ur'</emphasis>|</strong>|</style>|</a>' -fix_emphasis1_re = re.compile( ur'(\s+)(%s)' % end_emphasis, re.UNICODE ) -fix_emphasis2_re = re.compile( ur'(%s)(?=\w)' % end_emphasis, re.UNICODE ) -fix_emphasis3_re = re.compile( ur'([ \u00A0]*[\u2013\u2014-]+)(%s)' % end_emphasis, re.UNICODE ) -mdash_re = re.compile( ur'(?:[ \u00A0]|(?<=[,.?!:"\u2026]))[\u2013\u2014-]+(?:[ \u00A0]|(?=\w)|(?=<[^/]))', re.UNICODE ) -end_mdash_re = re.compile( ur'[ \u00A0][\u2013\u2014-]+[ \u00A0](?:(?=</p>)|(?=</v>)|(?=</subtitle>))' ) -dialog_re = re.compile( ur'(<(?:p|v|subtitle)\b[^>]*>(?:\s*(?:%s))*)\s*[\u2013\u2014-]+\s*' % start_emphasis, re.UNICODE ) -# fix_emphase_re = re.compile( ur'[ \u00A0][\u2013\u2014-][ \u00A0](</emphase>)' ) -empty_line_re = re.compile( ur'<empty-line/>\s*(?=<)(?!<p\b)|(?<=>)(?<!</p>)\s*<empty-line/>', re.UNICODE ) -stars_re = re.compile( u'|'.join( - ur'<%s(?: id="[^">]+")?>(?:%s)* ?(?:[*](?: [*]){2,}|[*]{3,}|x x x) ?(?:%s)*</%s>' % (start, start_emphasis, end_emphasis, end) - for start, end in ((u'p', u'p'), (u'subtitle', u'subtitle'), (ur'/section>\s*<section>\s*<title><p', ur'p>\s*</title')) + ) + r'<style [^>]*/>|<style [^>]*></style>', re.DOTALL ) +start_emphasis = r'<emphasis>|<strong>|<style [^>]*>|<a [^>]*>' +end_emphasis = r'</emphasis>|</strong>|</style>|</a>' +fix_emphasis1_re = re.compile( r'(\s+)(%s)' % end_emphasis, re.UNICODE ) +fix_emphasis2_re = re.compile( r'(%s)(?=\w)' % end_emphasis, re.UNICODE ) +fix_emphasis3_re = re.compile( r'([ \u00A0]*[\u2013\u2014-]+)(%s)' % end_emphasis, re.UNICODE ) +mdash_re = re.compile( r'(?:[ \u00A0]|(?<=[,.?!:"\u2026]))[\u2013\u2014-]+(?:[ \u00A0]|(?=\w)|(?=<[^/]))', re.UNICODE ) +end_mdash_re = re.compile( r'[ \u00A0][\u2013\u2014-]+[ \u00A0](?:(?=</p>)|(?=</v>)|(?=</subtitle>))' ) +dialog_re = re.compile( r'(<(?:p|v|subtitle)\b[^>]*>(?:\s*(?:%s))*)\s*[\u2013\u2014-]+\s*' % start_emphasis, re.UNICODE ) +# fix_emphase_re = re.compile( r'[ \u00A0][\u2013\u2014-][ \u00A0](</emphase>)' ) +empty_line_re = re.compile( r'<empty-line/>\s*(?=<)(?!<p\b)|(?<=>)(?<!</p>)\s*<empty-line/>', re.UNICODE ) +stars_re = re.compile( '|'.join( + r'<%s(?: id="[^">]+")?>(?:%s)* ?(?:[*](?: [*]){2,}|[*]{3,}|x x x) ?(?:%s)*</%s>' % (start, start_emphasis, end_emphasis, end) + for start, end in (('p', 'p'), ('subtitle', 'subtitle'), (r'/section>\s*<section>\s*<title><p', r'p>\s*</title')) ), re.UNICODE|re.DOTALL ) -# defis_str1 = [ur'(?<=\b%s)[\u2013\u2014-][ \u00A0]' % pre for pre in -# (u'по', u'в', u'во', u'из', u'кое')] -# defis_str2 = [ur'([\u2013\u2014-][ \u00A0]|[ \u00A0][\u2013\u2014-])(?=%s\b)' % post for post in -# (u'то', u'нибудь', u'таки', u'либо', u'никак', u'никак(?:ой|им|ом|ая|ую|ое)', u'никак(?:ого|ому)', u'стрит', u'летн(?:ий|им|ем|яя|юю|ей|ее|ии|их)', u'летн(?:его|ему|ими)')] -# # u'й', u'х', u'го', u'е', u'м', u'я', u'мм', u'ка', u'ю', -# fix_defis_re = re.compile( u'|'.join( defis_str1 + defis_str2 ), re.UNICODE|re.IGNORECASE ) +# defis_str1 = [r'(?<=\b%s)[\u2013\u2014-][ \u00A0]' % pre for pre in +# ('по', 'в', 'во', 'из', 'кое')] +# defis_str2 = [r'([\u2013\u2014-][ \u00A0]|[ \u00A0][\u2013\u2014-])(?=%s\b)' % post for post in +# ('то', 'нибудь', 'таки', 'либо', 'никак', 'никак(?:ой|им|ом|ая|ую|ое)', 'никак(?:ого|ому)', 'стрит', 'летн(?:ий|им|ем|яя|юю|ей|ее|ии|их)', 'летн(?:его|ему|ими)')] +# # 'й', 'х', 'го', 'е', 'м', 'я', 'мм', 'ка', 'ю', +# fix_defis_re = re.compile( '|'.join( defis_str1 + defis_str2 ), re.UNICODE|re.IGNORECASE ) -ndash_re = re.compile( ur'(?<=[0-9])[\u2013\u2014-][ \u00A0]?(?=[0-9])' ) -fix_date_re = re.compile( ur'(?<=value=")(?P<y>\d+)\u2013(?P<m>\d+)\u2013(?P<d>\d+)(?=")' ) -fix_date2_re = re.compile( ur'(?P<y>\d+)\u2013(?P<m>\d+)\u2013(?P<d>\d+)(?=</date>)' ) +ndash_re = re.compile( r'(?<=[0-9])[\u2013\u2014-][ \u00A0]?(?=[0-9])' ) +fix_date_re = re.compile( r'(?<=value=")(?P<y>\d+)\u2013(?P<m>\d+)\u2013(?P<d>\d+)(?=")' ) +fix_date2_re = re.compile( r'(?P<y>\d+)\u2013(?P<m>\d+)\u2013(?P<d>\d+)(?=</date>)' ) def fix_ndash( data ): - data = ndash_re.sub( u'\u2013', data ) - data = fix_date_re.sub( ur'\g<y>-\g<m>-\g<d>', data, 2 ) - data = fix_date2_re.sub( ur'\g<y>-\g<m>-\g<d>', data, 2 ) + data = ndash_re.sub( '\u2013', data ) + data = fix_date_re.sub( r'\g<y>-\g<m>-\g<d>', data, 2 ) + data = fix_date2_re.sub( r'\g<y>-\g<m>-\g<d>', data, 2 ) for tag in ('date', 'date', 'id', 'isbn', 'src-ocr'): start = data.find( '<%s>' % tag ) if start >= 0: end = data.find( '</%s>' % tag, start ) - if end >= 0 and data.find( u'\u2013', start, end ) >= 0: - data = data[:start] + data[start:end].replace( u'\u2013', u'-' ) + data[end:] + if end >= 0 and data.find( '\u2013', start, end ) >= 0: + data = data[:start] + data[start:end].replace( '\u2013', '-' ) + data[end:] return data def convert( data ): # Remove <h2> elements - data = fix_h2_re.sub( u'', data ) -# data = fix_style_re.sub( u'', data ) + data = fix_h2_re.sub( '', data ) +# data = fix_style_re.sub( '', data ) # Remove empty inline elements - data = empty_style_re.sub( u'', data ) + data = empty_style_re.sub( '', data ) # Move spaces out emphasis - data = fix_emphasis1_re.sub( ur'\2\1', data ) - data = fix_emphasis2_re.sub( ur'\1 ', data ) - data = fix_emphasis3_re.sub( ur'\2\1', data ) + data = fix_emphasis1_re.sub( r'\2\1', data ) + data = fix_emphasis2_re.sub( r'\1 ', data ) + data = fix_emphasis3_re.sub( r'\2\1', data ) # Again remove empty inline elements - data = empty_style_re.sub( u'', data ) + data = empty_style_re.sub( '', data ) # Correct dash in text - data = mdash_re.sub( u'\u00A0\u2014 ', data ) -# data = data.replace( ur'\u00A0\u2014 \u2013 ', u'\u00A0\u2014 ' ) -# data = fix_emphase_re.sub( ur'\1\u00A0\u2014', data ) + data = mdash_re.sub( '\u00A0\u2014 ', data ) +# data = data.replace( r'\u00A0\u2014 \u2013 ', '\u00A0\u2014 ' ) +# data = fix_emphase_re.sub( r'\1\u00A0\u2014', data ) # Correct dash at end of paragraph - data = end_mdash_re.sub( u'\u00A0\u2014', data ) + data = end_mdash_re.sub( '\u00A0\u2014', data ) # Correct defis -# data = fix_defis_re.sub( u'-', data ) +# data = fix_defis_re.sub( '-', data ) # Correct short dash data = fix_ndash( data ) # Correct dash at start of paragraph - data = dialog_re.sub( u'\\1\u2014\u00A0', data ) + data = dialog_re.sub( '\\1\u2014\u00A0', data ) # Correct ellipsis - data = data.replace( u'...', u'\u2026' ) + data = data.replace( '...', '\u2026' ) # Empty line must be only between paragraphs - data = empty_line_re.sub( u'', data ) + data = empty_line_re.sub( '', data ) # Unificate stars separator - data = stars_re.sub( u'<subtitle>* * *</subtitle>', data ) + data = stars_re.sub( '<subtitle>* * *</subtitle>', data ) # Empty line must be only between paragraphs - data = empty_line_re.sub( u'', data ) + data = empty_line_re.sub( '', data ) return data def writexml( doc, writer, encoding ): @@ -111,12 +112,12 @@ try: opts, args = getopt.getopt( sys.argv[1:], '@:hkqtvV', ['backup', 'help', 'progress', 'version'] ) - except getopt.GetoptError, err: - print >>sys.stderr, 'Error:', err + except getopt.GetoptError as err: + print( 'Error:', err, file = sys.stderr ) sys.exit( 2 ) keepBackup = False - backupSuffix = '.bak' + backupSuffix = str( '.bak' ) verbose = False for option, value in opts: @@ -124,13 +125,13 @@ sys.stdout.write( __doc__ ) sys.exit( 0 ) elif option in ('-V', '--version'): - print __version__ + print( __version__ ) sys.exit( 0 ) elif option == '-@': if value == '-': - args.extend( line.rstrip( '\n' ) for line in sys.stdin ) + args.extend( line.rstrip( str( '\n' ) ) for line in sys.stdin ) else: - args.extend( line.rstrip( '\n' ) for line in open( value ) ) + args.extend( line.rstrip( str( '\n' ) ) for line in open( value ) ) elif option in ('-k', '--backup'): keepBackup = True elif option in ('-v', '--progress'): @@ -143,25 +144,29 @@ global filename for filename in args: try: - if filename == '-': - doc = xml.dom.minidom.parse( sys.stdin ) + if filename == str( '-' ): + if sys.version_info[0] >= 3: + f = sys.stdin.buffer.raw + else: + f = sys.stdin + doc = xml.dom.minidom.parse( f ) else: - doc = xml.dom.minidom.parse( open( filename, 'r' ) ) - encoding = doc.encoding or 'UTF-8' - data0 = doc.toxml( 'UTF-8' ).decode( 'UTF-8' ) + doc = xml.dom.minidom.parse( open( filename, 'rb' ) ) + encoding = doc.encoding or str( 'utf-8' ) + data0 = doc.toxml( 'utf-8' ).decode( 'utf-8' ) data = convert( data0 ) if data != data0: - doc = xml.dom.minidom.parseString( data.encode( 'UTF-8' ) ) - if filename == '-': + doc = xml.dom.minidom.parse( io.BytesIO( data.encode( 'utf-8' ) ) ) + if filename == str( '-' ): writexml( doc, sys.stdout, encoding ) else: - tmpfilename = filename + '.tmp' - writexml( doc, open( tmpfilename, 'w' ), encoding ) + tmpfilename = filename + str( '.tmp' ) + writexml( doc, open( tmpfilename, 'wb' ), encoding ) if keepBackup: os.rename( filename, filename + backupSuffix ) os.rename( tmpfilename, filename ) except (KeyboardInterrupt, SystemExit): raise - except Exception, err: - print >>sys.stderr, 'Error processing "%s":' % filename - print >>sys.stderr, err + except Exception as err: + print( str( 'Error processing "%s":' ) % filename, file = sys.stderr ) + print( err, file = sys.stderr ) Modified: trunk/fb2-python-tools/fb2fixtr.py =================================================================== --- trunk/fb2-python-tools/fb2fixtr.py 2011-12-10 21:19:05 UTC (rev 70) +++ trunk/fb2-python-tools/fb2fixtr.py 2011-12-16 22:02:28 UTC (rev 71) @@ -1,5 +1,5 @@ #!/usr/bin/python -# -*- coding: UTF-8 -*- +# -*- coding: utf-8 -*- '''\ Fix some frequent OCR and conversion errors in FictionBook2 files. @@ -20,36 +20,38 @@ File name '-' means standard input. ''' + +from __future__ import division, print_function, unicode_literals __author__ = 'Serhiy Storchaka <sto...@us...>' __version__ = '0.2' __all__ = [] import string, re -import sys, getopt, os, os.path, xml.dom.minidom, codecs +import sys, getopt, os, os.path, xml.dom.minidom, codecs, io quick = False -rus_lowercase = u'абвгдеёжзийклмнопрстуфхцчшщъыьэюя' +rus_lowercase = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя' rus_uppercase = rus_lowercase.upper() rus_letters = rus_lowercase + rus_uppercase -cyr_lowercase = rus_lowercase + u'іїєґ' +cyr_lowercase = rus_lowercase + 'іїєґ' cyr_uppercase = cyr_lowercase.upper() cyr_letters = cyr_lowercase + cyr_uppercase -rus_tr = u'аАВсСеЕНКМпоОрРгТихХу' -rus_lat_tr = u'aABcCeEHKMnoOpPrTuxXy' -cyr_tr = u'аАВсСеЕНіІКМпоОрРгТихХу' -cyr_lat_tr = u'aABcCeEHiIKMnoOpPrTuxXy' +rus_tr = 'аАВсСеЕНКМпоОрРгТихХу' +rus_lat_tr = 'aABcCeEHKMnoOpPrTuxXy' +cyr_tr = 'аАВсСеЕНіІКМпоОрРгТихХу' +cyr_lat_tr = 'aABcCeEHiIKMnoOpPrTuxXy' lat2cyr = dict( zip( cyr_letters + cyr_lat_tr, cyr_letters + cyr_tr ) ) cyr2lat = dict( zip( string.ascii_letters + cyr_tr, string.ascii_letters + cyr_lat_tr ) ) -num2cyr = {u'0': u'О', u'3': u'З', u'6': u'б'} +num2cyr = {'0': 'О', '3': 'З', '6': 'б'} -word_re = re.compile( ur'([\w]+)', re.UNICODE ) +word_re = re.compile( r'([\w]+)', re.UNICODE ) def maketest( chars ): - return re.compile( ur'\A[' + chars + ur']+\Z', re.UNICODE ).match + return re.compile( r'\A[' + chars + r']+\Z', re.UNICODE ).match # islat = maketest( string.ascii_letters ) islat = maketest( string.ascii_letters + '_' ) @@ -61,14 +63,14 @@ ispseudolat = maketest( string.ascii_letters + rus_tr ) ispseudorus = maketest( rus_letters + rus_lat_tr ) ispseudocyr = maketest( cyr_letters + cyr_lat_tr ) -isrusJ = maketest( rus_letters + u'\u0408' ) -isnumber = re.compile( ur'\A\d+\Z', re.UNICODE ).match -isroman = re.compile( ur'\A(?:M{0,3})(?:D?C{0,3}|C[DM])(?:L?X{0,3}|X[LC])(?:V?I{0,3}|I[VX])\Z' ).match -beginnumber_re = re.compile( ur'\A([0-9]+)(\w+)\Z', re.UNICODE ) -endnumber_re = re.compile( ur'\A(\w+?)([0-9]+)\Z', re.UNICODE ) -iscross = re.compile( ur'\A[0-9]+(?:х[0-9]+)+\Z' ).match +isrusJ = maketest( rus_letters + '\u0408' ) +isnumber = re.compile( r'\A\d+\Z', re.UNICODE ).match +isroman = re.compile( r'\A(?:M{0,3})(?:D?C{0,3}|C[DM])(?:L?X{0,3}|X[LC])(?:V?I{0,3}|I[VX])\Z' ).match +beginnumber_re = re.compile( r'\A([0-9]+)(\w+)\Z', re.UNICODE ) +endnumber_re = re.compile( r'\A(\w+?)([0-9]+)\Z', re.UNICODE ) +iscross = re.compile( r'\A[0-9]+(?:х[0-9]+)+\Z' ).match -hasdigits = re.compile( ur'\A.*[0-9].*\Z', re.UNICODE ).match +hasdigits = re.compile( r'\A.*[0-9].*\Z', re.UNICODE ).match def tocyr( word ): return ''.join( lat2cyr[c] for c in word ) @@ -76,10 +78,10 @@ def tolat( word ): return ''.join( cyr2lat[c] for c in word ) -def readlist( f ): - for line in f: - line = line.rstrip( '\n' ).decode( 'utf-8' ) - if len( line ) > 0 and line[0] != '#': +def readlist( fname ): + for line in io.open( fname, 'rt', encoding = 'utf-8' ): + line = line.rstrip( '\n' ) + if line and line[0] != '#': yield line reserved_tr = set() @@ -91,11 +93,11 @@ translates = {} try: - translates.update( line.split( ' ', 1 ) for line in readlist( open( 'replaces' ) ) ) + translates.update( line.split( ' ', 1 ) for line in readlist( 'replaces' ) ) except: pass try: - translates.update( (w, w) for w in readlist( open( 'reserved' ) ) ) + translates.update( (w, w) for w in readlist( 'reserved' ) ) except: pass @@ -103,7 +105,9 @@ global filename def logtr( word, type, *args ): if logfile: - print >>logfile, '%s:' % filename, word.encode( 'utf-8' ), type, ' '.join( args ).encode( 'utf-8' ) + # hack for Python 2.x + fn = filename.decode( 'utf-8' ) if isinstance( filename, bytes ) else filename + print( '%s:' % fn, word, type, *args, file = logfile ) def tryconv( s, e1, e2 ): try: @@ -131,7 +135,7 @@ if cyr_word in reserved_tr and lat_word not in reserved_tr: return cyr_word # Только кириллическа 'Н' заменена на латинскую 'H' -- шуточки FIDO - if iscyr( word.replace( u'H', u'Н' ) ): + if iscyr( word.replace( 'H', 'Н' ) ): return cyr_word # Неопределённость @@ -156,16 +160,16 @@ m = endnumber_re.match( word ) if m and not hasdigits( m.group( 1 ) ): # Метки часто содержат в себе номер - if m.group( 1 ) in (ur'note', ur'note_', ur'Note', ur'footnote', ur'child_', ur'FbAutId_', ur'comment_', ur'text_', ur'N', ur'N_', ur'No'): + if m.group( 1 ) in (r'note', r'note_', r'Note', r'footnote', r'child_', r'FbAutId_', r'comment_', r'text_', r'N', r'N_', r'No'): return word - + # Между словом и номером пропущен пробел - if m.group( 1 ) in (ur'Глава', ur'ГЛАВА', ur'глава'): - return m.expand( ur'\1 \2' ) + if m.group( 1 ) in (r'Глава', r'ГЛАВА', r'глава'): + return m.expand( r'\1 \2' ) # Начальная единица года распозналась как 'I" - if re.match( ur'\AI[89][0-9][0-9]\Z', word ): - return u'1' + word[1:] + if re.match( r'\AI[89][0-9][0-9]\Z', word ): + return '1' + word[1:] # Просто собираем статистику logtr( word, '!' ) return word @@ -174,34 +178,34 @@ m = beginnumber_re.match( word ) if m and not hasdigits( m.group( 2 ) ): # Физические единицы отделяем неразрывным пробелом - if m.group( 2 ) in (u'гг', u'мг', u'г', u'кг', u'мл', u'л', u'ч', u'мм', u'см', u'дм', u'м', u'км' ): - return m.expand( u'\\1\u00A0\\2' ) + if m.group( 2 ) in ('гг', 'мг', 'г', 'кг', 'мл', 'л', 'ч', 'мм', 'см', 'дм', 'м', 'км' ): + return m.expand( '\\1\u00A0\\2' ) # Русские окончания отделяем дефисом - if m.group( 2 ) in (u'ый', u'ой', u'й', u'ым', u'ом', u'я', u'ая', u'е', u'ое', u'го', u'ого', u'ю', u'ую'): - return m.expand( ur'\1-\2' ) + if m.group( 2 ) in ('ый', 'ой', 'й', 'ым', 'ом', 'я', 'ая', 'е', 'ое', 'го', 'ого', 'ю', 'ую'): + return m.expand( r'\1-\2' ) # А английские оставляем так if m.group( 2 ) in ('st', 'nd', 'rd', 'th', 's', 'd', 'ff', 'mm', 'cm', 'mm', 'km', 'unt', 'cc', 'F'): return word - if word[0] in u'036' and ( iscyrlower( word[1:] ) or iscyrupper( word[1:] ) ): + if word[0] in '036' and ( iscyrlower( word[1:] ) or iscyrupper( word[1:] ) ): return num2cyr[word[0]] + word[1:] # Иначе просто собираем статистику logtr( word, '!' ) return word # Начальная единица распозналась как 'I" - m = re.match( ur'\AI[0-9]+(?:st|nd|rd|th|s|d)\Z', word ) + m = re.match( r'\AI[0-9]+(?:st|nd|rd|th|s|d)\Z', word ) if m: - return u'1' + word[1:] + return '1' + word[1:] # Возможно цифра -- на самом деле буква. # Дело тёмное и рискованное. - word2 = word.replace( u'ь1', u'ы' ).replace( u'Ь1', u'Ы' ) + word2 = word.replace( 'ь1', 'ы' ).replace( 'Ь1', 'Ы' ) if word2 != word: if ispseudorus( word2 ): return tocyr( word2 ) - if re.search( ur'6[аеиоуaeuoy]|[аеиоуaeuoy]6', word ): - word2 = word.replace( u'6', u'б' ) + if re.search( r'6[аеиоуaeuoy]|[аеиоуaeuoy]6', word ): + word2 = word.replace( '6', 'б' ) if ispseudorus( word2 ): return tocyr( word2 ) @@ -218,31 +222,31 @@ # Слово состоит из кириллических букв и похожих на кириллические и содержит i с точкой # Явно (псевдо)украинское или старорусское - if (u'i' in word or u'I' in word) and ispseudocyr( word ): + if ('i' in word or 'I' in word) and ispseudocyr( word ): # Часто 'п', за которой следуют 'о' или 'е' неправильно распознаётся - word2 = re.sub( u'^ii|^[гт]i(?=о)|[гi]i(?=[еоeo])', u'п', word ) + word2 = re.sub( '^ii|^[гт]i(?=о)|[гi]i(?=[еоeo])', 'п', word ) # Также начальные 'Ш' и 'П' - word2 = re.sub( u'^III', u'Ш', word2 ) - word2 = re.sub( u'^II', u'П', word2 ) + word2 = re.sub( '^III', 'Ш', word2 ) + word2 = re.sub( '^II', 'П', word2 ) # Украинское окончание - word2 = re.sub( u'ii$', u'ії', word2 ) - word2 = re.sub( u'II$', u'ІЇ', word2 ) + word2 = re.sub( 'ii$', 'ії', word2 ) + word2 = re.sub( 'II$', 'ІЇ', word2 ) word2 = tocyr( word2 ) return word2 # Слово состоит из русских букв и непонятного символа, похожего на J. # На самом деле это 'ё' - if u'\u0408' in word and isrusJ( word ) and word.replace( u'\u0408', u'' ): - return word.replace( u'\u0408', u'ё' ) + if '\u0408' in word and isrusJ( word ) and word.replace( '\u0408', '' ): + return word.replace( '\u0408', 'ё' ) # Слетевшая кодировка для кавычек-ёлочек - if word[0] == u'\u0458' and isrus( word[1:] ): - return u'\xab' + word[1:] - if word[-1] == u'\u0405' and isrus( word[:-1] ): - return word[:-1] + u'\xbb' + if word[0] == '\u0458' and isrus( word[1:] ): + return '\xab' + word[1:] + if word[-1] == '\u0405' and isrus( word[:-1] ): + return word[:-1] + '\xbb' # Для обозначения ударения в русском слове использованы диакритические знаки. - for c in u'áéúóý': - if isrus( word.replace( c, u'' ) ): + for c in 'áéúóý': + if isrus( word.replace( c, '' ) ): return word # Возможно оригинальный текст был в европейской кодировке iso-8859-15, @@ -260,26 +264,26 @@ logtr( word, '!' ) return word -utf_illegal_pref_re = re.compile( u'\u0432\u0402(?:\ufffd|[\u2000-\u203f])?', re.DOTALL ) +utf_illegal_pref_re = re.compile( '\u0432\u0402(?:\ufffd|[\u2000-\u203f])?', re.DOTALL ) def fix_utf_illegal_pref( m ): data = m.group() - if data == u'\u0432\u0402' or data == u'\u0432\u0402\ufffd': - return u'\u2018' + if data == '\u0432\u0402' or data == '\u0432\u0402\ufffd': + return '\u2018' return data.encode( 'cp1251' ).decode( 'utf-8' ) def fixtr_text( text ): global quick changed = False - if u'\u0432\u0402' in text: #'вЂ' + if '\u0432\u0402' in text: #'вЂ' # Указана кодировка cp1251, а на самом деле -- utf-8 text = utf_illegal_pref_re.sub( fix_utf_illegal_pref, text ) changed = True # Символы номера и копирайта, оставшиеся с HTML - text = text.replace( u'№', u'\u2116' ) - text = text.replace( u'©', u'\xa9' ) + text = text.replace( '№', '\u2116' ) + text = text.replace( '©', '\xa9' ) # Разбиваем текст на слова и обрабатываем их по отдельности. # Потом склеиваем. @@ -302,7 +306,7 @@ changed = True if changed: - text = u''.join( words ) + text = ''.join( words ) return text @@ -324,7 +328,7 @@ reserved_tr.add( word ) def read_trdict( fname ): - for word in readlist( open( fname ) ): + for word in readlist( fname ): update_trdict( word ) tword = word[0].upper() + word[1:] if tword != word: @@ -343,12 +347,12 @@ try: opts, args = getopt.getopt( sys.argv[1:], '@:d:hko:qTvV', ['backup', 'dictionary=', 'help', 'log-file', 'progress', 'quick', 'text', 'version'] ) - except getopt.GetoptError, err: - print >>sys.stderr, 'Error:', err + except getopt.GetoptError as err: + print( 'Error:', err, file = sys.stderr ) sys.exit( 2 ) keepBackup = False - backupSuffix = '.bak' + backupSuffix = str( '.bak' ) verbose = False plainText = False @@ -357,13 +361,13 @@ sys.stdout.write( __doc__ ) sys.exit( 0 ) elif option in ('-V', '--version'): - print __version__ + print( __version__ ) sys.exit( 0 ) elif option == '-@': if value == '-': - args.extend( line.rstrip( '\n' ) for line in sys.stdin ) + args.extend( line.rstrip( str( '\n' ) ) for line in sys.stdin ) else: - args.extend( line.rstrip( '\n' ) for line in open( value ) ) + args.extend( line.rstrip( str( '\n' ) ) for line in open( value ) ) elif option in ('-k', '--backup'): keepBackup = True elif option in ('-q', '--quick'): @@ -373,7 +377,7 @@ elif option in ('-T', '--text'): plainText = True elif option in ('-o', '--log-file'): - logfile = open( value, 'w' ) + logfile = io.open( value, 'wt', encoding = 'utf-8' ) elif option in ('-d', '--dictionary'): read_trdict( value ) @@ -386,40 +390,53 @@ try: if plainText: # Process plain text in UTF-8 - if filename == '-': - data0 = sys.stdin.read().decode( 'UTF-8' ) - data = fixtr_text( data0 ) - sys.stdout.write( data.encode( 'UTF-8' ) ) + if filename == str( '-' ): + if sys.version_info[0] >= 3: + data0 = sys.stdin.read() + data = fixtr_text( data0 ) + sys.stdout.write( data ) + else: + data0 = sys.stdin.read().decode( 'utf-8' ) + data = fixtr_text( data0 ) + sys.stdout.write( data.encode( 'utf-8' ) ) else: - data0 = open( filename, 'r' ).read().decode( 'UTF-8' ) + data0 = io.open( filename, 'rt', encoding = 'utf-8' ) data = fixtr_text( data0 ) if data != data0: - tmpfilename = filename + '.tmp' - open( tmpfilename, 'w' ).write( data.encode( 'UTF-8' ) ) + tmpfilename = filename + str( '.tmp' ) + io.open( tmpfilename, 'wt', encoding = 'utf-8' ).write( data ) if keepBackup: os.rename( filename, filename + backupSuffix ) os.rename( tmpfilename, filename ) else: # Process FB2 - if filename == '-': - doc = xml.dom.minidom.parse( sys.stdin ) - encoding = doc.encoding or 'UTF-8' + if filename == str( '-' ): + if sys.version_info[0] >= 3: + f = sys.stdin.buffer.raw + else: + f = sys.stdin + doc = xml.dom.minidom.parse( f ) + encoding = doc.encoding or str( 'utf-8' ) fixtr_fb2( doc ) - writexml( doc, sys.stdout, encoding ) + if sys.version_info[0] >= 3: + f = sys.stdout.buffer.raw + else: + f = sys.stdout + writexml( doc, f, encoding ) else: - doc = xml.dom.minidom.parse( open( filename, 'r' ) ) - encoding = doc.encoding or 'UTF-8' + doc = xml.dom.minidom.parse( open( filename, 'rb' ) ) + encoding = doc.encoding or str( 'utf-8' ) if fixtr_fb2( doc ): - tmpfilename = filename + '.tmp' - writexml( doc, open( tmpfilename, 'w' ), encoding ) + tmpfilename = filename + str( '.tmp' ) + writexml( doc, open( tmpfilename, 'wb' ), encoding ) if keepBackup: os.rename( filename, filename + backupSuffix ) os.rename( tmpfilename, filename ) except (KeyboardInterrupt, SystemExit): raise - except Exception, err: - print >>sys.stderr, 'Error processing "%s":' % filename - print >>sys.stderr, err + except Exception as err: + print( str( 'Error processing "%s":' ) % filename, file = sys.stderr ) + print( err, file = sys.stderr ) raise if logfile: Modified: trunk/fb2-python-tools/fb2format.py =================================================================== --- trunk/fb2-python-tools/fb2format.py 2011-12-10 21:19:05 UTC (rev 70) +++ trunk/fb2-python-tools/fb2format.py 2011-12-16 22:02:28 UTC (rev 71) @@ -1,5 +1,5 @@ #!/usr/bin/python -# -*- coding: UTF-8 -*- +# -*- coding: utf-8 -*- '''\ Usage: @@ -19,6 +19,7 @@ File name '-' means standard input. ''' +from __future__ import division, print_function, unicode_literals __author__ = 'Serhiy Storchaka <sto...@us...>' __version__ = '0.2' @@ -29,47 +30,47 @@ pass import re, base64 -import sys, getopt, os, os.path, xml.dom.minidom, codecs, cStringIO +import sys, getopt, os, os.path, xml.dom.minidom, codecs, io -_spaces_re = re.compile( r'[ \t\r\n]{2,}|[\t\r\n]' ) -_empty_element_re = re.compile( r'<([^ >]+)([^>]*)(?<!/)></\1>' ) +_spaces_re = re.compile( br'[ \t\r\n]{2,}|[\t\r\n]' ) +_empty_element_re = re.compile( br'<([^ >]+)([^>]*)(?<!/)></\1>' ) def _make_tags_switch( tags ): - return re.compile( '(%s)' % '|'.join( '<%s(?: [^>]*)?>.*?</%s>' % (tag, tag) for tag in tags ), re.DOTALL ) -_text_re = _make_tags_switch( ('p', 'v', 'subtitle', 'text-author', 'th', 'td') ) -_oneline_re = _make_tags_switch( ('title', 'author', 'translator') ) -_binary_re = re.compile( '(<binary [^>]*>)([^<]*)(</binary>)', re.DOTALL ) + return re.compile( b'(' + b'|'.join( b'<' + tag + b'(?: [^>]*)?>.*?</' + tag + b'>' for tag in tags ) + b')', re.DOTALL ) +_text_re = _make_tags_switch( (b'p', b'v', b'subtitle', b'text-author', b'th', b'td') ) +_oneline_re = _make_tags_switch( (b'title', b'author', b'translator') ) +_binary_re = re.compile( b'(<binary [^>]*>)([^<]*)(</binary>)', re.DOTALL ) def _remove_eols( m ): - return m.group().replace( '\n', '' ) + return m.group().replace( b'\n', b'' ) def _binary_squeeze( m ): - return m.group( 1 ) + m.group( 2 ).replace( ' ', '' ) + m.group( 3 ) + return m.group( 1 ) + m.group( 2 ).replace( b' ', b'' ) + m.group( 3 ) def _binary_recode( m ): - return m.group( 1 ) + base64.encodestring( base64.decodestring( m.group( 2 ) ) ) + m.group( 3 ) + return m.group( 1 ) + base64.b64encode( base64.b64decode( m.group( 2 ) ) ) + m.group( 3 ) def _squeeze_tag( s ): if _text_re.match( s ): return s else: - return _empty_element_re.sub( r'<\1\2/>', s.strip( ' ' ).replace( '> ', '>' ).replace( ' <', '<' ) ) + return _empty_element_re.sub( br'<\1\2/>', s.strip( b' ' ).replace( b'> ', b'>' ).replace( b' <', b'<' ) ) def _format_tag( s ): if _text_re.match( s ): return s else: - return _empty_element_re.sub( r'<\1\2/>', s.strip( ' ' ).replace( '> ', '>' ).replace( ' <', '<' ) ).replace( '><', '>\n<' ) + return _empty_element_re.sub( br'<\1\2/>', s.strip( b' ' ).replace( b'> ', b'>' ).replace( b' <', b'<' ) ).replace( b'><', b'>\n<' ) def fb2format( data, squeeze = False, squeezeBinary = False ): - data = _spaces_re.sub( ' ', data ) + data = _spaces_re.sub( b' ', data ) if squeeze: - data = ''.join( _squeeze_tag( s ) for s in _text_re.split( data ) ) - data = data.replace( '>', '>\n', 1 ) + data = b''.join( _squeeze_tag( s ) for s in _text_re.split( data ) ) + data = data.replace( b'>', b'>\n', 1 ) else: - data = '\n'.join( s for s in (_format_tag( s ) for s in _text_re.split( data )) if s ) + data = b'\n'.join( s for s in (_format_tag( s ) for s in _text_re.split( data )) if s ) data = _oneline_re.sub( _remove_eols, data ) - data = data.replace( '>\n<title>', '><title>' ) + data = data.replace( b'>\n<title>', b'><title>' ) if squeezeBinary or squeeze: data = _binary_re.sub( _binary_squeeze, data ) @@ -83,8 +84,8 @@ try: opts, args = getopt.getopt( sys.argv[1:], '@:be:fhksvV', ['backup', 'encoding=', 'format', 'help', 'progress', 'squeeze', 'squeeze-binaries', 'version'] ) - except getopt.GetoptError, err: - print >>sys.stderr, 'Error:', err + except getopt.GetoptError as err: + print( 'Error:', err, file = sys.stderr ) sys.exit( 2 ) forceEncoding = None @@ -100,11 +101,11 @@ sys.stdout.write( __doc__ ) sys.exit( 0 ) elif option in ('-V', '--version'): - print __version__ + print( __version__ ) sys.exit( 0 ) elif option == '-@': if value == '-': - args.extend( line.rstrip( '\n' ) for line in sys.stdin ) + args.extend( line.rstrip( str( '\n' ) ) for line in sys.stdin ) else: args.extend( line.rstrip( '\n' ) for line in open( value ) ) elif option in ('-e', '--encoding'): @@ -127,14 +128,18 @@ for filename in args: try: - if filename == '-': - data0 = sys.stdin.read() + if filename == str( '-' ): + if sys.version_info[0] >= 3: + f = sys.stdin.buffer.raw + else: + f = sys.stdin + data0 = f.read() else: - data0 = open( filename, 'r' ).read() + data0 = open( filename, 'rb' ).read() - doc = xml.dom.minidom.parseString( data0 ) - encoding = forceEncoding or doc.encoding or 'UTF-8' - writer = cStringIO.StringIO() + doc = xml.dom.minidom.parse( io.BytesIO( data0 ) ) + encoding = forceEncoding or doc.encoding or str( 'utf-8' ) + writer = io.BytesIO() writer = codecs.getwriter( encoding )( writer, 'xmlcharrefreplace' ) doc.writexml( writer, encoding = encoding ) data = writer.getvalue() @@ -143,16 +148,20 @@ if format: data = fb2format( data, squeeze = squeeze, squeezeBinary = squeezeBinary ) - if filename == '-': - sys.stdout.write( data ) + if filename == str( '-' ): + if sys.version_info[0] >= 3: + f = sys.stdout.buffer.raw + else: + f = sys.stdout + f.write( data ) elif data != data0: - tmpfilename = filename + '.tmp' - open( tmpfilename, 'w' ).write( data ) - if keepBackup: - os.rename( filename, filename + backupSuffix ) - os.rename( tmpfilename, filename ) + tmpfilename = filename + str( '.tmp' ) + open( tmpfilename, 'wb' ).write( data ) + if keepBackup: + os.rename( filename, filename + backupSuffix ) + os.rename( tmpfilename, filename ) except (KeyboardInterrupt, SystemExit): raise - except Exception, err: - print >>sys.stderr, 'Error processing "%s":' % filename - print >>sys.stderr, err + except Exception as err: + print( str( 'Error processing "%s":' ) % filename, file = sys.stderr ) + print( err, file = sys.stderr ) Modified: trunk/fb2-python-tools/fb2maketree.py =================================================================== --- trunk/fb2-python-tools/fb2maketree.py 2011-12-10 21:19:05 UTC (rev 70) +++ trunk/fb2-python-tools/fb2maketree.py 2011-12-16 22:02:28 UTC (rev 71) @@ -1,5 +1,5 @@ #!/usr/bin/env python -# -*- coding: UTF-8 -*- +# -*- coding: utf-8 -*- '''\ Usage: @@ -17,6 +17,7 @@ File name '-' means standard input. ''' +from __future__ import division, print_function, unicode_literals __author__ = 'Serhiy Storchaka <sto...@us...>' __version__ = '0.2' __all__ = [] @@ -30,6 +31,11 @@ filesystemencoding = sys.getfilesystemencoding() # filesystemencoding = 'utf-8' +def warn( tag, path ): + # hack for Python 2.x + if isinstance( path, bytes ): + path = path.encode( filesystemencoding ) + print( tag, path ) def genname( dirname, filename, otherpath = None ): filename = filename.replace( '"', "'" ) @@ -40,8 +46,8 @@ try: if not os.path.exists( dirname ): os.makedirs( dirname ) - except os.error, err: - print >>sys.stderr, err + except os.error as err: + print( err, file = sys.stderr ) pass count = 0 path = os.path.join( dirname, filename ) @@ -50,19 +56,19 @@ if os.path.samefile( path, otherpath ): return None if filecmp.cmp( path, otherpath, 0 ): - print '#', path.encode( filesystemencoding ) + warn( '#', path ) return None count += 1 path = os.path.join( dirname, '%s__%d%s' % (basename, count, suffix) ) if count > 0: - print '!', path.encode( filesystemencoding ) + warn( '!', path ) return path def mklink( src, dst ): try: os.link( src, dst ) - except OSError, err: - print '@', dst.encode( filesystemencoding ) + except OSError as err: + warn( '@', dst ) os.symlink( src, dst ) def linkauthors( path, authornames, book_title ): @@ -83,14 +89,14 @@ authorname += ' [%s]' % nickname return authorname -xml_re = re.compile( r'<\?xml version="(?:[^">]*)" encoding="(?:[^">]*)"\?>', re.DOTALL ) -desc_re = re.compile( r'<description>.*?</description>', re.DOTALL ) +xml_re = re.compile( br'<\?xml version="(?:[^">]*)" encoding="(?:[^">]*)"\?>', re.DOTALL ) +desc_re = re.compile( br'<description>.*?</description>', re.DOTALL ) if __name__ == '__main__': try: opts, args = getopt.getopt( sys.argv[1:], '@:hf:o:svV', ['help', 'format=', 'output=', 'symbolic', 'version', 'progress'] ) - except getopt.GetoptError, err: - print >>sys.stderr, 'Error:', err + except getopt.GetoptError as err: + print( 'Error:', err, file = sys.stderr ) sys.exit( 2 ) outputdir = '.' verbose = False @@ -100,13 +106,13 @@ sys.stdout.write( __doc__ ) sys.exit( 0 ) elif option in ('-V', '--version'): - print __version__ + print( __version__ ) sys.exit( 0 ) elif option == '-@': if value == '-': - args.extend( line.rstrip( '\n' ) for line in sys.stdin ) + args.extend( line.rstrip( str( '\n' ) ) for line in sys.stdin ) else: - args.extend( line.rstrip( '\n' ) for line in open( value ) ) + args.extend( line.rstrip( str( '\n' ) ) for line in open( value ) ) elif option in ('-v', '--progress'): verbose = True elif option in ('-f', '--format'): @@ -123,24 +129,23 @@ for fb2name in args: srcpath = os.path.abspath( fb2name ) #if verbose: - # print fb2name + # print( fb2name ) try: - f = open( srcpath ) - data = '' - while True: - data += f.read( 1 << 13 ) - try: - doc = xml_re.match( data ).group() + '\n' + desc_re.search( data ).group() - except AttributeError: - continue - break - f.close() - doc = doc.replace( 'xlink:href=', 'href=' ).replace( 'l:href=', 'href=' ) + with open( srcpath, 'rb' ) as f: + data = b'' + while True: + data += f.read( 1 << 13 ) + try: + doc = xml_re.match( data ).group() + b'\n' + desc_re.search( data ).group() + except AttributeError: + continue + break + doc = doc.replace( b'xlink:href=', b'href=' ).replace( b'l:href=', b'href=' ) try: description = xml.etree.ElementTree.fromstring( doc ) except: - print doc + print( doc ) raise title_info = description.find( 'title-info' ) @@ -178,7 +183,7 @@ linkauthors( path, authornames, book_title ) elif format == 'series': for sequence_name, sequence_number, sequence_src_name in sequences: - dirname = sequence_name + dirname = sequence_name or '-' if sequence_src_name: dirname += ' [%s]' % sequence_src_name dirname += ' : ' + authornames_str @@ -214,7 +219,7 @@ mklink( srcpath, path ) except (KeyboardInterrupt, SystemExit): raise - except Exception, err: - print >>sys.stderr, 'Error processing "%s":' % fb2name - print >>sys.stderr, err + except Exception as err: + print( str( 'Error processing "%s":' ) % fb2name, file = sys.stderr ) + print( err, file = sys.stderr ) sys.exit( 1 ) Modified: trunk/fb2-python-tools/progress_display.py =================================================================== --- trunk/fb2-python-tools/progress_display.py 2011-12-10 21:19:05 UTC (rev 70) +++ trunk/fb2-python-tools/progress_display.py 2011-12-16 22:02:28 UTC (rev 71) @@ -1,4 +1,5 @@ -# emacs-mode: -*- python-*- +# -*- coding: utf-8 -*- +from __future__ import division, print_function, unicode_literals try: import psyco psyco.full() @@ -7,21 +8,21 @@ import sys, time class progress_display: - def __init__( self, expected_count, width = 75, fout = sys.stderr ): + def __init__( self, expected_count, width = 75, file = sys.stderr ): self.__start = time.time() self.__expected_count = expected_count self.__count = 0 self.__width = width - 25 - - self.__fout = fout + + self.__file = file self.__progress( 0, 0 ) def next( self, increment = 1 ): self.__count += increment - self.__progress( float( self.__count ) / self.__expected_count, time.time() - self.__start ) + self.__progress( self.__count / self.__expected_count, time.time() - self.__start ) def close( self ): - print >>self.__fout + print( file = self.__file ) def __progress( self, perc, delta ): estimated = round( perc and delta / perc ) @@ -30,9 +31,11 @@ bar = '|' + '#' * int( width * perc ) + '.' * ( width - int( width * perc ) ) + '|' else: bar = '' - self.__fout.write( '\r%s%3d%% %s/%s' % ( bar, int( 100 * perc ), time.strftime( '%X', time.gmtime( round( delta ) ) ), time.strftime( '%X', time.gmtime( estimated ) ) ) ) + self.__file.write( '\r%s%3d%% %s/%s' % ( bar, int( 100 * perc ), + time.strftime( '%X', time.gmtime( round( delta ) ) ), + time.strftime( '%X', time.gmtime( estimated ) ) ) ) -def progress_iter( iter, width = 75, vis = None, fout = sys.stderr ): +def progress_iter( iter, vis = None, width = 75, file = sys.stderr ): if not vis: vis = lambda x: x start = time.time() data = list( iter ) @@ -44,11 +47,13 @@ bar = '|' + '#' * int( width * perc ) + '.' * ( width - int( width * perc ) ) + '|' else: bar = '' - fout.write( '\r%s%3d%% %s/%s ' % ( bar, int( 100 * perc ), time.strftime( '%X', time.gmtime( round( delta ) ) ), time.strftime( '%X', time.gmtime( estimated ) ) ) ) + file.write( '\r%s%3d%% %s/%s ' % ( bar, int( 100 * perc ), + time.strftime( '%X', time.gmtime( round( delta ) ) ), + time.strftime( '%X', time.gmtime( estimated ) ) ) ) _progress( 0, 0 ) for value in data: yield value count += 1 - _progress( float( count ) / len( data ), time.time() - start ) - print >>fout + _progress( count / len( data ), time.time() - start ) + print( file = file ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sto...@us...> - 2011-12-10 21:19:12
|
Revision: 70 http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=70&view=rev Author: storchaka Date: 2011-12-10 21:19:05 +0000 (Sat, 10 Dec 2011) Log Message: ----------- Add with parameter fo progress bar. Modified Paths: -------------- trunk/fb2-python-tools/progress_display.py Modified: trunk/fb2-python-tools/progress_display.py =================================================================== --- trunk/fb2-python-tools/progress_display.py 2011-06-29 08:28:19 UTC (rev 69) +++ trunk/fb2-python-tools/progress_display.py 2011-12-10 21:19:05 UTC (rev 70) @@ -7,10 +7,12 @@ import sys, time class progress_display: - def __init__( self, expected_count, fout = sys.stderr ): + def __init__( self, expected_count, width = 75, fout = sys.stderr ): self.__start = time.time() self.__expected_count = expected_count self.__count = 0 + self.__width = width - 25 + self.__fout = fout self.__progress( 0, 0 ) @@ -23,20 +25,30 @@ def __progress( self, perc, delta ): estimated = round( perc and delta / perc ) - print >>self.__fout, '\r|%s%s|%3d%% %s/%s' % ( '#' * int( 50 * perc ), '.' * ( 50 - int( 50 * perc ) ), int( 100 * perc ), time.strftime( '%X', time.gmtime( round( delta ) ) ), time.strftime( '%X', time.gmtime( estimated ) ) ), + width = self.__width + if width > 0: + bar = '|' + '#' * int( width * perc ) + '.' * ( width - int( width * perc ) ) + '|' + else: + bar = '' + self.__fout.write( '\r%s%3d%% %s/%s' % ( bar, int( 100 * perc ), time.strftime( '%X', time.gmtime( round( delta ) ) ), time.strftime( '%X', time.gmtime( estimated ) ) ) ) -def progress_iter( iter, vis = None, fout = sys.stderr ): +def progress_iter( iter, width = 75, vis = None, fout = sys.stderr ): if not vis: vis = lambda x: x start = time.time() data = list( iter ) + width -= 25 count = 0 def _progress( perc, delta ): estimated = round( perc and delta / perc ) - print >>fout, '\r|%s%s|%3d%% %s/%s' % ( '#' * int( 50 * perc ), '.' * ( 50 - int( 50 * perc ) ), int( 100 * perc ), time.strftime( '%X', time.gmtime( round( delta ) ) ), time.strftime( '%X', time.gmtime( estimated ) ) ), + if width > 0: + bar = '|' + '#' * int( width * perc ) + '.' * ( width - int( width * perc ) ) + '|' + else: + bar = '' + fout.write( '\r%s%3d%% %s/%s ' % ( bar, int( 100 * perc ), time.strftime( '%X', time.gmtime( round( delta ) ) ), time.strftime( '%X', time.gmtime( estimated ) ) ) ) _progress( 0, 0 ) for value in data: yield value count += 1 _progress( float( count ) / len( data ), time.time() - start ) - print >>fout, ' ' * 50 + print >>fout This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2011-06-29 08:28:25
|
Revision: 69 http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=69&view=rev Author: shaplov Date: 2011-06-29 08:28:19 +0000 (Wed, 29 Jun 2011) Log Message: ----------- fb2meta 0.02 2011-06-29 Now it is possible to rename files from comand line. Patch form Alexander Batischev Modified Paths: -------------- trunk/fb2-perl-tools/changelog trunk/fb2-perl-tools/fb2meta Modified: trunk/fb2-perl-tools/changelog =================================================================== --- trunk/fb2-perl-tools/changelog 2011-06-29 08:19:22 UTC (rev 68) +++ trunk/fb2-perl-tools/changelog 2011-06-29 08:28:19 UTC (rev 69) @@ -1,3 +1,4 @@ html2fb2.pl 2011-06-21 Added limited CSS support in order to convert files form OpenOffice.org fb2::Description::Extend 2011-06-29 Seems to be fixes for modern perl versions fb2images.pl 0.02 2011-06-29 Move form XML::DOM to XML::LibXML +fb2meta 0.02 2011-06-29 Now it is possible to rename files from comand line. Patch form Alexander Batischev Modified: trunk/fb2-perl-tools/fb2meta =================================================================== --- trunk/fb2-perl-tools/fb2meta 2011-06-29 08:19:22 UTC (rev 68) +++ trunk/fb2-perl-tools/fb2meta 2011-06-29 08:28:19 UTC (rev 69) @@ -1,6 +1,6 @@ #!/usr/bin/perl -our $VERSION=0.01; +our $VERSION=0.02; use strict; =head1 NAME @@ -319,13 +319,14 @@ =cut use File::Find; +use File::Copy; use Archive::Zip qw(:ERROR_CODES :CONSTANTS); use Compress::Zlib; use XML::Parser; use Data::Dumper; use Getopt::Std; use I18N::Langinfo qw(langinfo CODESET); -use vars qw($opt_c $opt_t $opt_f); +use vars qw($opt_c $opt_t $opt_f $opt_z); use XML::Writer; use Encode; use Locale::Language; @@ -827,6 +828,30 @@ # +# Changes names of specified files accordingly to metainfo +# +sub rename_file { + my $old_name = $metainfo{'filename'}; + my $new_name = format_string(); + unless (-e "$new_name") { + move($old_name, $new_name) or die "Can't rename $old_name to $new_name: $!"; + } else { + print "Can't rename $old_name to $new_name: file already exists!\n"; + } +} + +sub do_rename { + getopts("z"); + our $pattern = shift @ARGV; + if($opt_z) { + print "Option -z is not implemented yet!\n"; + exit 1; + } + set_pattern($pattern); + scan_tree(\&rename_file); +} + +# # Accumulates new names made by specified format # sub format_rename { @@ -940,7 +965,7 @@ 'find'=>\&TBD, 'update'=>\&TBD, 'uniq' => \&do_uniq, -'rename'=>\&TBD, +'rename'=>\&do_rename, 'fix'=>\&TBD, 'help'=>\&HELP_MESSAGE ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2011-06-29 08:19:29
|
Revision: 68 http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=68&view=rev Author: shaplov Date: 2011-06-29 08:19:22 +0000 (Wed, 29 Jun 2011) Log Message: ----------- added changelog file to track changes fb2::Description::Extend 2011-06-29 Seems to be fixes for modern perl versions fb2images.pl 0.02 2011-06-29 Move form XML::DOM to XML::LibXML Modified Paths: -------------- trunk/fb2-perl-tools/fb2/Description/Extend.pm trunk/fb2-perl-tools/fb2images.pl Added Paths: ----------- trunk/fb2-perl-tools/changelog Added: trunk/fb2-perl-tools/changelog =================================================================== --- trunk/fb2-perl-tools/changelog (rev 0) +++ trunk/fb2-perl-tools/changelog 2011-06-29 08:19:22 UTC (rev 68) @@ -0,0 +1,3 @@ +html2fb2.pl 2011-06-21 Added limited CSS support in order to convert files form OpenOffice.org +fb2::Description::Extend 2011-06-29 Seems to be fixes for modern perl versions +fb2images.pl 0.02 2011-06-29 Move form XML::DOM to XML::LibXML Modified: trunk/fb2-perl-tools/fb2/Description/Extend.pm =================================================================== --- trunk/fb2-perl-tools/fb2/Description/Extend.pm 2011-06-22 07:52:03 UTC (rev 67) +++ trunk/fb2-perl-tools/fb2/Description/Extend.pm 2011-06-29 08:19:22 UTC (rev 68) @@ -69,8 +69,8 @@ { my $p=$doc->createElement('p'); $node->appendChild($p); - $p->appendChild($doc->createTextNode(' ')); - + $p->appendChild($doc->createTextNode(' ')); + } elsif ($content =~ /$\#DATE\#\s*(.*)/ ) { @@ -105,7 +105,7 @@ } -# ################################## +# ################################## sub _extend_description_fill_complex_node { @@ -115,9 +115,9 @@ my $name=$node->nodeName(); my $doc=$node->getOwnerDocument; my $children_info=_get_node_children_info($name); - + my %name_to_num=(); - for(my $i=0;$i<=$#{@$children_info};$i++) + for(my $i=0;$i<=$#$children_info;$i++) { if ($children_info->[$i]->{'ver'} <= $par->{version}) { @@ -141,7 +141,7 @@ ( $children_info->[$i]->{'opt'} == 1 && $par->{'optional'} == 1 ) ) && ( $children_info->[$i]->{'ver'} <= $par->{version} ) ) { - my $offset_node = $doc->createTextNode("\n".(' ' x $par->{'offset'})); + my $offset_node = $doc->createTextNode("\n".(' ' x $par->{'offset'})); my $new_child = $doc->createElement($children_info->[$i]->{'name'}); my $content = $children_info->[$i]->{'content'}; @@ -161,14 +161,14 @@ } # When we processed all children of the $node then we add childern that should go after last_processed_child - for(my $i=$last_processed_child_num+1;$i<=$#{@$children_info};$i++) + for(my $i=$last_processed_child_num+1;$i<=$#$children_info;$i++) { if ( ( ( $children_info->[$i]->{'opt'} == 0 ) || ( $children_info->[$i]->{'opt'} == 1 && $par->{'optional'} == 1 ) ) && ( $children_info->[$i]->{'ver'} <= $par->{version} ) ) - { - my $offset_node = $doc->createTextNode("\n".(' ' x $par->{'offset'})); - my $new_child = $doc->createElement($children_info->[$i]->{'name'}); + { + my $offset_node = $doc->createTextNode("\n".(' ' x $par->{'offset'})); + my $new_child = $doc->createElement($children_info->[$i]->{'name'}); my $content = $children_info->[$i]->{'content'}; $node->appendChild($offset_node) if $i!=$last_processed_child_num+1; @@ -215,7 +215,7 @@ {'name' => 'book-title' ,'opt'=>0, 'ver'=> 2, 'content'=>'#SPACE#'}, {'name' => 'annotation' ,'opt'=>1, 'ver'=> 2, 'content'=>'#PARAGRAPH#'}, {'name' => 'keywords' ,'opt'=>1, 'ver'=> 2, 'content'=>'#SPACE#'}, - {'name' => 'date' ,'opt'=>1, 'ver'=> 2, 'content'=>'#DATE#'}, + {'name' => 'date' ,'opt'=>1, 'ver'=> 2, 'content'=>'#DATE#'}, {'name' => 'coverpage' ,'opt'=>1, 'ver'=> 2, 'content'=>'#IMAGE#'}, {'name' => 'lang' ,'opt'=>0, 'ver'=> 2, 'content'=>'#SPACE#'}, {'name' => 'src-lang' ,'opt'=>1, 'ver'=> 2, 'content'=>'#SPACE#'}, @@ -251,7 +251,7 @@ {'name' => 'id' , 'opt'=>0, 'ver'=> 2 , 'content'=>"#TEXT# $id"}, {'name' => 'version' , 'opt'=>0, 'ver'=> 2 , 'content'=>'#TEXT# 1.0'}, {'name' => 'history' , 'opt'=>1, 'ver'=> 2 , 'content'=>'#PARAGRAPH#'}, - {'name' => 'publisher' , 'opt'=>1, 'ver'=> 2.2, 'content'=>'#COMPLEX#'}, + {'name' => 'publisher' , 'opt'=>1, 'ver'=> 2.2, 'content'=>'#COMPLEX#'}, ]; } elsif ($name eq 'publish-info') Modified: trunk/fb2-perl-tools/fb2images.pl =================================================================== --- trunk/fb2-perl-tools/fb2images.pl 2011-06-22 07:52:03 UTC (rev 67) +++ trunk/fb2-perl-tools/fb2images.pl 2011-06-29 08:19:22 UTC (rev 68) @@ -1,12 +1,12 @@ #!/usr/bin/perl use strict; -use XML::DOM; +use XML::LibXML; use Getopt::Long qw(HelpMessage VersionMessage); use File::MMagic; use MIME::Base64 qw(encode_base64); use Encode; -our $VERSION=0.01; +our $VERSION=0.02; =head1 NAME @@ -29,13 +29,21 @@ =head1 BUGS -Utility doesn't check if image reference presents in the file, and is +Utility doesn't check if image reference presents in the file, and is unable to add references. -=head1 AUTHOR +=head1 VERSION -Nikolay Shaplov <sh...@sf...> +0.02 +=head1 COPYRIGHT AND LICENSE + +Copyright 2006-2011 by Swami Dhyan Nataraj (Nikolay Shaplov) + +This library is free software; you can redistribute it and/or modify +it under the terms of the General Public License (GPL). For +more information, see http://www.fsf.org/licenses/gpl.txt + =cut my $flags={}; @@ -50,8 +58,8 @@ $opts->{'list'}=1 if @ARGV && ! %{$opts}; my $FileName= $ARGV[0]; - my $parser = new XML::DOM::Parser; - my $doc = $parser->parsefile ($FileName); + my $parser = XML::LibXML->new(); + my $doc = $parser->parse_file($FileName); if ( $opts->{'extract'} ) { @@ -75,17 +83,13 @@ my $backup = $FileName . "~"; unlink $backup; rename $FileName, $backup or warn("Cannot make backup copy: $!"); - my $encoding=$doc->getXMLDecl()->getEncoding(); - # This call of Encode::decode fixes problem in XML::DOM which do not - # mark entire output utf8 correctly. - my $data = decode("utf8",$doc->toString); - open DST,">:encoding($encoding)",$FileName; + my $data = $doc->toString; + open DST,">",$FileName; + print DST $data; close DST; } - $doc->dispose; # Avoid memory leaks - cleanup circular references - sub printImageList { my $List=shift; @@ -102,12 +106,8 @@ foreach ($doc->getDocumentElement()->getElementsByTagName('binary' ,0) ) { - my $id=$_->getAttributes()->getNamedItem('id'); - if ($id) - { - $id=$id->getNodeValue(); - @list= (@list,$id); - } + my $id=$_->getAttribute('id'); + push @list,$id if ($id) } return \@list } @@ -119,12 +119,8 @@ foreach ($doc->getDocumentElement()->getElementsByTagName('*' ,1) ) { - my $id=$_->getAttributes()->getNamedItem('id'); - if ($id) - { - $id=$id->getNodeValue(); - @list= (@list,$id); - } + my $id=$_->getAttribute('id'); + push @list,$id if $id } return \@list } @@ -200,7 +196,7 @@ { my $prev = $binary->getPreviousSibling(); last until defined($prev); - last until ($prev->getNodeType() eq XML::DOM::TEXT_NODE && $prev->getData() =~ /^\s*$/ ); + last until ($prev->nodeType() == XML_TEXT_NODE && $prev->getData() =~ /^\s*$/ ); $root->removeChild($prev); } $root->removeChild($binary); @@ -219,11 +215,11 @@ my $text = ''; for my $node ($elem->getChildNodes()) { - if ($node->getNodeType() eq XML::DOM::ELEMENT_NODE) + if ($node->nodeType() == XML_ELEMENT_NODE) { $text .= getText($node); } - elsif ($node->getNodeType() eq XML::DOM::TEXT_NODE) + elsif ($node->nodeType() == XML_TEXT_NODE) { $text .= $node->getData(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2011-06-22 07:52:10
|
Revision: 67 http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=67&view=rev Author: shaplov Date: 2011-06-22 07:52:03 +0000 (Wed, 22 Jun 2011) Log Message: ----------- Now also uses paragraph class to determinate text style Modified Paths: -------------- trunk/fb2-perl-tools/html2fb2.pl Modified: trunk/fb2-perl-tools/html2fb2.pl =================================================================== --- trunk/fb2-perl-tools/html2fb2.pl 2011-06-21 19:16:45 UTC (rev 66) +++ trunk/fb2-perl-tools/html2fb2.pl 2011-06-22 07:52:03 UTC (rev 67) @@ -304,7 +304,6 @@ my $previous_space = $space; $space = ''; $space=' ' if $txt =~ /^\s/; -# if ($space && $previous_space) if ($previous_space) { my $newstate=0; @@ -342,7 +341,7 @@ my $newstate=0; $newstate|=1 if @_ ? $_[0] : $strong; $newstate|=2 if @_ ? $_[1] : $emphasis; - return if $curstate==$newstate || ($curstate==0 && !$realtext); + return if $curstate==$newstate; # || ($curstate==0 && !$realtext); # always close whatever is open $textbuf.="</$ST>" if $curstate&1; $textbuf.="</$EM>" if $curstate&2; @@ -500,7 +499,13 @@ } } pbreak(1); # start of p doesnt add an empty line, but it stops an unclosed paragraph + my %styles=get_styles($elem); + i_open() if ($styles{'font-style'} && $styles{'font-style'} eq 'italic'); + b_open() if ($styles{'font-weight'} && $styles{'font-weight'} eq 'bold'); element($_) for $elem->content_list; + b_close() if ($styles{'font-weight'} && $styles{'font-weight'} eq 'bold'); + i_close() if ($styles{'font-style'} && $styles{'font-style'} eq 'italic'); + pbreak(); # end of paragraph always closes return; } elsif ($t eq "dd" || $t eq "br") { @@ -526,8 +531,32 @@ i_open() if ($styles{'font-style'} && $styles{'font-style'} eq 'italic'); b_open() if ($styles{'font-weight'} && $styles{'font-weight'} eq 'bold'); + + my $stored_emph; + if ($styles{'font-style'} && $styles{'font-style'} eq 'normal') + { + $stored_emph = $emphasis; + $emphasis = 0; + checkhl(); + } + my $stored_strong; + if ($styles{'font-weight'} && $styles{'font-weight'} eq 'normal') + { + $stored_strong = $strong; + $strong = 0; + checkhl(); + } + element($_) for $elem->content_list; + if ($styles{'font-style'} && $styles{'font-style'} eq 'normal') + { + $emphasis = $stored_emph; + } + if ($styles{'font-weight'} && $styles{'font-weight'} eq 'normal') + { + $strong = $stored_strong; + } b_close() if ($styles{'font-weight'} && $styles{'font-weight'} eq 'bold'); i_close() if ($styles{'font-style'} && $styles{'font-style'} eq 'italic'); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2011-06-21 19:16:53
|
Revision: 66 http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=66&view=rev Author: shaplov Date: 2011-06-21 19:16:45 +0000 (Tue, 21 Jun 2011) Log Message: ----------- Limited css support for html2fb2.pl in order to properly convert html files made by OpenOffice.org Some improvement with merging <i>1</i><i>2</i> into <i>12</i> also were made Modified Paths: -------------- trunk/fb2-perl-tools/html2fb2.pl Modified: trunk/fb2-perl-tools/html2fb2.pl =================================================================== --- trunk/fb2-perl-tools/html2fb2.pl 2011-02-04 11:05:58 UTC (rev 65) +++ trunk/fb2-perl-tools/html2fb2.pl 2011-06-21 19:16:45 UTC (rev 66) @@ -77,15 +77,17 @@ html2fb2 -b head -p 14,20 text.html -=head1 AUTHOR +=head1 AUTHORS -Mike Matsnev <mi...@po...> +Mike Matsnev <mi...@po...> (initial version) +Nikolay Shaplov <n...@sh...> (c) 2011 =cut use strict; use warnings; use HTML::TreeBuilder; +use CSS; use Getopt::Std; my $xmllib=$^O eq "MSWin32" ? "use Win32::OLE" : "use XML::LibXML"; @@ -94,6 +96,7 @@ print STDERR "No XML support found.\n"; undef $xmllib; } +my $css = CSS->new(); # global options my $minempty=1; # minimum number of empty paragraphs that @@ -298,7 +301,26 @@ $txt =~ s/[<>]/$angbr{$1}/sg unless $_[0]; } $txt =~ y/\t\r\n / /s; # also destroys nbsp + my $previous_space = $space; + $space = ''; $space=' ' if $txt =~ /^\s/; +# if ($space && $previous_space) + if ($previous_space) + { + my $newstate=0; + $newstate|=1 if $strong; + $newstate|=2 if $emphasis; + + if ($curstate>$newstate) # if we were in some <i> or <b> tag, now out of it but not cloed it yet in $textbuf + { + $space = $previous_space; + $previous_space = ''; + } else + { + $space=''; + } + } + my $msp=''; $msp=' ' if $txt =~ /\s$/; $txt =~ s/^ //; @@ -307,8 +329,10 @@ if (!length($txt)) { # whitespace only??? $space=(length($space) || length($msp)) && $realtext ? ' ' : ''; } else { + $textbuf.=$previous_space; # if $realtext; + checkhl(); $textbuf.=$space if $realtext; - $realtext=1,checkhl() unless $realtext; + $realtext=1; $textbuf.=$txt; $space=$msp; } @@ -346,6 +370,32 @@ } } +sub i_open +{ + ++$emphasis; + $textbuf.=$space; # commition buffered space before opening a tag + $space=''; + checkhl(); + +} +sub i_close +{ + --$emphasis; +} + +sub b_open +{ + ++$strong; + $textbuf.=$space; # commition buffered space before opening a tag + $space=''; + checkhl(); +} + +sub b_close +{ + --$strong; +} + sub add_section { my ($txt,$depth)=@_; cleanup($txt); @@ -386,13 +436,25 @@ } sub get_styles { - my $styles=$_[0]->attr('style'); - return () unless $styles; - my @styles; + my $elem = shift; + my $styles= $elem->attr('style') || ""; + my @l = (); for (split(/;/,$styles)) { - push (@styles,$1,$2) if /^\s*(\S+)\s*:\s*(\S+)\s*$/; + push (@l,$1,$2) if /^\s*(\S+)\s*:\s*(\S+)\s*$/; } - @styles; + my %styles = @l; + if ($elem->attr('class')) + { + my $class_style = $css->get_style_by_selector('.'.$elem->attr('class')); + if ($class_style) + { + foreach my $p (@{$class_style->{properties}}) # This is in ugly hack we are using CSS::Styles internals + { + $styles{$p->{property}} = $p->{simple_value}; + } + } + } + return %styles; } sub element { @@ -430,11 +492,9 @@ return; } elsif ($class eq "intro") { pbreak(); - ++$emphasis; - checkhl; + i_open(); element($_) for $elem->content_list; - --$emphasis; - checkhl; + i_close(); pbreak(); return; } @@ -448,18 +508,30 @@ } elsif ($t =~ /^h(\d)/) { add_section($elem->as_text,$1*3); return; - } elsif ($minstyle && $t eq "span") { + } elsif ($t eq "span") { my %styles=get_styles($elem); - if ($styles{'font-size'} && - $styles{'font-size'} =~ /^(\d+(?:\.\d+)?)(?:pt)?$/ && - $1>=$minstyle && $1<=$maxstyle) + if ($minstyle) { - my $depth=36-$1; - $depth=1 if $depth<1; - $depth=20 if $depth>20; - add_section($elem->as_text,$depth); - return; + if ($styles{'font-size'} && + $styles{'font-size'} =~ /^(\d+(?:\.\d+)?)(?:pt)?$/ && + $1>=$minstyle && $1<=$maxstyle) + { + my $depth=36-$1; + $depth=1 if $depth<1; + $depth=20 if $depth>20; + add_section($elem->as_text,$depth); + } + return; } + + i_open() if ($styles{'font-style'} && $styles{'font-style'} eq 'italic'); + b_open() if ($styles{'font-weight'} && $styles{'font-weight'} eq 'bold'); + + element($_) for $elem->content_list; + + b_close() if ($styles{'font-weight'} && $styles{'font-weight'} eq 'bold'); + i_close() if ($styles{'font-style'} && $styles{'font-style'} eq 'italic'); + return; } elsif ($minfont && $t eq "font") { my $size=$elem->attr('size'); if ($size && $size>=$minfont) { @@ -472,26 +544,20 @@ } elsif ($t eq "script" || $t eq "style") { return; } elsif ($t eq "i" || $t eq "em") { - ++$emphasis; - checkhl; + i_open(); element($_) for $elem->content_list; - --$emphasis; - checkhl; + i_close(); return; } elsif ($t eq "blockquote") { pbreak(); - ++$emphasis; - checkhl; + i_open(); element($_) for $elem->content_list; - --$emphasis; - checkhl; + i_close; return; } elsif ($t eq "b" || $t eq "strong") { - ++$strong; - checkhl; + b_open(); element($_) for $elem->content_list; - --$strong; - checkhl; + b_close(); return; } elsif ($t eq 'img') { my $src = $elem->attr('src'); @@ -527,6 +593,11 @@ !$Encoding && $content =~ /charset=(\S+)/i; } elsif ($elem->tag eq "title") { $Title=$elem->as_text; + } elsif ($elem->tag eq "style") { + foreach ($elem->content_list()) + { + $css->read_string($_); + } } } element($_) for $elem->content_list; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2011-02-04 11:06:04
|
Revision: 65 http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=65&view=rev Author: shaplov Date: 2011-02-04 11:05:58 +0000 (Fri, 04 Feb 2011) Log Message: ----------- Migration from XML::DOM to XML::LibXML Modified Paths: -------------- trunk/fb2-perl-tools/fb2_normalize.pl Modified: trunk/fb2-perl-tools/fb2_normalize.pl =================================================================== --- trunk/fb2-perl-tools/fb2_normalize.pl 2010-12-08 07:54:07 UTC (rev 64) +++ trunk/fb2-perl-tools/fb2_normalize.pl 2011-02-04 11:05:58 UTC (rev 65) @@ -1,7 +1,7 @@ #!/usr/bin/perl use strict; -use XML::DOM; +use XML::LibXML; my @inline_elsments=('a', 'book-name', 'book-title', 'city', 'code', 'custom-info', 'date', @@ -17,8 +17,8 @@ } my $FileName= $ARGV[0]; -my $parser = new XML::DOM::Parser; -my $root = $parser->parsefile($FileName)->getDocumentElement(); +my $parser = XML::LibXML->new(); +my $root = $parser->parse_file($FileName)->getDocumentElement(); normalize_branch($root); print $root->toString(); @@ -29,16 +29,15 @@ my $level = shift; foreach ($branch->getChildNodes()) { - normalize_text_node($_) if ($_->getNodeType()==TEXT_NODE); + normalize_text_node($_) if ($_->nodeType() == XML_TEXT_NODE); } my @children=$branch->getChildNodes(); - - if (! $inline_elements_hash{$branch->getNodeName()} ) + if (! $inline_elements_hash{$branch->nodeName()} ) { my $count=1; foreach my $node (@children) { - if( !(($branch->getNodeName() eq 'section') && ($count==1) && ($node->getNodeName() eq 'title') )) + if( !(($branch->nodeName() eq 'section') && ($count==1) && ($node->nodeName() eq 'title') )) { my $new_node=$branch->getOwnerDocument()->createTextNode("\n ".$level); $branch->insertBefore ($new_node,$node); @@ -46,19 +45,18 @@ $count++; } my $new_node=$branch->getOwnerDocument()->createTextNode("\n".$level); - $branch->insertBefore ($new_node); + $branch->insertBefore ($new_node,undef); # adding as last node } - foreach (@children) { - normalize_branch($_,$level." ") if ($_->getNodeType()== ELEMENT_NODE); + normalize_branch($_,$level." ") if ($_->nodeType() == XML_ELEMENT_NODE); } } sub normalize_text_node { my $text_node=shift; - return 0 if ( $text_node->getNodeType()!=TEXT_NODE ); + return 0 if ( $text_node->nodeType() != XML_TEXT_NODE ); my $text=$text_node->getData(); $text=~s/\s+/ /g; $text=~s/^ //g; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2010-12-08 07:54:13
|
Revision: 64 http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=64&view=rev Author: shaplov Date: 2010-12-08 07:54:07 +0000 (Wed, 08 Dec 2010) Log Message: ----------- Renumering is added to footnotes processing script: renumbering script scans body of a book for footnote links and reorder footnodes in footnote body according to the order of footnote links. New nubers are also assigned to footonte's links text and footnote's titles. Modified Paths: -------------- trunk/fb2-perl-tools/fb2/Footnotes.pm trunk/fb2-perl-tools/fb2_notes Modified: trunk/fb2-perl-tools/fb2/Footnotes.pm =================================================================== --- trunk/fb2-perl-tools/fb2/Footnotes.pm 2009-11-29 14:57:22 UTC (rev 63) +++ trunk/fb2-perl-tools/fb2/Footnotes.pm 2010-12-08 07:54:07 UTC (rev 64) @@ -1,8 +1,9 @@ package fb2::Footnotes; -our $VERSION=0.01; +our $VERSION=0.02; use strict; +use warnings; use XML::LibXML; =head1 NAME @@ -48,8 +49,8 @@ Default value is 1; =back - + =cut sub ConvertFromComments @@ -101,6 +102,222 @@ return($changes_flag); } +=cut + +=head2 RenumberFootnotes + + fb2::Footnotes::RenumberFootnotes($document); + +Reorder footnotes in footnotes body according to the order of footnote links in the book's body. Each footnote will get new title according +to it's position in this list; footnote links text will also be changed to each footnote index number. Meanwhile footnote ids are kept unchanged. +If reorder were successful function returns 1, or 0 if something went wrong. + +I<$document> - Fb2 e-book stored as an XML::LibXML Document object + + +=cut + +sub RenumberFootnotes +{ + my $doc = shift; + my $root = $doc->getDocumentElement(); + my $note_body = undef; + + foreach my $node ($doc->getElementsByTagName('body')) + { + foreach ($node->attributes()) + { + if ( ($_->nodeName eq 'name') && ($_->value eq 'notes')) + { + # It's assumed that there is only one note-body in the book + if ($note_body) + { + warn "More then one footnote body in the document. Refusing renombering footnotes"; + return 0; + } + $note_body = $node; + } + } + } + if (! $note_body) + { + warn ("No footnote body found. No renumbering have been done"); + return 0; + } + my %footnotes = (); + my @lost_foot_notes = (); + foreach my $section ($note_body->getChildrenByLocalName('*')) + { + if ($section->nodeName ne 'section') + { + warn "Unexpected node in footnote body:'".$section->nodeName."', aborting"; + return 0; + } + + my $id = $section->getAttribute('id'); + my $fn_record = {content=>$section, prefix=>[]}; + + # saving all non-element nodes that goes before each foonnote sections into prefix array in $fn_record + my $node = $section->previousSibling(); + while ($node) + { + if ($node->nodeType != XML_ELEMENT_NODE) + { + push @{$fn_record->{prefix}}, $node; + } else + { + $node = undef; + } + $node=$node->previousSibling() if $node; + } + + if (! $id) # If we habe no id, we are trying to get footnote title for error message + { + # Trying to get title if any + my $title = ""; + foreach my $title_node ($section->getChildrenByLocalName('title')) + { + foreach my $p_node ($title_node->getChildrenByLocalName('*')) + { + my $p_content = $p_node->firstChild; + while ($p_content) + { + $title.= $p_content->toString; + $p_content=$p_content->nextSibling + } + } + } + warn "Lost footnote (footnote withot id) found in section with title '$title'" if $title; + warn "Lost footnote (footnote withot id) found in section with no title" unless $title; + push @lost_foot_notes,$fn_record; + } else + { + $footnotes{$id} = $fn_record; + } + } + + # Saving bottom of the footnite body to preserve formatting and comments, if any + my @bottom = (); + my $node = $note_body->lastChild; + while ($node) + { + if ($node->nodeType != XML_ELEMENT_NODE) + { + unshift @bottom,$node; + } else + { + $node = undef; + } + $node = $node->previousSibling if $node; + } + + my @footnote_links = _recur_find_footnote_link($root); + + + my $new_note_body = $doc->createElementNS("http://www.gribuser.ru/xml/fictionbook/2.0",'body'); + $new_note_body->setAttribute( 'name','notes'); + + my $i = 0; + foreach my $a_node (@footnote_links) + { + my $id = $a_node->getAttributeNS('http://www.w3.org/1999/xlink', 'href');; + if ($id =~s/^\#//) + { + unless ($footnotes{$id}) + { + if (defined($footnotes{$id})) + { + warn "Footnote with id='$id' is linked twice or more"; + } else + { + warn "Footnote with id='$id' does not exists but linked from the main body"; + } + } else ## if note exists + { + while (@{$footnotes{$id}->{prefix}}) + { + $new_note_body->appendChild(shift(@{$footnotes{$id}->{prefix}})->cloneNode(1)); + } + $i++; + my $new_note = $footnotes{$id}->{content}->cloneNode(1); + my $insert_after = undef; + foreach ($new_note->getChildrenByTagName('title')) + { + unless (defined $insert_after) + { + $insert_after =$_->previousSibling + } else + { + $insert_after = 0; + } + $new_note->removeChild($_); + } + my $new_note_title = $doc->createElementNS("http://www.gribuser.ru/xml/fictionbook/2.0",'title'); + $new_note_title->addNewChild("http://www.gribuser.ru/xml/fictionbook/2.0",'p')->appendText("[$i]"); + + if ($insert_after) + { + $insert_after->parentNode->insertAfter($new_note_title,$insert_after); + } else + { + $new_note->insertBefore($new_note_title,$new_note->firstChild); + } + $new_note_body->appendChild($new_note); + $footnotes{$id}=0; + $a_node->removeChildNodes(); + $a_node->appendText("[$i]"); + } + } + } + foreach (keys %footnotes) + { + if ($footnotes{$_}) + { + push @lost_foot_notes, $footnotes{$_}; + warn "Footnote with id ='$_' does not linked from the main body"; + } + } + if (@lost_foot_notes) + { + $new_note_body->appendText("\n"); + $new_note_body->appendChild($doc->createComment(' ======== Lost footnotes: footnotes without id, or footnotes not linked from the main body ========')); + foreach my $lost_fn_rec (@lost_foot_notes) + { + while (@{$lost_fn_rec->{prefix}}) + { + $new_note_body->appendChild(shift(@{$lost_fn_rec->{prefix}})->cloneNode(1)); + } + $new_note_body->appendChild($lost_fn_rec->{content}->cloneNode(1)); + } + } + foreach (@bottom) + { + $new_note_body->appendChild($_->cloneNode(1)); + } + $note_body->parentNode->insertBefore($new_note_body,$note_body); + $note_body->parentNode->removeChild($note_body); + + return 1; # FIXME 1 is retured even if no real changes were made (i.e. when renubering file that were already renumbered +} + +sub _recur_find_footnote_link +{ + my $node = shift; + my @res = (); + if ( ($node->nodeType == XML_ELEMENT_NODE) && ($node->nodeName eq 'a') && $node->getAttribute('type') && ($node->getAttribute('type') eq 'note')) + { + return $node; # in note link found, we do not look futher + } + if ( $node->nodeType == XML_ELEMENT_NODE) + { + foreach my $n ($node->childNodes) + { + push @res, _recur_find_footnote_link($n); + } + } + return @res; +} + =head2 Add fb2::Footnotes::Add($document,{Option1 => 'Value1', Option2 => 'Value2'}); @@ -152,7 +369,7 @@ $note_body = $node; } } - } + } if (! $note_body) { $note_body = $doc->createElement('body'); @@ -160,7 +377,7 @@ $book->appendChild($doc->createTextNode(' ')); $book->appendChild($note_body); $book->appendChild($doc->createTextNode("\n")); - } + } my $section_node = $doc->createElement('section'); $section_node->setAttribute('id',"note$number"); @@ -268,15 +485,15 @@ =head1 AUTHOR -Nikolay Shaplov <N...@Sh...> +Swami Dhyan Nataraj (Nikolay Shaplov) <N...@Sh...> =head1 VERSION -0.01 +0.02 =head1 COPYRIGHT AND LICENSE -Copyright 2007 by Nikolay Shaplov +Copyright 2007,2010 by Swami Dhyan Nataraj (Nikolay Shaplov) This library is free software; you can redistribute it and/or modify it under the terms of the General Public License (GPL). For Modified: trunk/fb2-perl-tools/fb2_notes =================================================================== --- trunk/fb2-perl-tools/fb2_notes 2009-11-29 14:57:22 UTC (rev 63) +++ trunk/fb2-perl-tools/fb2_notes 2010-12-08 07:54:07 UTC (rev 64) @@ -5,7 +5,7 @@ use XML::LibXML; use Encode; use Getopt::Long qw(HelpMessage VersionMessage); -our $VERSION=0.01; +our $VERSION=0.02; =head1 NAME @@ -17,6 +17,8 @@ B<fb2_notes> B<convert> <I<src_file.fb2> >I<dst_file.fb2> +B<fb2_notes> B<renumber> <I<src_file.fb2> >I<dst_file.fb2> + =head1 DESCRIPTION This utility allows to convert specifically formated comments info fb2 footnotes @@ -51,6 +53,12 @@ =back + +=item B<renumber> + +Reorder footnotes according to the order of the footnotes links in main body. Footnote's title and link's text +are changed to the index number of each footnote in a new list. Footnote ids are remain unchanged. + =back =head1 EXAMPLES @@ -89,15 +97,15 @@ =head1 AUTHOR -Nikolay Shaplov <N...@Sh...> +Swami Dhyan Nataraj (Nikolay Shaplov) <N...@Sh...> =head1 VERSION -0.01 +0.02 =head1 COPYRIGHT AND LICENSE -Copyright 2007 by Nikolay Shaplov +Copyright 2007,2010 by Swami Dhyan Nataraj (Nikolay Shaplov) This library is free software; you can redistribute it and/or modify it under the terms of the General Public License (GPL). For @@ -108,6 +116,7 @@ my $Command = shift @ARGV; do_convert() if $Command eq 'convert'; +do_renumber() if $Command eq 'renumber'; HelpMessage() if ! $Command || $Command eq 'help'; @@ -157,6 +166,32 @@ print STDERR "Comments successfully converted\n"; } + +sub do_renumber +{ + my $opts={}; + GetOptions( + help => sub {HelpMessage(); }, + version => sub {VersionMessage(); }, + "keyword|w=s" => \$opts->{'keyword'}, + "use-number|n" => \$opts->{'use_number'}, + ); + + my $file_name = $ARGV[0]; + + my $doc; + + if ($file_name) + { + $doc = _parse_file($file_name); + } else + { + $doc = _parse_stdin(); + } + my $changes_flag = fb2::Footnotes::RenumberFootnotes($doc); + print $doc->toString(); +} + sub _parse_file { my $file_name=shift; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sto...@us...> - 2009-11-29 14:57:30
|
Revision: 63 http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=63&view=rev Author: storchaka Date: 2009-11-29 14:57:22 +0000 (Sun, 29 Nov 2009) Log Message: ----------- Support long options. Modified Paths: -------------- trunk/fb2-python-tools/fb2clean.py trunk/fb2-python-tools/fb2fixtr.py trunk/fb2-python-tools/fb2format.py Modified: trunk/fb2-python-tools/fb2clean.py =================================================================== --- trunk/fb2-python-tools/fb2clean.py 2009-11-29 12:40:50 UTC (rev 62) +++ trunk/fb2-python-tools/fb2clean.py 2009-11-29 14:57:22 UTC (rev 63) @@ -3,17 +3,19 @@ '''\ Usage: - fb2clean.py [<options>] [<fb2-files>] + fb2clean.py [options] [fb2-files] + Options: - -h display this help message and exit - -V display the version and exit - -k create backup files - -@ <file> read file names from file (one name per line) - -v display progressbar -File name '-' means standard input/output. + -h, --help display this help message and exit + -V, --version display the version and exit + -k, --backup create backup files + -@ FILE read file names from FILE (one name per line) + -v, --progress display progressbar + +File name '-' means standard input. ''' __author__ = 'Serhiy Storchaka <sto...@us...>' -__version__ = '0.1' +__version__ = '0.2' __all__ = [] import re @@ -107,20 +109,21 @@ if __name__ == '__main__': try: - opts, args = getopt.getopt( sys.argv[1:], '@:hkqtvV' ) + opts, args = getopt.getopt( sys.argv[1:], '@:hkqtvV', + ['backup', 'help', 'progress', 'version'] ) except getopt.GetoptError, err: print >>sys.stderr, 'Error:', err - sys.exit(2) + sys.exit( 2 ) keepBackup = False backupSuffix = '.bak' verbose = False for option, value in opts: - if option == '-h': - print __doc__ + if option in ('-h', '--help'): + sys.stdout.write( __doc__ ) sys.exit( 0 ) - elif option == '-V': + elif option in ('-V', '--version'): print __version__ sys.exit( 0 ) elif option == '-@': @@ -128,14 +131,14 @@ args.extend( line.rstrip( '\n' ) for line in sys.stdin ) else: args.extend( line.rstrip( '\n' ) for line in open( value ) ) - elif option == '-k': + elif option in ('-k', '--backup'): keepBackup = True - elif option == '-v': + elif option in ('-v', '--progress'): verbose = True if verbose: import progress_display - args = progress_display.progress_iter( args, os.path.basename, sys.stderr ) + args = progress_display.progress_iter( args ) global filename for filename in args: @@ -160,5 +163,5 @@ except (KeyboardInterrupt, SystemExit): raise except Exception, err: - print >>sys.stderr, 'Error processing %s:' % filename + print >>sys.stderr, 'Error processing "%s":' % filename print >>sys.stderr, err Modified: trunk/fb2-python-tools/fb2fixtr.py =================================================================== --- trunk/fb2-python-tools/fb2fixtr.py 2009-11-29 12:40:50 UTC (rev 62) +++ trunk/fb2-python-tools/fb2fixtr.py 2009-11-29 14:57:22 UTC (rev 63) @@ -2,23 +2,26 @@ # -*- coding: UTF-8 -*- '''\ -Fix some popular OCR and conversion errors in FictionBook2 files. +Fix some frequent OCR and conversion errors in FictionBook2 files. Usage: - fb2fixtr.py [<options>] [<fb2-files>] + fb2fixtr.py [options] [fb2-files] + Options: - -h display this help message and exit - -V display the version and exit - -k create backup files - -@ <file> read file names from file (one name per line) - -q quick but use more memory - -T process plain text - -v display progressbar - -o logfile log all fixes to logfile -File name '-' means standard input/output. + -h, --help display this help message and exit + -V, --version display the version and exit + -k, --backup create backup files + -@ FILE read file names from FILE (one name per line) + -q, --quick quick but use more memory + -T, --text process plain text + -v, --progress display progressbar + -o FILE, --log-file FILE log all fixes to FILE + -d FILE, --dictionary FILE use dictionary from FILE + +File name '-' means standard input. ''' __author__ = 'Serhiy Storchaka <sto...@us...>' -__version__ = '0.1' +__version__ = '0.2' __all__ = [] import string, re @@ -338,10 +341,11 @@ if __name__ == '__main__': try: - opts, args = getopt.getopt( sys.argv[1:], '@:d:hko:qTvV' ) + opts, args = getopt.getopt( sys.argv[1:], '@:d:hko:qTvV', + ['backup', 'dictionary=', 'help', 'log-file', 'progress', 'quick', 'text', 'version'] ) except getopt.GetoptError, err: print >>sys.stderr, 'Error:', err - sys.exit(2) + sys.exit( 2 ) keepBackup = False backupSuffix = '.bak' @@ -349,10 +353,10 @@ plainText = False for option, value in opts: - if option == '-h': - print __doc__ + if option in ('-h', '--help'): + sys.stdout.write( __doc__ ) sys.exit( 0 ) - elif option == '-V': + elif option in ('-V', '--version'): print __version__ sys.exit( 0 ) elif option == '-@': @@ -360,22 +364,22 @@ args.extend( line.rstrip( '\n' ) for line in sys.stdin ) else: args.extend( line.rstrip( '\n' ) for line in open( value ) ) - elif option == '-k': + elif option in ('-k', '--backup'): keepBackup = True - elif option == '-q': + elif option in ('-q', '--quick'): quick = True - elif option == '-v': + elif option in ('-v', '--progress'): verbose = True - elif option == '-T': + elif option in ('-T', '--text'): plainText = True - elif option == '-o': + elif option in ('-o', '--log-file'): logfile = open( value, 'w' ) - elif option == '-d': + elif option in ('-d', '--dictionary'): read_trdict( value ) if verbose: import progress_display - args = progress_display.progress_iter( args, os.path.basename, sys.stderr ) + args = progress_display.progress_iter( args ) global filename for filename in args: @@ -414,7 +418,7 @@ except (KeyboardInterrupt, SystemExit): raise except Exception, err: - print >>sys.stderr, 'Error processing %s:' % filename + print >>sys.stderr, 'Error processing "%s":' % filename print >>sys.stderr, err raise Modified: trunk/fb2-python-tools/fb2format.py =================================================================== --- trunk/fb2-python-tools/fb2format.py 2009-11-29 12:40:50 UTC (rev 62) +++ trunk/fb2-python-tools/fb2format.py 2009-11-29 14:57:22 UTC (rev 63) @@ -3,22 +3,24 @@ '''\ Usage: - fb2format.py [<options>] [<fb2-files>] + fb2format.py [options] [fb2-files] + Options: - -h display this help message and exit - -V display the version and exit - -e <encoding> output in the given encoding - -f convert file to human readable format - -s sqeeze file in one line - -b sqeeze binaries in one line - -k create backup files - -@ <file> read file names from file (one name per line) - -v display progressbar -File name '-' means standard input/output. + -h, --help display this help message and exit + -V, --version display the version and exit + -e ENCODING, -encoding ENCODING output in the given encoding + -f, --format convert file to human readable format + -s, --squeeze squeeze file in one line + -b, --squeeze-binaries squeeze binaries in one line + -k, --backup create backup files + -@ FILE read file names from FILE (one name per line) + -v, --progress display progressbar + +File name '-' means standard input. ''' __author__ = 'Serhiy Storchaka <sto...@us...>' -__version__ = '0.1' +__version__ = '0.2' try: import psyco @@ -79,7 +81,8 @@ if __name__ == '__main__': try: - opts, args = getopt.getopt( sys.argv[1:], '@:e:fhkstvV' ) + opts, args = getopt.getopt( sys.argv[1:], '@:be:fhksvV', + ['backup', 'encoding=', 'format', 'help', 'progress', 'squeeze', 'squeeze-binaries', 'version'] ) except getopt.GetoptError, err: print >>sys.stderr, 'Error:', err sys.exit( 2 ) @@ -93,10 +96,10 @@ verbose = False for option, value in opts: - if option == '-h': - print __doc__ + if option in ('-h', '--help'): + sys.stdout.write( __doc__ ) sys.exit( 0 ) - elif option == '-V': + elif option in ('-V', '--version'): print __version__ sys.exit( 0 ) elif option == '-@': @@ -104,18 +107,18 @@ args.extend( line.rstrip( '\n' ) for line in sys.stdin ) else: args.extend( line.rstrip( '\n' ) for line in open( value ) ) - elif option == '-e': + elif option in ('-e', '--encoding'): forceEncoding = value - elif option == '-k': + elif option in ('-k', '--backup'): keepBackup = True - elif option == '-f': + elif option in ('-f', '--format'): format = True - elif option == '-s': + elif option in ('-s', '--squeeze'): format = True squeeze = True - elif option == '-b': + elif option in ('-b', '--squeeze-binaries'): squeezeBinary = True - elif option == '-v': + elif option in ('-v', '--progress'): verbose = True if verbose: @@ -151,5 +154,5 @@ except (KeyboardInterrupt, SystemExit): raise except Exception, err: - print >>sys.stderr, 'Error processing %s:' % filename + print >>sys.stderr, 'Error processing "%s":' % filename print >>sys.stderr, err This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sto...@us...> - 2009-11-29 12:40:56
|
Revision: 62 http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=62&view=rev Author: storchaka Date: 2009-11-29 12:40:50 +0000 (Sun, 29 Nov 2009) Log Message: ----------- fb2maketree.py 0.2. Modified Paths: -------------- trunk/fb2-python-tools/fb2maketree.py Modified: trunk/fb2-python-tools/fb2maketree.py =================================================================== --- trunk/fb2-python-tools/fb2maketree.py 2009-11-28 17:50:15 UTC (rev 61) +++ trunk/fb2-python-tools/fb2maketree.py 2009-11-29 12:40:50 UTC (rev 62) @@ -3,20 +3,22 @@ '''\ Usage: - fb2maketree.py [<options>] [<fb2-files>] + fb2maketree.py [options] [fb2-files] + Options: - -h display this help message and exit - -V display the version and exit - -f <format> use tree format (translators, authors, authors-src, series, genres) - -o, --output <dir> tree base directory - -s make symbolic links instead of hard links - -@ <file> read file names from file (one name per line) - -v display progressbar -File name '-' means standard input/output. + -h, --help display this help message and exit + -V, --version display the version and exit + -f FORMAT, --format=FORMAT use tree format (authors, authors-src, series, genres, translators, date) + -o DIR, --output DIR tree base directory + -s, --symbolic make symbolic links instead of hard links + -@ FILE read file names from FILE (one name per line) + -v, --progress display progressbar + +File name '-' means standard input. ''' __author__ = 'Serhiy Storchaka <sto...@us...>' -__version__ = '0.1' +__version__ = '0.2' __all__ = [] try: @@ -29,14 +31,6 @@ filesystemencoding = sys.getfilesystemencoding() # filesystemencoding = 'utf-8' -def get_text( node ): - if node is None: - return '' - text = node.text - if text is None: - return '' - return text.strip() - def genname( dirname, filename, otherpath = None ): filename = filename.replace( '"', "'" ) filename = filename.replace( ':', '.' ) @@ -46,16 +40,18 @@ try: if not os.path.exists( dirname ): os.makedirs( dirname ) - except os.error, e: - print >>sys.stderr, e + except os.error, err: + print >>sys.stderr, err pass count = 0 path = os.path.join( dirname, filename ) while os.access( path, os.F_OK ): - if otherpath and filecmp.cmp( path, otherpath, 0 ): -# if data and os.path.getsize( path ) == len( data ) and open( path ).read() == data: - print '#', path.encode( filesystemencoding ) - return None + if otherpath: + if os.path.samefile( path, otherpath ): + return None + if filecmp.cmp( path, otherpath, 0 ): + print '#', path.encode( filesystemencoding ) + return None count += 1 path = os.path.join( dirname, '%s__%d%s' % (basename, count, suffix) ) if count > 0: @@ -66,48 +62,44 @@ try: os.link( src, dst ) except OSError, err: - os.symlink( src, dst ) print '@', dst.encode( filesystemencoding ) + os.symlink( src, dst ) -def linkauthors( basedir, authornames, book_title, fb2name ): - if len( authornames ) > 4: - authornames_str = ', '.join( authornames[:4] ) + u',..' - else: - authornames_str = ', '.join( authornames ) +def linkauthors( path, authornames, book_title ): + if len( authornames ) > 1: + (dirname, filename) = os.path.split( path ) + (basedir, dirname) = os.path.split( dirname ) + mainname = os.path.join( '..', dirname, filename ) + for authorname in authornames: + os.symlink( mainname, genname( os.path.join( basedir, authorname ), book_title + '.fb2' ) ) - path = genname( os.path.join( basedir, authornames_str ), book_title + '.fb2', fb2name ) - if path: - mklink( os.path.abspath( fb2name ), path ) - if len( authornames ) > 1: - mainname = os.path.join( '..', authornames_str, os.path.basename( path ) ) - for authorname in authornames: - os.symlink( mainname, genname( os.path.join( basedir, authorname ), book_title + '.fb2' ) ) +def getauthorname( author ): + first_name = author.findtext( 'first-name' ) + last_name = author.findtext( 'last-name' ) + middle_name = author.findtext( 'middle-name' ) + authorname = ' '.join( [name for name in [last_name, first_name, middle_name] if name] ) + nickname = author.findtext( 'nickname' ) + if nickname: + authorname += ' [%s]' % nickname + return authorname xml_re = re.compile( r'<\?xml version="(?:[^">]*)" encoding="(?:[^">]*)"\?>', re.DOTALL ) desc_re = re.compile( r'<description>.*?</description>', re.DOTALL ) -def parse( data ): - return xml.dom.minidom.parseString( - xml_re.match( data ).group() + - desc_re.search( data ).group(). - replace( 'xlink:href=', 'href=' ). - replace( 'l:href=', 'href=' ) - ) if __name__ == '__main__': try: - opts, args = getopt.getopt( sys.argv[1:], '@:hf:o:svV', ['output='] ) - except getopt.GetoptError: - # print help information and exit: - print >>sys.stderr, 'Illegal option' + opts, args = getopt.getopt( sys.argv[1:], '@:hf:o:svV', ['help', 'format=', 'output=', 'symbolic', 'version', 'progress'] ) + except getopt.GetoptError, err: + print >>sys.stderr, 'Error:', err sys.exit( 2 ) outputdir = '.' verbose = False format = None for option, value in opts: - if option == '-h': - print __doc__ + if option in ('-h', '--help'): + sys.stdout.write( __doc__ ) sys.exit( 0 ) - elif option == '-V': + elif option in ('-V', '--version'): print __version__ sys.exit( 0 ) elif option == '-@': @@ -115,128 +107,114 @@ args.extend( line.rstrip( '\n' ) for line in sys.stdin ) else: args.extend( line.rstrip( '\n' ) for line in open( value ) ) - elif option == '-v': + elif option in ('-v', '--progress'): verbose = True - elif option == '-f': + elif option in ('-f', '--format'): format = value elif option in ('-o', '--output'): outputdir = value - elif option == '-s': + elif option in ('-s', '--symbolic'): mklink = os.symlink if verbose: import progress_display - args = progress_display.progress_iter( args, os.path.basename, sys.stderr ) + args = progress_display.progress_iter( args ) for fb2name in args: + srcpath = os.path.abspath( fb2name ) #if verbose: # print fb2name - f = file( fb2name ) - data = '' - while True: - data += f.read( 1 << 13 ) - try: - doc = xml_re.match( data ).group() + '\n' + desc_re.search( data ).group() - except AttributeError: - continue - break - f.close() - doc = doc.replace( 'xlink:href=', 'href=' ).replace( 'l:href=', 'href=' ) - try: - description = xml.etree.ElementTree.fromstring( doc ) - except: - print description - raise + f = open( srcpath ) + data = '' + while True: + data += f.read( 1 << 13 ) + try: + doc = xml_re.match( data ).group() + '\n' + desc_re.search( data ).group() + except AttributeError: + continue + break + f.close() + doc = doc.replace( 'xlink:href=', 'href=' ).replace( 'l:href=', 'href=' ) - title_info = description.find( 'title-info' ) + try: + description = xml.etree.ElementTree.fromstring( doc ) + except: + print doc + raise - authornames = [] - for author in title_info.findall( 'author' ): - first_name = get_text( author.find( 'first-name' ) ) - last_name = get_text( author.find( 'last-name' ) ) - authorname = [last_name, first_name] + [get_text( middle_name ) for middle_name in author.findall( 'middle-name' )] - authorname = ' '.join( [name for name in authorname if name] ) - nickname = get_text( author.find( 'nickname' ) ) - if nickname: - authorname += ' [%s]' % nickname - authornames.append( authorname ) - translatornames = [] - for author in title_info.findall( 'translator' ): - first_name = get_text( author.find( 'first-name' ) ) - last_name = get_text( author.find( 'last-name' ) ) - authorname = [last_name, first_name] + [get_text( middle_name ) for middle_name in author.findall( 'middle-name' )] - authorname = ' '.join( [name for name in authorname if name] ) - nickname = get_text( author.find( 'nickname' ) ) - if nickname: - authorname += ' [%s]' % nickname - translatornames.append( authorname ) + title_info = description.find( 'title-info' ) + authornames = [getauthorname( author ) for author in title_info.findall( 'author' )] + translatornames = [getauthorname( author ) for author in title_info.findall( 'translator' )] - book_title = get_text( title_info.find( 'book-title' ) ) - lang = get_text( title_info.find( 'lang' ) ) - srclang = get_text( title_info.find( 'src-lang' ) ) or os.path.join( 'unknown', lang ) + book_title = title_info.findtext( 'book-title' ) + lang = title_info.findtext( 'lang' ) + src_lang = title_info.findtext( 'src-lang' ) - genres = [get_text( genre ) for genre in title_info.findall( 'genre' )] - sequences = [(sequence.get( 'name' ), sequence.get( 'number' ), sequence.get( 'src-name' )) for sequence in title_info.findall( 'sequence' )] + genres = [genre.text for genre in title_info.findall( 'genre' )] + sequences = [(sequence.get( 'name' ), sequence.get( 'number' ), sequence.get( 'src-name' )) for sequence in title_info.findall( 'sequence' )] - #print ('%s "%s"' % (', '.join( authornames ), book_title)).ljust(50)[:50].encode( filesystemencoding ), + if len( authornames ) > 4: + authornames_str = ', '.join( authornames[:4] ) + ',..' + else: + authornames_str = ', '.join( authornames ) - if len( authornames ) > 4: - authornames_str = ', '.join( authornames[:4] ) + u',..' - else: - authornames_str = ', '.join( authornames ) + if len( book_title ) > 120: + book_title = book_title[:120] + '...' - try: - if format == 'translators': - basedir = outputdir.decode( filesystemencoding ) - for authorname in translatornames: - os.symlink( os.path.abspath( fb2name ), genname( os.path.join( basedir, authorname ), book_title + '.fb2' ) ) if format == 'authors': - basedir = os.path.join( outputdir.decode( filesystemencoding ), lang ) - path = genname( os.path.join( basedir, authornames_str ), book_title + '.fb2', fb2name ) + basedir = os.path.join( outputdir, lang ) + path = genname( os.path.join( basedir, authornames_str ), book_title + '.fb2', srcpath ) if path: - mklink( os.path.abspath( fb2name ), path ) - if len( authornames ) > 1: - mainname = os.path.join( '..', authornames_str, os.path.basename( path ) ) - for authorname in authornames: - os.symlink( mainname, genname( os.path.join( basedir, authorname ), book_title + '.fb2' ) ) - if format == 'authors-src': - basedir = os.path.join( outputdir.decode( filesystemencoding ), srclang ) - path = genname( os.path.join( basedir, authornames_str ), book_title + '.fb2', fb2name ) + mklink( srcpath, path ) + linkauthors( path, authornames, book_title ) + elif format == 'authors-src': + basedir = os.path.join( outputdir, src_lang or lang ) + path = genname( os.path.join( basedir, authornames_str ), book_title + '.fb2', srcpath ) if path: - mklink( os.path.abspath( fb2name ), path ) - if len( authornames ) > 1: - mainname = os.path.join( '..', authornames_str, os.path.basename( path ) ) - for authorname in authornames: - os.symlink( mainname, genname( os.path.join( basedir, authorname ), book_title + '.fb2' ) ) - if format == 'series': + mklink( srcpath, path ) + linkauthors( path, authornames, book_title ) + elif format == 'series': for sequence_name, sequence_number, sequence_src_name in sequences: + dirname = sequence_name if sequence_src_name: - path0 = os.path.join( outputdir, lang, ( '%s [%s] : %s' % ( sequence_name, sequence_src_name, authornames_str ) )[:120] ) - else: - path0 = os.path.join( outputdir, lang, ( '%s : %s' % ( sequence_name, authornames_str ) )[:120] ) - # path0 = os.path.join( outputdir, lang, sequence_name, authornames_str ) - if sequence_number != '': - path = genname( path0, '%s. %s.fb2' % ( sequence_number, book_title ), fb2name ) - else: - path = genname( path0, '%s.fb2' % book_title, fb2name ) + dirname += ' [%s]' % sequence_src_name + dirname += ' : ' + authornames_str + filename = book_title + '.fb2' + if sequence_number: + filename = sequence_number + '. ' + filename + path = genname( os.path.join( outputdir, lang, dirname[:120] ), filename, srcpath ) if path: - mklink( os.path.abspath( fb2name ), path ) - if format == 'genres': - for genre in genres: + mklink( srcpath, path ) + elif format == 'genres': + for genre in genres or ('?'): basedir = os.path.join( outputdir, lang, genre ) - path = genname( os.path.join( basedir, authornames_str ), book_title + '.fb2', fb2name ) + path = genname( os.path.join( basedir, authornames_str ), book_title + '.fb2', srcpath ) if path: - mklink( os.path.abspath( fb2name ), path ) - mainname = os.path.join( '..', authornames_str, os.path.basename( path ) ) - if len( authornames ) > 1: - for authorname in authornames: - os.symlink( mainname, genname( os.path.join( basedir, authorname ), book_title + '.fb2' ) ) + mklink( srcpath, path ) + linkauthors( path, authornames, book_title ) + elif format == 'translators': + basedir = outputdir + if not translatornames and lang != src_lang: + translatornames = ('?') + for authorname in translatornames: + mklink( srcpath, genname( os.path.join( basedir, authorname ), ( authornames_str + '. ' + book_title )[:120] + '.fb2' ) ) + elif format == 'date': + date = title_info.find( 'date' ) + if date is not None: + date_str = date.text or '?' + if date.get( 'value' ): + date_str += ' [%s]' % date.get( 'value' ) + date_str = date_str or '?' + basedir = os.path.join( outputdir, date_str ) + path = genname( os.path.join( basedir, authornames_str ), book_title + '.fb2', srcpath ) + if path: + mklink( srcpath, path ) except (KeyboardInterrupt, SystemExit): raise except Exception, err: - print >>sys.stderr, 'Error processing %s:' % fb2name + print >>sys.stderr, 'Error processing "%s":' % fb2name print >>sys.stderr, err sys.exit( 1 ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sto...@us...> - 2009-11-28 17:50:25
|
Revision: 61 http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=61&view=rev Author: storchaka Date: 2009-11-28 17:50:15 +0000 (Sat, 28 Nov 2009) Log Message: ----------- Set svn:mime-type and svn:eol-style. Property Changed: ---------------- trunk/fb2-python-tools/dict/bulgarian.words trunk/fb2-python-tools/dict/english.words trunk/fb2-python-tools/dict/french.words trunk/fb2-python-tools/dict/german.words trunk/fb2-python-tools/dict/italian.words trunk/fb2-python-tools/dict/ngerman.words trunk/fb2-python-tools/dict/ogerman.words trunk/fb2-python-tools/dict/polish.words trunk/fb2-python-tools/dict/portuguese.words trunk/fb2-python-tools/dict/russian.words trunk/fb2-python-tools/dict/spanish.words trunk/fb2-python-tools/dict/swedish.words trunk/fb2-python-tools/dict/ukrainian.words trunk/fb2-python-tools/dict/web2.words trunk/fb2-python-tools/fb2clean.py trunk/fb2-python-tools/fb2fixtr.py trunk/fb2-python-tools/fb2format.py trunk/fb2-python-tools/progress_display.py trunk/fb2-python-tools/replaces trunk/fb2-python-tools/reserved trunk/fb2-python-tools/reserved_cyr trunk/fb2-python-tools/reserved_lat Property changes on: trunk/fb2-python-tools/dict/bulgarian.words ___________________________________________________________________ Modified: svn:mime-type - application/octet-stream + text/plain Added: svn:eol-style + native Property changes on: trunk/fb2-python-tools/dict/english.words ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Property changes on: trunk/fb2-python-tools/dict/french.words ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Property changes on: trunk/fb2-python-tools/dict/german.words ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Property changes on: trunk/fb2-python-tools/dict/italian.words ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Property changes on: trunk/fb2-python-tools/dict/ngerman.words ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Property changes on: trunk/fb2-python-tools/dict/ogerman.words ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Property changes on: trunk/fb2-python-tools/dict/polish.words ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Property changes on: trunk/fb2-python-tools/dict/portuguese.words ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Property changes on: trunk/fb2-python-tools/dict/russian.words ___________________________________________________________________ Modified: svn:mime-type - application/octet-stream + text/plain Added: svn:eol-style + native Property changes on: trunk/fb2-python-tools/dict/spanish.words ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Property changes on: trunk/fb2-python-tools/dict/swedish.words ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Property changes on: trunk/fb2-python-tools/dict/ukrainian.words ___________________________________________________________________ Modified: svn:mime-type - application/octet-stream + text/plain Added: svn:eol-style + native Property changes on: trunk/fb2-python-tools/dict/web2.words ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Property changes on: trunk/fb2-python-tools/fb2clean.py ___________________________________________________________________ Added: svn:mime-type + text/x-python Added: svn:eol-style + native Property changes on: trunk/fb2-python-tools/fb2fixtr.py ___________________________________________________________________ Added: svn:mime-type + text/x-python Added: svn:eol-style + native Property changes on: trunk/fb2-python-tools/fb2format.py ___________________________________________________________________ Added: svn:mime-type + text/x-python Added: svn:eol-style + native Property changes on: trunk/fb2-python-tools/progress_display.py ___________________________________________________________________ Added: svn:mime-type + text/x-python Added: svn:eol-style + native Property changes on: trunk/fb2-python-tools/replaces ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Property changes on: trunk/fb2-python-tools/reserved ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Property changes on: trunk/fb2-python-tools/reserved_cyr ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Property changes on: trunk/fb2-python-tools/reserved_lat ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sto...@us...> - 2009-11-28 16:16:01
|
Revision: 60 http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=60&view=rev Author: storchaka Date: 2009-11-28 16:15:54 +0000 (Sat, 28 Nov 2009) Log Message: ----------- Add fb2maketree.py. Added Paths: ----------- trunk/fb2-python-tools/fb2maketree.py Added: trunk/fb2-python-tools/fb2maketree.py =================================================================== --- trunk/fb2-python-tools/fb2maketree.py (rev 0) +++ trunk/fb2-python-tools/fb2maketree.py 2009-11-28 16:15:54 UTC (rev 60) @@ -0,0 +1,242 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- + +'''\ +Usage: + fb2maketree.py [<options>] [<fb2-files>] +Options: + -h display this help message and exit + -V display the version and exit + -f <format> use tree format (translators, authors, authors-src, series, genres) + -o, --output <dir> tree base directory + -s make symbolic links instead of hard links + -@ <file> read file names from file (one name per line) + -v display progressbar +File name '-' means standard input/output. +''' + +__author__ = 'Serhiy Storchaka <sto...@us...>' +__version__ = '0.1' +__all__ = [] + +try: + import psyco + psyco.full() +except: + pass +import sys, xml.etree.ElementTree, re, getopt, os, os.path, filecmp + +filesystemencoding = sys.getfilesystemencoding() +# filesystemencoding = 'utf-8' + +def get_text( node ): + if node is None: + return '' + text = node.text + if text is None: + return '' + return text.strip() + +def genname( dirname, filename, otherpath = None ): + filename = filename.replace( '"', "'" ) + filename = filename.replace( ':', '.' ) + for c in '+/<>\\|': + filename = filename.replace( c, '_' ) + basename, suffix = os.path.splitext( filename ) + try: + if not os.path.exists( dirname ): + os.makedirs( dirname ) + except os.error, e: + print >>sys.stderr, e + pass + count = 0 + path = os.path.join( dirname, filename ) + while os.access( path, os.F_OK ): + if otherpath and filecmp.cmp( path, otherpath, 0 ): +# if data and os.path.getsize( path ) == len( data ) and open( path ).read() == data: + print '#', path.encode( filesystemencoding ) + return None + count += 1 + path = os.path.join( dirname, '%s__%d%s' % (basename, count, suffix) ) + if count > 0: + print '!', path.encode( filesystemencoding ) + return path + +def mklink( src, dst ): + try: + os.link( src, dst ) + except OSError, err: + os.symlink( src, dst ) + print '@', dst.encode( filesystemencoding ) + +def linkauthors( basedir, authornames, book_title, fb2name ): + if len( authornames ) > 4: + authornames_str = ', '.join( authornames[:4] ) + u',..' + else: + authornames_str = ', '.join( authornames ) + + path = genname( os.path.join( basedir, authornames_str ), book_title + '.fb2', fb2name ) + if path: + mklink( os.path.abspath( fb2name ), path ) + if len( authornames ) > 1: + mainname = os.path.join( '..', authornames_str, os.path.basename( path ) ) + for authorname in authornames: + os.symlink( mainname, genname( os.path.join( basedir, authorname ), book_title + '.fb2' ) ) + +xml_re = re.compile( r'<\?xml version="(?:[^">]*)" encoding="(?:[^">]*)"\?>', re.DOTALL ) +desc_re = re.compile( r'<description>.*?</description>', re.DOTALL ) +def parse( data ): + return xml.dom.minidom.parseString( + xml_re.match( data ).group() + + desc_re.search( data ).group(). + replace( 'xlink:href=', 'href=' ). + replace( 'l:href=', 'href=' ) + ) + +if __name__ == '__main__': + try: + opts, args = getopt.getopt( sys.argv[1:], '@:hf:o:svV', ['output='] ) + except getopt.GetoptError: + # print help information and exit: + print >>sys.stderr, 'Illegal option' + sys.exit( 2 ) + outputdir = '.' + verbose = False + format = None + for option, value in opts: + if option == '-h': + print __doc__ + sys.exit( 0 ) + elif option == '-V': + print __version__ + sys.exit( 0 ) + elif option == '-@': + if value == '-': + args.extend( line.rstrip( '\n' ) for line in sys.stdin ) + else: + args.extend( line.rstrip( '\n' ) for line in open( value ) ) + elif option == '-v': + verbose = True + elif option == '-f': + format = value + elif option in ('-o', '--output'): + outputdir = value + elif option == '-s': + mklink = os.symlink + + if verbose: + import progress_display + args = progress_display.progress_iter( args, os.path.basename, sys.stderr ) + + for fb2name in args: + #if verbose: + # print fb2name + f = file( fb2name ) + data = '' + while True: + data += f.read( 1 << 13 ) + try: + doc = xml_re.match( data ).group() + '\n' + desc_re.search( data ).group() + except AttributeError: + continue + break + f.close() + doc = doc.replace( 'xlink:href=', 'href=' ).replace( 'l:href=', 'href=' ) + + try: + description = xml.etree.ElementTree.fromstring( doc ) + except: + print description + raise + + title_info = description.find( 'title-info' ) + + authornames = [] + for author in title_info.findall( 'author' ): + first_name = get_text( author.find( 'first-name' ) ) + last_name = get_text( author.find( 'last-name' ) ) + authorname = [last_name, first_name] + [get_text( middle_name ) for middle_name in author.findall( 'middle-name' )] + authorname = ' '.join( [name for name in authorname if name] ) + nickname = get_text( author.find( 'nickname' ) ) + if nickname: + authorname += ' [%s]' % nickname + authornames.append( authorname ) + translatornames = [] + for author in title_info.findall( 'translator' ): + first_name = get_text( author.find( 'first-name' ) ) + last_name = get_text( author.find( 'last-name' ) ) + authorname = [last_name, first_name] + [get_text( middle_name ) for middle_name in author.findall( 'middle-name' )] + authorname = ' '.join( [name for name in authorname if name] ) + nickname = get_text( author.find( 'nickname' ) ) + if nickname: + authorname += ' [%s]' % nickname + translatornames.append( authorname ) + + + book_title = get_text( title_info.find( 'book-title' ) ) + lang = get_text( title_info.find( 'lang' ) ) + srclang = get_text( title_info.find( 'src-lang' ) ) or os.path.join( 'unknown', lang ) + + genres = [get_text( genre ) for genre in title_info.findall( 'genre' )] + sequences = [(sequence.get( 'name' ), sequence.get( 'number' ), sequence.get( 'src-name' )) for sequence in title_info.findall( 'sequence' )] + + + #print ('%s "%s"' % (', '.join( authornames ), book_title)).ljust(50)[:50].encode( filesystemencoding ), + + if len( authornames ) > 4: + authornames_str = ', '.join( authornames[:4] ) + u',..' + else: + authornames_str = ', '.join( authornames ) + + try: + if format == 'translators': + basedir = outputdir.decode( filesystemencoding ) + for authorname in translatornames: + os.symlink( os.path.abspath( fb2name ), genname( os.path.join( basedir, authorname ), book_title + '.fb2' ) ) + if format == 'authors': + basedir = os.path.join( outputdir.decode( filesystemencoding ), lang ) + path = genname( os.path.join( basedir, authornames_str ), book_title + '.fb2', fb2name ) + if path: + mklink( os.path.abspath( fb2name ), path ) + if len( authornames ) > 1: + mainname = os.path.join( '..', authornames_str, os.path.basename( path ) ) + for authorname in authornames: + os.symlink( mainname, genname( os.path.join( basedir, authorname ), book_title + '.fb2' ) ) + if format == 'authors-src': + basedir = os.path.join( outputdir.decode( filesystemencoding ), srclang ) + path = genname( os.path.join( basedir, authornames_str ), book_title + '.fb2', fb2name ) + if path: + mklink( os.path.abspath( fb2name ), path ) + if len( authornames ) > 1: + mainname = os.path.join( '..', authornames_str, os.path.basename( path ) ) + for authorname in authornames: + os.symlink( mainname, genname( os.path.join( basedir, authorname ), book_title + '.fb2' ) ) + if format == 'series': + for sequence_name, sequence_number, sequence_src_name in sequences: + if sequence_src_name: + path0 = os.path.join( outputdir, lang, ( '%s [%s] : %s' % ( sequence_name, sequence_src_name, authornames_str ) )[:120] ) + else: + path0 = os.path.join( outputdir, lang, ( '%s : %s' % ( sequence_name, authornames_str ) )[:120] ) + # path0 = os.path.join( outputdir, lang, sequence_name, authornames_str ) + if sequence_number != '': + path = genname( path0, '%s. %s.fb2' % ( sequence_number, book_title ), fb2name ) + else: + path = genname( path0, '%s.fb2' % book_title, fb2name ) + if path: + mklink( os.path.abspath( fb2name ), path ) + if format == 'genres': + for genre in genres: + basedir = os.path.join( outputdir, lang, genre ) + path = genname( os.path.join( basedir, authornames_str ), book_title + '.fb2', fb2name ) + if path: + mklink( os.path.abspath( fb2name ), path ) + mainname = os.path.join( '..', authornames_str, os.path.basename( path ) ) + if len( authornames ) > 1: + for authorname in authornames: + os.symlink( mainname, genname( os.path.join( basedir, authorname ), book_title + '.fb2' ) ) + except (KeyboardInterrupt, SystemExit): + raise + except Exception, err: + print >>sys.stderr, 'Error processing %s:' % fb2name + print >>sys.stderr, err + sys.exit( 1 ) Property changes on: trunk/fb2-python-tools/fb2maketree.py ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/x-python Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sto...@us...> - 2009-11-28 10:15:42
|
Revision: 59 http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=59&view=rev Author: storchaka Date: 2009-11-28 10:15:34 +0000 (Sat, 28 Nov 2009) Log Message: ----------- Fix my email. Modified Paths: -------------- trunk/fb2-python-tools/fb2clean.py trunk/fb2-python-tools/fb2fixtr.py trunk/fb2-python-tools/fb2format.py Modified: trunk/fb2-python-tools/fb2clean.py =================================================================== --- trunk/fb2-python-tools/fb2clean.py 2008-04-09 05:12:17 UTC (rev 58) +++ trunk/fb2-python-tools/fb2clean.py 2009-11-28 10:15:34 UTC (rev 59) @@ -12,7 +12,7 @@ -v display progressbar File name '-' means standard input/output. ''' -__author__ = 'Serhiy Storchaka <sto...@so...>' +__author__ = 'Serhiy Storchaka <sto...@us...>' __version__ = '0.1' __all__ = [] Modified: trunk/fb2-python-tools/fb2fixtr.py =================================================================== --- trunk/fb2-python-tools/fb2fixtr.py 2008-04-09 05:12:17 UTC (rev 58) +++ trunk/fb2-python-tools/fb2fixtr.py 2009-11-28 10:15:34 UTC (rev 59) @@ -17,7 +17,7 @@ -o logfile log all fixes to logfile File name '-' means standard input/output. ''' -__author__ = 'Serhiy Storchaka <sto...@so...>' +__author__ = 'Serhiy Storchaka <sto...@us...>' __version__ = '0.1' __all__ = [] Modified: trunk/fb2-python-tools/fb2format.py =================================================================== --- trunk/fb2-python-tools/fb2format.py 2008-04-09 05:12:17 UTC (rev 58) +++ trunk/fb2-python-tools/fb2format.py 2009-11-28 10:15:34 UTC (rev 59) @@ -17,7 +17,7 @@ File name '-' means standard input/output. ''' -__author__ = 'Serhiy Storchaka <sto...@so...>' +__author__ = 'Serhiy Storchaka <sto...@us...>' __version__ = '0.1' try: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2008-04-09 05:12:36
|
Revision: 58 http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=58&view=rev Author: shaplov Date: 2008-04-08 22:12:17 -0700 (Tue, 08 Apr 2008) Log Message: ----------- Patch from Alex Nekipelov: now html2fb2 adds images from html file if possible... Modified Paths: -------------- trunk/fb2-perl-tools/html2fb2.pl Modified: trunk/fb2-perl-tools/html2fb2.pl =================================================================== --- trunk/fb2-perl-tools/html2fb2.pl 2008-01-27 19:40:02 UTC (rev 57) +++ trunk/fb2-perl-tools/html2fb2.pl 2008-04-09 05:12:17 UTC (rev 58) @@ -109,6 +109,7 @@ my $Author; my $report_styles; # styles my %sect_styles; # styles to use as sections +my %images; # fetch options my %options; @@ -352,6 +353,38 @@ push(@elist,[ $depth, $txt ]); } +sub add_image { + my ($src) = shift; + + if( -f $src ) { + unless( defined $images{$src} ) { + unless( $src =~ /\.(jpe?g)$/i ) { + my $new = $src; + $new =~ s/\.\w+$/\.jpg/; + + if( system(qq{convert "$src" "$new"}) == 0 ) { + $src = $new; + } else { + print STDERR "Can`t convert image $src\n"; + return; # :-( + } + } + use MIME::Base64; + my $data; + + open INPUT, "<$src" or die "Can`t open image: $!"; + binmode INPUT; + $data .= $_ while <INPUT>; + close INPUT; + + $data = encode_base64( $data ); + $images{$src} = $data; + } + pbreak; + $textbuf .= "<image xlink:href=\"#$src\" />"; + } +} + sub get_styles { my $styles=$_[0]->attr('style'); return () unless $styles; @@ -460,6 +493,10 @@ --$strong; checkhl; return; + } elsif ($t eq 'img') { + my $src = $elem->attr('src'); + add_image( $src ); + return; } elsif ($t eq "a") { my $href=$elem->attr('href'); my $name=$elem->attr('name'); @@ -629,6 +666,7 @@ } } remove_empty_sections($root); + print STDERR "done.\n"; print STDERR "Writing XML... " unless $print_toc; @@ -726,10 +764,16 @@ section($root); } -print $outfile <<EOF ; - </body> -</FictionBook> -EOF +print $outfile "\n</body>\n"; + +if( scalar(keys %images) > 0 ) { + foreach(keys %images) { + print $outfile qq{<binary content-type="image/jpeg" id="$_">$images{$_}</binary>\n}; + } +} + +print $outfile "\n</FictionBook>\n"; + print STDERR "done.\n" unless $print_toc; exit 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2008-01-27 19:40:30
|
Revision: 57 http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=57&view=rev Author: shaplov Date: 2008-01-27 11:40:02 -0800 (Sun, 27 Jan 2008) Log Message: ----------- now use Getopt::Long to get oprions move outfile to --outfile option Modified Paths: -------------- trunk/fb2-perl-tools/fb22htmls Modified: trunk/fb2-perl-tools/fb22htmls =================================================================== --- trunk/fb2-perl-tools/fb22htmls 2008-01-27 17:58:54 UTC (rev 56) +++ trunk/fb2-perl-tools/fb22htmls 2008-01-27 19:40:02 UTC (rev 57) @@ -28,42 +28,54 @@ use fb2::Convert::Htmls; +use Getopt::Long qw(HelpMessage VersionMessage); use strict; +our $VERSION = 0.02; + my $xsl_file=$ENV{FB2_PERL_TOOLS}; $xsl_file.="/" if $xsl_file && $xsl_file =~ /[^\/]$/; $xsl_file.="XSL/fb22htmls.xsl"; + my $Mute=0; my $SectionSize=30000; my $MinSectionSize=20000; +my $OutFileName = ''; + #============================================================= -if (!$ARGV[1]){print "\nkolbasorezka.pl by GribUser v 0.01\nUsage:\n\nkolbasorezka.pl <inputfile.fb2> <outputfile> [-options] +if (! @ARGV) { print " +FB2 to HTMLs convertor v$VERSION +Usage: - outputfile name will be used to create new files. - outputfile_page#.html files will be created +fb22html [-options] <inputfile.fb2> Options available - -mute Do not print progress messages. - -partsize <number> Set part size (default is $SectionSize) - -minsize <number> Set minimum part size (default is $MinSectionSize) + --mute Do not print progress messages. + --partsize=<number> Set part size (default is $SectionSize) + --minsize=<number> Set minimum part size (default is $MinSectionSize) + --outfile=<file_name> Base name for output htmls (default is infputfile stripped of .fb2 or .xml extentions) + outfile name will be used to create new files. + outfile_<page#>.html files will be created + ";exit 0;} #============================================================= -my $FileToParce=$ARGV[0]; -my $OutFileName=$ARGV[1]; -for (my $I=2;$I<@ARGV;$I++){ - $Mute=1 if $ARGV[$I] eq '-mute'; - if ($ARGV[$I] eq '-partsize'){ - $SectionSize=$ARGV[$I+1] if $ARGV[$I+1]; - $I++; - } - if ($ARGV[$I] eq '-minsize'){ - $MinSectionSize=$ARGV[$I+1] if $ARGV[$I+1]; - $I++; - } +GetOptions ( help=>sub {HelpMessage(); }, + version=>sub {VersionMessage(); }, + "mute" => \$Mute, + 'partsize=i' => \$SectionSize, + 'minsize=i'=> \$MinSectionSize, + 'outfile=s'=> \$OutFileName + ); +my $FileToParce = shift @ARGV; + +if (!$OutFileName) +{ + $OutFileName = $FileToParce; + $OutFileName =~ s/\.xml|\.fb2$//i; } fb2::Convert::Htmls::Kolbasim($FileToParce,$xsl_file,$OutFileName,$SectionSize,$MinSectionSize,$Mute); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2008-01-27 17:58:48
|
Revision: 56 http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=56&view=rev Author: shaplov Date: 2008-01-27 09:58:54 -0800 (Sun, 27 Jan 2008) Log Message: ----------- Editing fb22htmls Step1 Modified Paths: -------------- trunk/fb2-perl-tools/XSL/fb22htmls.xsl trunk/fb2-perl-tools/fb2/Convert/Htmls.pm trunk/fb2-perl-tools/fb22htmls Modified: trunk/fb2-perl-tools/XSL/fb22htmls.xsl =================================================================== --- trunk/fb2-perl-tools/XSL/fb22htmls.xsl 2008-01-27 17:52:52 UTC (rev 55) +++ trunk/fb2-perl-tools/XSL/fb22htmls.xsl 2008-01-27 17:58:54 UTC (rev 56) @@ -1,5 +1,31 @@ +<!-- Copyright (c) 2004 Dmitry Gribov (GribUser) + 2008 Nikolay Shaplov + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --> + <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:fb="http://www.gribuser.ru/xml/fictionbook/2.0"> - <xsl:output method="html" encoding="windows-1251"/> + <xsl:output method="html" encoding="utf-8"/> <xsl:param name="PageN">1</xsl:param> <xsl:param name="TotalPages">1</xsl:param> <xsl:param name="BookTitle">NoName</xsl:param> Modified: trunk/fb2-perl-tools/fb2/Convert/Htmls.pm =================================================================== --- trunk/fb2-perl-tools/fb2/Convert/Htmls.pm 2008-01-27 17:52:52 UTC (rev 55) +++ trunk/fb2-perl-tools/fb2/Convert/Htmls.pm 2008-01-27 17:58:54 UTC (rev 56) @@ -1,186 +1,214 @@ -#!/usr/bin/perl -package FB2ToManyHTML; - -use XML::Parser; -use XML::LibXSLT; -use XML::LibXML; -use strict; -no warnings; - -my $Mute; -my $SectionSize; -my $MinSectionSize; - -my @BodyParts; -my $RootAttrs; -my $BookTitle; - -sub Kolbasim{ - my $FileToParce=shift; - my $StyleSheet=shift; - my $OutFileName=shift; - $SectionSize=shift; - $MinSectionSize=shift; - $Mute=shift; - ($RootAttrs,$BookTitle,@BodyParts)=&SplitBook($FileToParce); - return TransformParts($StyleSheet,$OutFileName,$RootAttrs,$BookTitle,@BodyParts); -} - -sub SplitBook{ - my $FileToParce=shift; - my $I; - my $CurDeepness=0; - my ($CurPart,$InBinary,$InHead); - my $Description; - my @BodyAsArray; - my $PartSize=0; - my $PartStarted=1; - my $InSectionTitle=0; - my $AllowSectionTitle=0; - my $CanCutHere=1; - my $SectionTitle; - my @ContentParts; - my $InNotesBody; - my $RootAttrs; - my $BookTitle; - my $InBookTitle; - my $SplitParser=new XML::Parser(Handlers => { - Start => sub { - my $expat=shift; - my $elem=shift; - my %Params=@_; - $I++; - print "Working element #$I\r" unless $Mute; - - $InHead = 1 if $elem eq 'description'; - $InBinary=($elem eq 'description')?1:0; - $CurPart='' if $elem=~/\Adescription\Z/; - if ($elem eq 'FictionBook'){ - for (keys(%Params)){ - $RootAttrs.=" $_=\"".xmlescape($Params{$_})."\"" unless $_ eq 'xmlns'; - } - } - $InBookTitle=$elem eq 'book-title'?1:0 ; - unless ($elem eq 'section'){ - if ($elem eq 'title'){ - $Params{'deepness'}=$InNotesBody?5:$CurDeepness; - $Params{'number'}=scalar @BodyAsArray; - } - $CurPart.="<$elem"; - for (keys(%Params)){ - $CurPart.=" $_=\"".xmlescape($Params{$_})."\""; - } - $CurPart.=">"; - }else{ - $CurDeepness++; - } - $AllowSectionTitle=0 if $elem eq 'poem'; - $InSectionTitle=1 if ($AllowSectionTitle && $elem eq 'title'); - if ($elem=~/\A(title|epigraph|annotation|poem|cite)\Z/){ - $CanCutHere=0; - } - if ($elem=~/\A(section|body)\Z/){ -# $CurPart='' unless $InNotesBody; - $CurPart='' if $elem eq 'body'; - $PartSize=0 if $elem eq 'body'; - $PartStarted=1; - $AllowSectionTitle=1; - $SectionTitle=''; - $InNotesBody=1 if ($elem eq 'body' && $Params{'name'}=~/\Anotes\Z/i); - } - }, - Char => sub { - $PartSize+=length($_[1]); - $CurPart.=xmlescape($_[1]) unless $InBinary; - $SectionTitle.=xmlescape($_[1]) if $InSectionTitle; - $BookTitle.=xmlescape($_[1]) if $InBookTitle; - }, - End => sub { - my $elem=$_[1]; - $CurPart.="</".$_[1].">" unless $elem=~ /(section|body)/; - if (((!$InHead && $CanCutHere && $elem eq 'p' && $PartSize>=$SectionSize) || - ($elem eq 'section' && $PartSize>=$MinSectionSize) || $elem eq 'description') && !$InNotesBody || $elem eq 'body') { - my %t=( - 'parstart'=>$PartStarted, - 'partcontent'=>$CurPart, - 'level'=>$CurDeepness - ); - push(@BodyAsArray,\%t) unless $CurPart=~/\A\s+\Z/; - $CurPart=''; - $PartSize=0; - $PartStarted=0; - $InHead=0 if $_[1] eq 'description'; - } - $CurDeepness-- if $_[1] eq 'section'; - if ($elem=~/\A(title|epigraph|annotation|poem|cite)\Z/){ - $CanCutHere=1; - } - $AllowSectionTitle=0 if $elem eq 'section'; - - if ($elem eq 'p' && $InSectionTitle && $SectionTitle){ - my %t=('title'=>$SectionTitle,'N'=>(scalar @BodyAsArray), 'deep'=>$CurDeepness); - push (@ContentParts,\%t); - $InSectionTitle=0; - $SectionTitle=''; - $AllowSectionTitle=0; - } - } - }); - - $SplitParser->parsefile($FileToParce) or die $!; - $SplitParser=undef; - for (@ContentParts){ - $BodyAsArray[0]->{'partcontent'}.="<toc-item n=\"".$_->{'N'}."\" deep=\"".$_->{'deep'}."\">".$_->{'title'}."</toc-item>\n"; - } - return ($RootAttrs,$BookTitle,@BodyAsArray); -} - -sub TransformParts{ - my $StyleSheet=shift; - my $OutFileName=shift; - my $RootAttrs=shift; - my $BookTitle=shift; - my @Parts=@_; - my $OutFileSHort=$OutFileName; - $OutFileSHort=~s/\A(.*[\/\\])?([^\/\\]*)\Z/$2/; - for (my $I=0;$I<@Parts;$I++){ - my $ItemLength=$Parts[$I]->{'title'}; - print "Generating file ${OutFileName}_$I.html...\n" unless $Mute; - my $Result=TransformXML("<part$RootAttrs>".$Parts[$I]->{'partcontent'}."</part>", - $StyleSheet,'PageN'=>"'$I'", - 'TotalPages'=>'"'.(@Parts-1).'"', - 'FileName'=>"'$OutFileSHort'", - 'BookTitle'=>"'$BookTitle'"); - open OUTFILE,">${OutFileName}_$I.html"; - print OUTFILE $Result; - close OUTFILE; - } - return scalar(@Parts); -} - -sub xmlescape { - my %escapes=( - '&' => '&', - '<' => '<', - '>' => '>', - '"' => '"', - "'" => ''' - ); - $b=shift; - $_=$b; - s/([&<>'"])/$escapes{$1}/gs; - $_; -} - -sub TransformXML{ - my $XML=shift; - my $XSL=shift; - my $parser = XML::LibXML->new(); - my $xslt = XML::LibXSLT->new(); - my $source = $parser->parse_string($XML); - my $style_doc = $parser->parse_file($XSL); - my $stylesheet = $xslt->parse_stylesheet($style_doc); - my $results = $stylesheet->transform($source,@_); - $stylesheet->output_string($results); -} +#!/usr/bin/perl + +# Copyright (c) 2004 Dmitry Gribov (GribUser) +# 2008 Nikolay Shaplov +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. The name of the author may not be used to endorse or promote products +# derived from this software without specific prior written permission. + +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +package fb2::Convert::Htmls; + +use XML::Parser; +use XML::LibXSLT; +use XML::LibXML; +use strict; +no warnings; + +my $Mute; +my $SectionSize; +my $MinSectionSize; + +my @BodyParts; +my $RootAttrs; +my $BookTitle; + +sub Kolbasim{ + my $FileToParce=shift; + my $StyleSheet=shift; + my $OutFileName=shift; + $SectionSize=shift; + $MinSectionSize=shift; + $Mute=shift; + ($RootAttrs,$BookTitle,@BodyParts)=&SplitBook($FileToParce); + return TransformParts($StyleSheet,$OutFileName,$RootAttrs,$BookTitle,@BodyParts); +} + +sub SplitBook{ + my $FileToParce=shift; + my $I; + my $CurDeepness=0; + my ($CurPart,$InBinary,$InHead); + my $Description; + my @BodyAsArray; + my $PartSize=0; + my $PartStarted=1; + my $InSectionTitle=0; + my $AllowSectionTitle=0; + my $CanCutHere=1; + my $SectionTitle; + my @ContentParts; + my $InNotesBody; + my $RootAttrs; + my $BookTitle; + my $InBookTitle; + my $SplitParser=new XML::Parser(Handlers => { + Start => sub { + my $expat=shift; + my $elem=shift; + my %Params=@_; + $I++; + print "Working element #$I\r" unless $Mute; + + $InHead = 1 if $elem eq 'description'; + $InBinary=($elem eq 'description')?1:0; + $CurPart='' if $elem=~/\Adescription\Z/; + if ($elem eq 'FictionBook'){ + for (keys(%Params)){ + $RootAttrs.=" $_=\"".xmlescape($Params{$_})."\"" unless $_ eq 'xmlns'; + } + } + $InBookTitle=$elem eq 'book-title'?1:0 ; + unless ($elem eq 'section'){ + if ($elem eq 'title'){ + $Params{'deepness'}=$InNotesBody?5:$CurDeepness; + $Params{'number'}=scalar @BodyAsArray; + } + $CurPart.="<$elem"; + for (keys(%Params)){ + $CurPart.=" $_=\"".xmlescape($Params{$_})."\""; + } + $CurPart.=">"; + }else{ + $CurDeepness++; + } + $AllowSectionTitle=0 if $elem eq 'poem'; + $InSectionTitle=1 if ($AllowSectionTitle && $elem eq 'title'); + if ($elem=~/\A(title|epigraph|annotation|poem|cite)\Z/){ + $CanCutHere=0; + } + if ($elem=~/\A(section|body)\Z/){ +# $CurPart='' unless $InNotesBody; + $CurPart='' if $elem eq 'body'; + $PartSize=0 if $elem eq 'body'; + $PartStarted=1; + $AllowSectionTitle=1; + $SectionTitle=''; + $InNotesBody=1 if ($elem eq 'body' && $Params{'name'}=~/\Anotes\Z/i); + } + }, + Char => sub { + $PartSize+=length($_[1]); + $CurPart.=xmlescape($_[1]) unless $InBinary; + $SectionTitle.=xmlescape($_[1]) if $InSectionTitle; + $BookTitle.=xmlescape($_[1]) if $InBookTitle; + }, + End => sub { + my $elem=$_[1]; + $CurPart.="</".$_[1].">" unless $elem=~ /(section|body)/; + if (((!$InHead && $CanCutHere && $elem eq 'p' && $PartSize>=$SectionSize) || + ($elem eq 'section' && $PartSize>=$MinSectionSize) || $elem eq 'description') && !$InNotesBody || $elem eq 'body') { + my %t=( + 'parstart'=>$PartStarted, + 'partcontent'=>$CurPart, + 'level'=>$CurDeepness + ); + push(@BodyAsArray,\%t) unless $CurPart=~/\A\s+\Z/; + $CurPart=''; + $PartSize=0; + $PartStarted=0; + $InHead=0 if $_[1] eq 'description'; + } + $CurDeepness-- if $_[1] eq 'section'; + if ($elem=~/\A(title|epigraph|annotation|poem|cite)\Z/){ + $CanCutHere=1; + } + $AllowSectionTitle=0 if $elem eq 'section'; + + if ($elem eq 'p' && $InSectionTitle && $SectionTitle){ + my %t=('title'=>$SectionTitle,'N'=>(scalar @BodyAsArray), 'deep'=>$CurDeepness); + push (@ContentParts,\%t); + $InSectionTitle=0; + $SectionTitle=''; + $AllowSectionTitle=0; + } + } + }); + + $SplitParser->parsefile($FileToParce) or die $!; + $SplitParser=undef; + for (@ContentParts){ + $BodyAsArray[0]->{'partcontent'}.="<toc-item n=\"".$_->{'N'}."\" deep=\"".$_->{'deep'}."\">".$_->{'title'}."</toc-item>\n"; + } + return ($RootAttrs,$BookTitle,@BodyAsArray); +} + +sub TransformParts{ + my $StyleSheet=shift; + my $OutFileName=shift; + my $RootAttrs=shift; + my $BookTitle=shift; + my @Parts=@_; + my $OutFileSHort=$OutFileName; + $OutFileSHort=~s/\A(.*[\/\\])?([^\/\\]*)\Z/$2/; + for (my $I=0;$I<@Parts;$I++){ + my $ItemLength=$Parts[$I]->{'title'}; + print "Generating file ${OutFileName}_$I.html...\n" unless $Mute; + my $Result=TransformXML("<part$RootAttrs>".$Parts[$I]->{'partcontent'}."</part>", + $StyleSheet,'PageN'=>"'$I'", + 'TotalPages'=>'"'.(@Parts-1).'"', + 'FileName'=>"'$OutFileSHort'", + 'BookTitle'=>"'$BookTitle'"); + open OUTFILE,">${OutFileName}_$I.html"; + print OUTFILE $Result; + close OUTFILE; + } + return scalar(@Parts); +} + +sub xmlescape { + my %escapes=( + '&' => '&', + '<' => '<', + '>' => '>', + '"' => '"', + "'" => ''' + ); + $b=shift; + $_=$b; + s/([&<>'"])/$escapes{$1}/gs; #' + $_; +} + +sub TransformXML{ + my $XML=shift; + my $XSL=shift; + my $parser = XML::LibXML->new(); + my $xslt = XML::LibXSLT->new(); + my $source = $parser->parse_string($XML); + my $style_doc = $parser->parse_file($XSL); + my $stylesheet = $xslt->parse_stylesheet($style_doc); + my $results = $stylesheet->transform($source,@_); + $stylesheet->output_string($results); +} 1; \ No newline at end of file Modified: trunk/fb2-perl-tools/fb22htmls =================================================================== --- trunk/fb2-perl-tools/fb22htmls 2008-01-27 17:52:52 UTC (rev 55) +++ trunk/fb2-perl-tools/fb22htmls 2008-01-27 17:58:54 UTC (rev 56) @@ -1,12 +1,44 @@ #!/usr/bin/perl -use FB2ToManyHTML; +# Copyright (c) 2004 Dmitry Gribov (GribUser), +# 2008 Nikolay Shaplov +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. The name of the author may not be used to endorse or promote products +# derived from this software without specific prior written permission. +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +use fb2::Convert::Htmls; +use strict; + +my $xsl_file=$ENV{FB2_PERL_TOOLS}; +$xsl_file.="/" if $xsl_file && $xsl_file =~ /[^\/]$/; +$xsl_file.="XSL/fb22htmls.xsl"; + my $Mute=0; my $SectionSize=30000; my $MinSectionSize=20000; #============================================================= -if (!$ARGV[2]){print "\nkolbasorezka.pl by GribUser v 0.01\nUsage:\n\nkolbasorezka.pl <inputfile.fb2> <stylesheet.xsl> <outputfile> [-options] +if (!$ARGV[1]){print "\nkolbasorezka.pl by GribUser v 0.01\nUsage:\n\nkolbasorezka.pl <inputfile.fb2> <outputfile> [-options] outputfile name will be used to create new files. outputfile_page#.html files will be created @@ -20,9 +52,8 @@ #============================================================= my $FileToParce=$ARGV[0]; -my $StyleSheet=$ARGV[1]; -my $OutFileName=$ARGV[2]; -for (my $I=3;$I<@ARGV;$I++){ +my $OutFileName=$ARGV[1]; +for (my $I=2;$I<@ARGV;$I++){ $Mute=1 if $ARGV[$I] eq '-mute'; if ($ARGV[$I] eq '-partsize'){ $SectionSize=$ARGV[$I+1] if $ARGV[$I+1]; @@ -35,4 +66,4 @@ } -FB2ToManyHTML::Kolbasim($FileToParce,$StyleSheet,$OutFileName,$SectionSize,$MinSectionSize,$Mute); +fb2::Convert::Htmls::Kolbasim($FileToParce,$xsl_file,$OutFileName,$SectionSize,$MinSectionSize,$Mute); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2008-01-27 17:52:55
|
Revision: 55 http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=55&view=rev Author: shaplov Date: 2008-01-27 09:52:52 -0800 (Sun, 27 Jan 2008) Log Message: ----------- fb2_to_many_html by Gribuser, as is. Just renamed files and removed dos style line ends. Added Paths: ----------- trunk/fb2-perl-tools/XSL/ trunk/fb2-perl-tools/XSL/fb22htmls.xsl trunk/fb2-perl-tools/fb2/Convert/ trunk/fb2-perl-tools/fb2/Convert/Htmls.pm trunk/fb2-perl-tools/fb22htmls Added: trunk/fb2-perl-tools/XSL/fb22htmls.xsl =================================================================== --- trunk/fb2-perl-tools/XSL/fb22htmls.xsl (rev 0) +++ trunk/fb2-perl-tools/XSL/fb22htmls.xsl 2008-01-27 17:52:52 UTC (rev 55) @@ -0,0 +1,300 @@ +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:fb="http://www.gribuser.ru/xml/fictionbook/2.0"> + <xsl:output method="html" encoding="windows-1251"/> + <xsl:param name="PageN">1</xsl:param> + <xsl:param name="TotalPages">1</xsl:param> + <xsl:param name="BookTitle">NoName</xsl:param> + <xsl:param name="FileName">noname</xsl:param> + <xsl:template match="/*"> + <html> + <head> + <title> + <xsl:value-of select="$BookTitle"/> + </title> + <style type="text/css" media="screen"> + A { color : #0002CC } + A:HOVER { color : #BF0000 } + BODY { background-color : #FEFEFE; color : #000000; font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; text-align : justify } + H1{ font-size : 160%; font-style : normal; font-weight : bold; text-align : left; text-transform : capitalize; border : 1px solid Black; background-color : #E7E7E7; text-transform : capitalize; margin-left : 0px; padding-left : 0.5em; } + H2{ font-size : 130%; font-style : normal; font-weight : bold; text-align : left; text-transform : capitalize; background-color : #EEEEEE; border : 1px solid Gray; text-transform : capitalize; padding-left : 1em; } + H3{ font-size : 110%; font-style : normal; font-weight : bold; text-align : left; background-color : #F1F1F1; border : 1px solid Silver; text-transform : capitalize; padding-left : 1.5em;} + H4{ font-size : 100%; font-style : normal; font-weight : bold; text-align : left padding-left : 0.5em; text-transform : capitalize; border : 1px solid Gray; background-color : #F4F4F4; padding-left : 2em;} + H5{ font-size : 100%; font-style : italic; font-weight : bold; text-align : left; text-transform : capitalize;border : 1px solid Gray; background-color : #F4F4F4; padding-left : 2.5em;} + H6{ font-size : 100%; font-style : italic; font-weight : normal; text-align : left; text-transform : capitalize;border : 1px solid Gray; background-color : #F4F4F4; padding-left : 2.5em;} + SMALL{ font-size : 80% } + BLOCKQUOTE{ margin : 0 1em 0.2em 4em } + HR{ color : Black } + UL{ padding-left : 1em; margin-left: 0} + .epigraph{width:50%; margin-left : 35%;} + </style> + <style type="text/css" media="print"> + A { color : #0002CC } + A:HOVER { color : #BF0000 } + BODY { background-color : #FEFEFE; color : #000000; font-family : "Times New Roman", Times, serif; text-align : justify } + H1{ font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : 160%; font-style : normal; font-weight : bold; text-align : left; text-transform : capitalize } + H2{ font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : 130%; font-style : normal; font-weight : bold; text-align : left; text-transform : capitalize } + H3{ font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : 110%; font-style : normal; font-weight : bold; text-align : left } + H4{ font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : 100%; font-style : normal; font-weight : bold; text-align : left } + H5,H6{ font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : 100%; font-style : italic; font-weight : normal; text-align : left; text-transform : uppercase } + SMALL{ font-size : 80% } + BLOCKQUOTE{ margin : 0 1em 0.2em 4em } + HR{ color : Black } + </style> + </head> + <body> + <div><xsl:call-template name="for"/></div> + <br/> + <xsl:apply-templates/> + <br/> + <div><xsl:call-template name="for"/></div> + </body> + </html> + </xsl:template> + <xsl:template match="toc-item"> + <div> + <xsl:attribute name="style">padding-left: <xsl:value-of select="@deep"/>em;</xsl:attribute> + <a href="{$FileName}_{@n}.html"><xsl:apply-templates/></a> + </div> + </xsl:template> + <xsl:template match="description"> + <xsl:apply-templates select="title-info/coverpage/image"/> + <h1><xsl:apply-templates select="title-info/book-title"/></h1> + <h2> + <small> + <xsl:for-each select="title-info/author"> + <b> + <xsl:call-template name="author"/> + </b> + </xsl:for-each> + </small> + </h2> + <xsl:if test="title-info/sequence"> + <p> + <xsl:for-each select="title-info/sequence"> + <xsl:call-template name="sequence"/><br/> + </xsl:for-each> + </p> + </xsl:if> + <xsl:for-each select="title-info/annotation"> + <div> + <xsl:call-template name="annotation"/> + </div> + <hr/> + </xsl:for-each> + </xsl:template> + <!-- author template --> + <xsl:template name="author"> + <xsl:value-of select="first-name"/> + <xsl:text disable-output-escaping="no"> </xsl:text> + <xsl:value-of select="middle-name"/>  + <xsl:text disable-output-escaping="no"> </xsl:text> + <xsl:value-of select="last-name"/> + <br/> + </xsl:template> + <!-- secuence template --> + <xsl:template name="sequence"> + <LI/> + <xsl:value-of select="@name"/> + <xsl:if test="@number"> + <xsl:text disable-output-escaping="no">, #</xsl:text> + <xsl:value-of select="@number"/> + </xsl:if> + <xsl:if test="sequence"> + <UL> + <xsl:for-each select="sequence"> + <xsl:call-template name="sequence"/> + </xsl:for-each> + </UL> + </xsl:if> + <!-- <br/> --> + </xsl:template> + <xsl:template match="fb:subtitle"> + <xsl:if test="@id"> + <xsl:element name="a"> + <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute> + </xsl:element> + </xsl:if> + <h5> + <xsl:apply-templates/> + </h5> + </xsl:template> + + <xsl:template match="p"> + <div align="justify"><xsl:if test="@id"> + <xsl:element name="a"> + <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute> + </xsl:element> + </xsl:if>    <xsl:apply-templates/></div> + </xsl:template> + <!-- strong --> + <xsl:template match="strong"> + <b><xsl:apply-templates/></b> + </xsl:template> + <!-- emphasis --> + <xsl:template match="emphasis"> + <i> <xsl:apply-templates/></i> + </xsl:template> + <!-- style --> + <xsl:template match="style"> + <span class="{@name}"><xsl:apply-templates/></span> + </xsl:template> + <!-- empty-line --> + <xsl:template match="empty-line"> + <br/> + </xsl:template> + <!-- link --> + <xsl:template match="a"> + <xsl:choose> + <xsl:when test="(@type) = 'note'"> + <xsl:element name="a"> + <xsl:attribute name="href"><xsl:value-of select="$FileName"/>_<xsl:value-of select="$TotalPages"/>.html<xsl:value-of select="@xlink:href"/></xsl:attribute> + <sup> + <xsl:apply-templates/> + </sup> + </xsl:element> + </xsl:when> + <xsl:otherwise> + <xsl:apply-templates/> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + <!-- annotation --> + <xsl:template name="annotation"> + <xsl:if test="@id"> + <xsl:element name="a"> + <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute> + </xsl:element> + </xsl:if> + <h3>Annotation</h3> + <xsl:apply-templates/> + </xsl:template> + <!-- epigraph --> + <xsl:template match="epigraph"> + <blockquote class="epigraph"> + <xsl:if test="@id"> + <xsl:element name="a"> + <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute> + </xsl:element> + </xsl:if> + <xsl:apply-templates/> + </blockquote> + </xsl:template> + <!-- epigraph/text-author --> + <xsl:template match="epigraph/text-author"> + <blockquote> + <i><xsl:apply-templates/></i> + </blockquote> + </xsl:template> + <!-- cite --> + <xsl:template match="cite"> + ...<blockquote><i> + <xsl:if test="@id"> + <xsl:element name="a"> + <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute> + </xsl:element> + </xsl:if> + <xsl:apply-templates/> + </i></blockquote> + </xsl:template> + <!-- cite/text-author --> + <xsl:template name="text-author"> + <br/> + <i> <xsl:apply-templates/></i> + </xsl:template> + <!-- date --> + <xsl:template match="date"> + <xsl:choose> + <xsl:when test="not(@value)"> +    <xsl:apply-templates/> + <br/> + </xsl:when> + <xsl:otherwise> +    <xsl:value-of select="@value"/> + <br/> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + <!-- poem --> + <xsl:template match="poem"> + <blockquote> + <xsl:if test="@id"> + <xsl:element name="a"> + <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute> + </xsl:element> + </xsl:if> + <xsl:apply-templates/> + </blockquote> + </xsl:template> + <!-- poem/title --> +<!-- <xsl:template match="poem/title"> + <h6><xsl:apply-templates/></h6> + </blockquote> + </xsl:template> --> + <!-- stanza --> + <xsl:template match="stanza"> + <br/> + <xsl:apply-templates/> + <br/> + </xsl:template> + <!-- v --> + <xsl:template match="v"> + <xsl:if test="@id"> + <xsl:element name="a"> + <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute> + </xsl:element> + </xsl:if> + <xsl:apply-templates/><br/> + </xsl:template> + <!-- image --> + <xsl:template match="image"> + <div align="center"> + <img border="1"> + <xsl:choose> + <xsl:when test="starts-with(@xlink:href,'#')"> + <xsl:attribute name="src"><xsl:value-of select="substring-after(@xlink:href,'#')"/></xsl:attribute> + </xsl:when> + <xsl:otherwise> + <xsl:attribute name="src"><xsl:value-of select="@xlink:href"/></xsl:attribute> + </xsl:otherwise> + </xsl:choose> + </img> + </div> + </xsl:template> + <xsl:template match="title"> + <xsl:choose> + <xsl:when test="@deepness > 5"><h6><a name="@number"></a><xsl:apply-templates/></h6></xsl:when> + <xsl:otherwise><xsl:element name="h{@deepness+1}"><a name="@number"></a><xsl:apply-templates/></xsl:element></xsl:otherwise> + </xsl:choose> + + </xsl:template> + <xsl:template name="for"> + <xsl:param name="i" select="0"/> + <xsl:param name="n" select="$TotalPages"/> + <xsl:if test="$i <= $n"> + <xsl:choose> + <xsl:when test="$i = $PageN"> + <strong> + <xsl:choose> + <xsl:when test="$i != 0"><xsl:value-of select="$i"/></xsl:when> + <xsl:otherwise>Содержание</xsl:otherwise> + </xsl:choose> + </strong> + </xsl:when> + <xsl:otherwise> + <xsl:element name="a"> + <xsl:attribute name="href"><xsl:value-of select="$FileName"/>_<xsl:value-of select="$i"/>.html</xsl:attribute> + <xsl:attribute name="title">Перейти на страницу <xsl:value-of select="$i"/></xsl:attribute> + <xsl:choose> + <xsl:when test="$i != 0"><xsl:value-of select="$i"/></xsl:when> + <xsl:otherwise>Содержание</xsl:otherwise> + </xsl:choose> + </xsl:element> + </xsl:otherwise> + </xsl:choose> + <xsl:if test="$i < $n">  |  </xsl:if> + <xsl:call-template name="for"> + <xsl:with-param name="i" select="$i + 1"/> + <xsl:with-param name="n" select="$n"/> + </xsl:call-template> + </xsl:if> + </xsl:template> +</xsl:stylesheet> \ No newline at end of file Added: trunk/fb2-perl-tools/fb2/Convert/Htmls.pm =================================================================== --- trunk/fb2-perl-tools/fb2/Convert/Htmls.pm (rev 0) +++ trunk/fb2-perl-tools/fb2/Convert/Htmls.pm 2008-01-27 17:52:52 UTC (rev 55) @@ -0,0 +1,186 @@ +#!/usr/bin/perl +package FB2ToManyHTML; + +use XML::Parser; +use XML::LibXSLT; +use XML::LibXML; +use strict; +no warnings; + +my $Mute; +my $SectionSize; +my $MinSectionSize; + +my @BodyParts; +my $RootAttrs; +my $BookTitle; + +sub Kolbasim{ + my $FileToParce=shift; + my $StyleSheet=shift; + my $OutFileName=shift; + $SectionSize=shift; + $MinSectionSize=shift; + $Mute=shift; + ($RootAttrs,$BookTitle,@BodyParts)=&SplitBook($FileToParce); + return TransformParts($StyleSheet,$OutFileName,$RootAttrs,$BookTitle,@BodyParts); +} + +sub SplitBook{ + my $FileToParce=shift; + my $I; + my $CurDeepness=0; + my ($CurPart,$InBinary,$InHead); + my $Description; + my @BodyAsArray; + my $PartSize=0; + my $PartStarted=1; + my $InSectionTitle=0; + my $AllowSectionTitle=0; + my $CanCutHere=1; + my $SectionTitle; + my @ContentParts; + my $InNotesBody; + my $RootAttrs; + my $BookTitle; + my $InBookTitle; + my $SplitParser=new XML::Parser(Handlers => { + Start => sub { + my $expat=shift; + my $elem=shift; + my %Params=@_; + $I++; + print "Working element #$I\r" unless $Mute; + + $InHead = 1 if $elem eq 'description'; + $InBinary=($elem eq 'description')?1:0; + $CurPart='' if $elem=~/\Adescription\Z/; + if ($elem eq 'FictionBook'){ + for (keys(%Params)){ + $RootAttrs.=" $_=\"".xmlescape($Params{$_})."\"" unless $_ eq 'xmlns'; + } + } + $InBookTitle=$elem eq 'book-title'?1:0 ; + unless ($elem eq 'section'){ + if ($elem eq 'title'){ + $Params{'deepness'}=$InNotesBody?5:$CurDeepness; + $Params{'number'}=scalar @BodyAsArray; + } + $CurPart.="<$elem"; + for (keys(%Params)){ + $CurPart.=" $_=\"".xmlescape($Params{$_})."\""; + } + $CurPart.=">"; + }else{ + $CurDeepness++; + } + $AllowSectionTitle=0 if $elem eq 'poem'; + $InSectionTitle=1 if ($AllowSectionTitle && $elem eq 'title'); + if ($elem=~/\A(title|epigraph|annotation|poem|cite)\Z/){ + $CanCutHere=0; + } + if ($elem=~/\A(section|body)\Z/){ +# $CurPart='' unless $InNotesBody; + $CurPart='' if $elem eq 'body'; + $PartSize=0 if $elem eq 'body'; + $PartStarted=1; + $AllowSectionTitle=1; + $SectionTitle=''; + $InNotesBody=1 if ($elem eq 'body' && $Params{'name'}=~/\Anotes\Z/i); + } + }, + Char => sub { + $PartSize+=length($_[1]); + $CurPart.=xmlescape($_[1]) unless $InBinary; + $SectionTitle.=xmlescape($_[1]) if $InSectionTitle; + $BookTitle.=xmlescape($_[1]) if $InBookTitle; + }, + End => sub { + my $elem=$_[1]; + $CurPart.="</".$_[1].">" unless $elem=~ /(section|body)/; + if (((!$InHead && $CanCutHere && $elem eq 'p' && $PartSize>=$SectionSize) || + ($elem eq 'section' && $PartSize>=$MinSectionSize) || $elem eq 'description') && !$InNotesBody || $elem eq 'body') { + my %t=( + 'parstart'=>$PartStarted, + 'partcontent'=>$CurPart, + 'level'=>$CurDeepness + ); + push(@BodyAsArray,\%t) unless $CurPart=~/\A\s+\Z/; + $CurPart=''; + $PartSize=0; + $PartStarted=0; + $InHead=0 if $_[1] eq 'description'; + } + $CurDeepness-- if $_[1] eq 'section'; + if ($elem=~/\A(title|epigraph|annotation|poem|cite)\Z/){ + $CanCutHere=1; + } + $AllowSectionTitle=0 if $elem eq 'section'; + + if ($elem eq 'p' && $InSectionTitle && $SectionTitle){ + my %t=('title'=>$SectionTitle,'N'=>(scalar @BodyAsArray), 'deep'=>$CurDeepness); + push (@ContentParts,\%t); + $InSectionTitle=0; + $SectionTitle=''; + $AllowSectionTitle=0; + } + } + }); + + $SplitParser->parsefile($FileToParce) or die $!; + $SplitParser=undef; + for (@ContentParts){ + $BodyAsArray[0]->{'partcontent'}.="<toc-item n=\"".$_->{'N'}."\" deep=\"".$_->{'deep'}."\">".$_->{'title'}."</toc-item>\n"; + } + return ($RootAttrs,$BookTitle,@BodyAsArray); +} + +sub TransformParts{ + my $StyleSheet=shift; + my $OutFileName=shift; + my $RootAttrs=shift; + my $BookTitle=shift; + my @Parts=@_; + my $OutFileSHort=$OutFileName; + $OutFileSHort=~s/\A(.*[\/\\])?([^\/\\]*)\Z/$2/; + for (my $I=0;$I<@Parts;$I++){ + my $ItemLength=$Parts[$I]->{'title'}; + print "Generating file ${OutFileName}_$I.html...\n" unless $Mute; + my $Result=TransformXML("<part$RootAttrs>".$Parts[$I]->{'partcontent'}."</part>", + $StyleSheet,'PageN'=>"'$I'", + 'TotalPages'=>'"'.(@Parts-1).'"', + 'FileName'=>"'$OutFileSHort'", + 'BookTitle'=>"'$BookTitle'"); + open OUTFILE,">${OutFileName}_$I.html"; + print OUTFILE $Result; + close OUTFILE; + } + return scalar(@Parts); +} + +sub xmlescape { + my %escapes=( + '&' => '&', + '<' => '<', + '>' => '>', + '"' => '"', + "'" => ''' + ); + $b=shift; + $_=$b; + s/([&<>'"])/$escapes{$1}/gs; + $_; +} + +sub TransformXML{ + my $XML=shift; + my $XSL=shift; + my $parser = XML::LibXML->new(); + my $xslt = XML::LibXSLT->new(); + my $source = $parser->parse_string($XML); + my $style_doc = $parser->parse_file($XSL); + my $stylesheet = $xslt->parse_stylesheet($style_doc); + my $results = $stylesheet->transform($source,@_); + $stylesheet->output_string($results); +} +1; \ No newline at end of file Added: trunk/fb2-perl-tools/fb22htmls =================================================================== --- trunk/fb2-perl-tools/fb22htmls (rev 0) +++ trunk/fb2-perl-tools/fb22htmls 2008-01-27 17:52:52 UTC (rev 55) @@ -0,0 +1,38 @@ +#!/usr/bin/perl + +use FB2ToManyHTML; + +my $Mute=0; +my $SectionSize=30000; +my $MinSectionSize=20000; +#============================================================= +if (!$ARGV[2]){print "\nkolbasorezka.pl by GribUser v 0.01\nUsage:\n\nkolbasorezka.pl <inputfile.fb2> <stylesheet.xsl> <outputfile> [-options] + + outputfile name will be used to create new files. + outputfile_page#.html files will be created + + Options available + -mute Do not print progress messages. + -partsize <number> Set part size (default is $SectionSize) + -minsize <number> Set minimum part size (default is $MinSectionSize) + +";exit 0;} +#============================================================= + +my $FileToParce=$ARGV[0]; +my $StyleSheet=$ARGV[1]; +my $OutFileName=$ARGV[2]; +for (my $I=3;$I<@ARGV;$I++){ + $Mute=1 if $ARGV[$I] eq '-mute'; + if ($ARGV[$I] eq '-partsize'){ + $SectionSize=$ARGV[$I+1] if $ARGV[$I+1]; + $I++; + } + if ($ARGV[$I] eq '-minsize'){ + $MinSectionSize=$ARGV[$I+1] if $ARGV[$I+1]; + $I++; + } + +} + +FB2ToManyHTML::Kolbasim($FileToParce,$StyleSheet,$OutFileName,$SectionSize,$MinSectionSize,$Mute); Property changes on: trunk/fb2-perl-tools/fb22htmls ___________________________________________________________________ Name: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2008-01-26 22:41:33
|
Revision: 54 http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=54&view=rev Author: shaplov Date: 2008-01-26 14:41:33 -0800 (Sat, 26 Jan 2008) Log Message: ----------- Small script to check if file is a valid fb2-book Added Paths: ----------- trunk/fb2-perl-tools/XSD/ trunk/fb2-perl-tools/XSD/FB2.0/ trunk/fb2-perl-tools/XSD/FB2.0/FictionBook2.xsd trunk/fb2-perl-tools/XSD/FB2.0/FictionBookGenres.xsd trunk/fb2-perl-tools/XSD/FB2.0/FictionBookLang.xsd trunk/fb2-perl-tools/XSD/FB2.0/FictionBookLinks.xsd trunk/fb2-perl-tools/XSD/FB2.1/ trunk/fb2-perl-tools/XSD/FB2.1/FictionBook.xsd trunk/fb2-perl-tools/XSD/FB2.1/FictionBook2.1.xsd trunk/fb2-perl-tools/XSD/FB2.1/FictionBookGenres.xsd trunk/fb2-perl-tools/XSD/FB2.1/FictionBookLang.xsd trunk/fb2-perl-tools/XSD/FB2.1/FictionBookLinks.xsd trunk/fb2-perl-tools/fb2validate Added: trunk/fb2-perl-tools/XSD/FB2.0/FictionBook2.xsd =================================================================== --- trunk/fb2-perl-tools/XSD/FB2.0/FictionBook2.xsd (rev 0) +++ trunk/fb2-perl-tools/XSD/FB2.0/FictionBook2.xsd 2008-01-26 22:41:33 UTC (rev 54) @@ -0,0 +1,1061 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- edited with XML Spy v4.4 U (http://www.xmlspy.com) by Dmitry Gribov (DDS) --> + +<xs:schema targetNamespace="http://www.gribuser.ru/xml/fictionbook/2.0" xmlns="http://www.gribuser.ru/xml/fictionbook/2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:genre="http://www.gribuser.ru/xml/fictionbook/2.0/genres" elementFormDefault="qualified" attributeFormDefault="unqualified"> + + <xs:import namespace="http://www.w3.org/1999/xlink" schemaLocation="FictionBookLinks.xsd"/> + + <xs:import namespace="http://www.gribuser.ru/xml/fictionbook/2.0/genres" schemaLocation="FictionBookGenres.xsd"/> + + <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="FictionBookLang.xsd"/> + + <xs:element name="FictionBook"> + + <xs:annotation> + + <xs:documentation>Root element</xs:documentation> + + </xs:annotation> + + <xs:complexType> + + <xs:sequence> + + <xs:element name="stylesheet" minOccurs="0" maxOccurs="unbounded"> + + <xs:annotation> + + <xs:documentation>This element contains an arbitrary stylesheet that is intepreted by a some processing programs, e.g. text/css stylesheets can be used by XSLT stylesheets to generate better looking html</xs:documentation> + + </xs:annotation> + + <xs:complexType> + + <xs:simpleContent> + + <xs:extension base="xs:string"> + + <xs:attribute name="type" type="xs:string" use="required"/> + + </xs:extension> + + </xs:simpleContent> + + </xs:complexType> + + </xs:element> + + <xs:element name="description"> + + <xs:complexType> + + <xs:sequence> + + <xs:element name="title-info"> + + <xs:annotation> + + <xs:documentation>Generic information about the book</xs:documentation> + + </xs:annotation> + + <xs:complexType> + + <xs:sequence> + + <xs:element name="genre" maxOccurs="unbounded"> + + <xs:annotation> + + <xs:documentation>Genre of this book, with the optional match percentage</xs:documentation> + + </xs:annotation> + + <xs:complexType> + + <xs:simpleContent> + + <xs:extension base="genre:genreType"> + + <xs:attribute name="match" type="xs:integer" use="optional" default="100"/> + + </xs:extension> + + </xs:simpleContent> + + </xs:complexType> + + </xs:element> + + <xs:element name="author" maxOccurs="unbounded"> + + <xs:annotation> + + <xs:documentation>Author(s) of this book</xs:documentation> + + </xs:annotation> + + <xs:complexType> + + <xs:complexContent> + + <xs:extension base="authorType"/> + + </xs:complexContent> + + </xs:complexType> + + </xs:element> + + <xs:element name="book-title" type="textFieldType"> + + <xs:annotation> + + <xs:documentation>Book title</xs:documentation> + + </xs:annotation> + + </xs:element> + + <xs:element name="annotation" type="annotationType" minOccurs="0"> + + <xs:annotation> + + <xs:documentation>Annotation for this book</xs:documentation> + + </xs:annotation> + + </xs:element> + + <xs:element name="keywords" type="textFieldType" minOccurs="0"> + + <xs:annotation> + + <xs:documentation>Any keywords for this book, intended for use in search engines</xs:documentation> + + </xs:annotation> + + </xs:element> + + <xs:element name="date" type="dateType" minOccurs="0"> + + <xs:annotation> + + <xs:documentation>Date this book was written, can be not exact, e.g. 1863-1867. If an optional attribute is present, then it should contain some computer-readable date from the interval for use by search and indexingengines</xs:documentation> + + </xs:annotation> + + </xs:element> + + <xs:element name="coverpage" minOccurs="0"> + + <xs:annotation> + + <xs:documentation>Any coverpage items, currently only images</xs:documentation> + + </xs:annotation> + + <xs:complexType> + + <xs:sequence> + + <xs:element name="image" type="imageType" maxOccurs="unbounded"/> + + </xs:sequence> + + </xs:complexType> + + </xs:element> + + <xs:element name="lang" type="xs:language"/> + + <xs:element name="src-lang" type="xs:language" minOccurs="0"> + + <xs:annotation> + + <xs:documentation>Book's source language if this is a translation</xs:documentation> + + </xs:annotation> + + </xs:element> + + <xs:element name="translator" type="authorType" minOccurs="0" maxOccurs="unbounded"> + + <xs:annotation> + + <xs:documentation>Translators if this is a translation</xs:documentation> + + </xs:annotation> + + </xs:element> + + <xs:element name="sequence" type="sequenceType" minOccurs="0" maxOccurs="unbounded"> + + <xs:annotation> + + <xs:documentation>Any sequences this book might be part of</xs:documentation> + + </xs:annotation> + + </xs:element> + + </xs:sequence> + + </xs:complexType> + + </xs:element> + + <xs:element name="document-info"> + + <xs:annotation> + + <xs:documentation>Information about this particular (xml) document</xs:documentation> + + </xs:annotation> + + <xs:complexType> + + <xs:sequence> + + <xs:element name="author" type="authorType" maxOccurs="unbounded"> + + <xs:annotation> + + <xs:documentation>Author(s) of this particular document</xs:documentation> + + </xs:annotation> + + </xs:element> + + <xs:element name="program-used" type="textFieldType" minOccurs="0"> + + <xs:annotation> + + <xs:documentation>Any software used in preparation of this document, in free format</xs:documentation> + + </xs:annotation> + + </xs:element> + + <xs:element name="date" type="dateType"> + + <xs:annotation> + + <xs:documentation>Date this document was created, same guidelines as in the <title-info> section apply</xs:documentation> + + </xs:annotation> + + </xs:element> + + <xs:element name="src-url" type="xs:string" minOccurs="0" maxOccurs="unbounded"> + + <xs:annotation> + + <xs:documentation>Source URL if this document is a conversion of some other (online) document</xs:documentation> + + </xs:annotation> + + </xs:element> + + <xs:element name="src-ocr" type="textFieldType" minOccurs="0"> + + <xs:annotation> + + <xs:documentation>Author of the original (online) document, if this is a conversion</xs:documentation> + + </xs:annotation> + + </xs:element> + + <xs:element name="id" type="xs:token"> + + <xs:annotation> + + <xs:documentation>this is a unique identifier for a document. this must not change unless you make substantial updates to the document</xs:documentation> + + </xs:annotation> + + </xs:element> + + <xs:element name="version" type="xs:float"> + + <xs:annotation> + + <xs:documentation>Document version, in free format, should be incremented if the document is changed and re-released to the public</xs:documentation> + + </xs:annotation> + + </xs:element> + + <xs:element name="history" type="annotationType" minOccurs="0"/> + + </xs:sequence> + + </xs:complexType> + + </xs:element> + + <xs:element name="publish-info" minOccurs="0"> + + <xs:annotation> + + <xs:documentation>Information about some paper/outher published document, that was used as a source of this xml document</xs:documentation> + + </xs:annotation> + + <xs:complexType> + + <xs:sequence> + + <xs:element name="book-name" type="textFieldType" minOccurs="0"> + + <xs:annotation> + + <xs:documentation>Original (paper) book name</xs:documentation> + + </xs:annotation> + + </xs:element> + + <xs:element name="publisher" type="textFieldType" minOccurs="0"> + + <xs:annotation> + + <xs:documentation>Original (paper) book publisher</xs:documentation> + + </xs:annotation> + + </xs:element> + + <xs:element name="city" type="textFieldType" minOccurs="0"> + + <xs:annotation> + + <xs:documentation>City where the original (paper) book was published</xs:documentation> + + </xs:annotation> + + </xs:element> + + <xs:element name="year" type="xs:gYear" minOccurs="0"> + + <xs:annotation> + + <xs:documentation>Year of the original (paper) publication</xs:documentation> + + </xs:annotation> + + </xs:element> + + <xs:element name="isbn" type="textFieldType" minOccurs="0"/> + + <xs:element name="sequence" type="sequenceType" minOccurs="0" maxOccurs="unbounded"/> + + </xs:sequence> + + </xs:complexType> + + </xs:element> + + <xs:element name="custom-info" minOccurs="0" maxOccurs="unbounded"> + + <xs:annotation> + + <xs:documentation>Any other information about the book/document that didnt fit in the above groups</xs:documentation> + + </xs:annotation> + + <xs:complexType> + + <xs:simpleContent> + + <xs:extension base="textFieldType"> + + <xs:attribute name="info-type" type="xs:string" use="required"/> + + </xs:extension> + + </xs:simpleContent> + + </xs:complexType> + + </xs:element> + + </xs:sequence> + + </xs:complexType> + + </xs:element> + + <xs:element name="body" maxOccurs="unbounded"> + + <xs:annotation> + + <xs:documentation>Main content of the book, multiple bodies are used for additional information, like footnotes, that do not appear in the main book flow. The first body is presented to the reader by default, and content in the other bodies should be accessible by hyperlinks. Name attribute should describe the meaning of this body, this is optional for the main body.</xs:documentation> + + </xs:annotation> + + <xs:complexType> + + <xs:sequence> + + <xs:element name="image" type="imageType" minOccurs="0"> + + <xs:annotation> + + <xs:documentation>Image to be displayed at the top of this section</xs:documentation> + + </xs:annotation> + + </xs:element> + + <xs:element name="title" type="titleType" minOccurs="0"> + + <xs:annotation> + + <xs:documentation>A fancy title for the entire book, should be used if the simple text version in <description> is not adequate, e.g. the book title has multiple paragraphs and/or character styles</xs:documentation> + + </xs:annotation> + + </xs:element> + + <xs:element name="epigraph" type="epigraphType" minOccurs="0" maxOccurs="unbounded"> + + <xs:annotation> + + <xs:documentation>Epigraph(s) for the entire book, if any</xs:documentation> + + </xs:annotation> + + </xs:element> + + <xs:element name="section" type="sectionType" maxOccurs="unbounded"/> + + </xs:sequence> + + <xs:attribute name="name" type="xs:string" use="optional"/> + + <xs:attribute ref="xml:lang"/> + + </xs:complexType> + + </xs:element> + + <xs:element name="binary" minOccurs="0" maxOccurs="unbounded"> + + <xs:annotation> + + <xs:documentation>Any binary data that is required for the presentation of this book in base64 format. Currently only images are used.</xs:documentation> + + </xs:annotation> + + <xs:complexType> + + <xs:simpleContent> + + <xs:extension base="xs:base64Binary"> + + <xs:attribute name="content-type" type="xs:string" use="required"/> + + <xs:attribute name="id" type="xs:ID" use="required"/> + + </xs:extension> + + </xs:simpleContent> + + </xs:complexType> + + </xs:element> + + </xs:sequence> + + </xs:complexType> + + </xs:element> + + <xs:complexType name="authorType"> + + <xs:annotation> + + <xs:documentation>Information about a single author</xs:documentation> + + </xs:annotation> + + <xs:choice> + + <xs:sequence> + + <xs:element name="first-name" type="textFieldType"/> + + <xs:element name="middle-name" type="textFieldType" minOccurs="0"/> + + <xs:element name="last-name" type="textFieldType"/> + + <xs:element name="nickname" type="textFieldType" minOccurs="0"/> + + <xs:element name="home-page" type="xs:string" minOccurs="0" maxOccurs="unbounded"/> + + <xs:element name="email" type="xs:string" minOccurs="0" maxOccurs="unbounded"/> + + </xs:sequence> + + <xs:sequence> + + <xs:element name="nickname" type="textFieldType"/> + + <xs:element name="home-page" type="xs:string" minOccurs="0"/> + + <xs:element name="email" type="xs:string" minOccurs="0"/> + + </xs:sequence> + + </xs:choice> + + </xs:complexType> + + <xs:complexType name="textFieldType"> + + <xs:simpleContent> + + <xs:extension base="xs:string"> + + <xs:attribute ref="xml:lang"/> + + </xs:extension> + + </xs:simpleContent> + + </xs:complexType> + + <xs:complexType name="dateType"> + + <xs:annotation> + + <xs:documentation>A human readable date, maybe not exact, with an optional computer readable variant</xs:documentation> + + </xs:annotation> + + <xs:simpleContent> + + <xs:extension base="xs:string"> + + <xs:attribute name="value" type="xs:date" use="optional"/> + + <xs:attribute ref="xml:lang"/> + + </xs:extension> + + </xs:simpleContent> + + </xs:complexType> + + <xs:complexType name="titleType"> + + <xs:annotation> + + <xs:documentation>A title, used in sections, poems and body elements</xs:documentation> + + </xs:annotation> + + <xs:choice minOccurs="0" maxOccurs="unbounded"> + + <xs:element name="p" type="pType"/> + + <xs:element name="empty-line"/> + + </xs:choice> + + <xs:attribute ref="xml:lang"/> + + </xs:complexType> + + <xs:complexType name="imageType"> + + <xs:annotation> + + <xs:documentation>An empty element with an image name as an attribute</xs:documentation> + + </xs:annotation> + + <xs:attribute ref="xlink:type"/> + + <xs:attribute ref="xlink:href"/> + + <xs:attribute name="alt" type="xs:string" use="optional"/> + + </xs:complexType> + + <xs:complexType name="pType" mixed="true"> + + <xs:annotation> + + <xs:documentation>A basic paragraph, may include simple formatting inside</xs:documentation> + + </xs:annotation> + + <xs:complexContent mixed="true"> + + <xs:extension base="styleType"> + + <xs:attribute name="id" type="xs:ID" use="optional"/> + + <xs:attribute name="style" type="xs:string" use="optional"/> + + </xs:extension> + + </xs:complexContent> + + </xs:complexType> + + <xs:complexType name="citeType"> + + <xs:annotation> + + <xs:documentation>A citation with an optional citation author at the end</xs:documentation> + + </xs:annotation> + + <xs:sequence> + + <xs:choice minOccurs="0" maxOccurs="unbounded"> + + <xs:element name="p" type="pType"/> + + <xs:element name="poem" type="poemType"/> + + <xs:element name="empty-line"/> + + </xs:choice> + + <xs:element name="text-author" type="textFieldType" minOccurs="0" maxOccurs="unbounded"/> + + </xs:sequence> + + <xs:attribute name="id" type="xs:ID" use="optional"/> + + <xs:attribute ref="xml:lang"/> + + </xs:complexType> + + <xs:complexType name="poemType"> + + <xs:annotation> + + <xs:documentation>A poem</xs:documentation> + + </xs:annotation> + + <xs:sequence> + + <xs:element name="title" type="titleType" minOccurs="0"> + + <xs:annotation> + + <xs:documentation>Poem title</xs:documentation> + + </xs:annotation> + + </xs:element> + + <xs:element name="epigraph" type="epigraphType" minOccurs="0" maxOccurs="unbounded"> + + <xs:annotation> + + <xs:documentation>Poem epigraph(s), if any</xs:documentation> + + </xs:annotation> + + </xs:element> + + <xs:element name="stanza" maxOccurs="unbounded"> + + <xs:annotation> + + <xs:documentation>Each poem should have at least one stanza. Stanzas are usually separated with empty lines by user agents.</xs:documentation> + + </xs:annotation> + + <xs:complexType> + + <xs:sequence> + + <xs:element name="title" type="titleType" minOccurs="0"/> + + <xs:element name="subtitle" type="pType" minOccurs="0"/> + + <xs:element name="v" type="pType" maxOccurs="unbounded"> + + <xs:annotation> + + <xs:documentation>An individual line in a stanza</xs:documentation> + + </xs:annotation> + + </xs:element> + + </xs:sequence> + + <xs:attribute ref="xml:lang"/> + + </xs:complexType> + + </xs:element> + + <xs:element name="text-author" type="textFieldType" minOccurs="0" maxOccurs="unbounded"/> + + <xs:element name="date" type="dateType" minOccurs="0"> + + <xs:annotation> + + <xs:documentation>Date this poem was written.</xs:documentation> + + </xs:annotation> + + </xs:element> + + </xs:sequence> + + <xs:attribute name="id" type="xs:ID" use="optional"/> + + <xs:attribute ref="xml:lang"/> + + </xs:complexType> + + <xs:complexType name="epigraphType"> + + <xs:annotation> + + <xs:documentation>An epigraph</xs:documentation> + + </xs:annotation> + + <xs:sequence> + + <xs:choice minOccurs="0" maxOccurs="unbounded"> + + <xs:element name="p" type="pType"/> + + <xs:element name="poem" type="poemType"/> + + <xs:element name="cite" type="citeType"/> + + <xs:element name="empty-line"/> + + </xs:choice> + + <xs:element name="text-author" type="textFieldType" minOccurs="0" maxOccurs="unbounded"/> + + </xs:sequence> + + <xs:attribute name="id" type="xs:ID" use="optional"/> + + </xs:complexType> + + <xs:complexType name="annotationType"> + + <xs:annotation> + + <xs:documentation>A cut-down version of <section> used in annotations</xs:documentation> + + </xs:annotation> + + <xs:choice minOccurs="0" maxOccurs="unbounded"> + + <xs:element name="p" type="pType"/> + + <xs:element name="poem" type="poemType"/> + + <xs:element name="cite" type="citeType"/> + + <xs:element name="empty-line"/> + + </xs:choice> + + <xs:attribute name="id" type="xs:ID" use="optional"/> + + <xs:attribute ref="xml:lang"/> + + </xs:complexType> + + <xs:complexType name="sectionType"> + + <xs:annotation> + + <xs:documentation>A basic block of a book, can contain more child sections or textual content</xs:documentation> + + </xs:annotation> + + <xs:sequence minOccurs="0"> + + <xs:element name="title" type="titleType" minOccurs="0"> + + <xs:annotation> + + <xs:documentation>Section's title</xs:documentation> + + </xs:annotation> + + </xs:element> + + <xs:element name="epigraph" type="epigraphType" minOccurs="0" maxOccurs="unbounded"> + + <xs:annotation> + + <xs:documentation>Epigraph(s) for this section</xs:documentation> + + </xs:annotation> + + </xs:element> + + <xs:element name="image" type="imageType" minOccurs="0"> + + <xs:annotation> + + <xs:documentation>Image to be displayed at the top of this section</xs:documentation> + + </xs:annotation> + + </xs:element> + + <xs:element name="annotation" type="annotationType" minOccurs="0"> + + <xs:annotation> + + <xs:documentation>Annotation for this section, if any</xs:documentation> + + </xs:annotation> + + </xs:element> + + <xs:choice> + + <xs:sequence> + + <xs:element name="section" type="sectionType" maxOccurs="unbounded"> + + <xs:annotation> + + <xs:documentation>Child sections</xs:documentation> + + </xs:annotation> + + </xs:element> + + </xs:sequence> + + <xs:sequence> + + <xs:choice> + + <xs:element name="p" type="pType"/> + + <xs:element name="poem" type="poemType"/> + + <xs:element name="subtitle" type="pType"/> + + <xs:element name="cite" type="citeType"/> + + <xs:element name="empty-line"/> + + <xs:element name="table" type="tableType"/> + + </xs:choice> + + <xs:choice minOccurs="0" maxOccurs="unbounded"> + + <xs:element name="p" type="pType"/> + + <xs:element name="image" type="imageType"/> + + <xs:element name="poem" type="poemType"/> + + <xs:element name="subtitle" type="pType"/> + + <xs:element name="cite" type="citeType"/> + + <xs:element name="empty-line"/> + + <xs:element name="table" type="tableType"/> + + </xs:choice> + + </xs:sequence> + + </xs:choice> + + </xs:sequence> + + <xs:attribute name="id" type="xs:ID" use="optional"/> + + <xs:attribute ref="xml:lang"/> + + </xs:complexType> + + <xs:complexType name="styleType" mixed="true"> + + <xs:annotation> + + <xs:documentation>Markup</xs:documentation> + + </xs:annotation> + + <xs:choice minOccurs="0" maxOccurs="unbounded"> + + <xs:element name="strong" type="styleType"/> + + <xs:element name="emphasis" type="styleType"/> + + <xs:element name="style" type="namedStyleType"/> + + <xs:element name="a" type="linkType"/> + + <xs:element name="image" type="imageType"/> + + </xs:choice> + + <xs:attribute ref="xml:lang"/> + + </xs:complexType> + + <xs:complexType name="namedStyleType" mixed="true"> + + <xs:annotation> + + <xs:documentation>Markup</xs:documentation> + + </xs:annotation> + + <xs:choice minOccurs="0" maxOccurs="unbounded"> + + <xs:element name="strong" type="styleType"/> + + <xs:element name="emphasis" type="styleType"/> + + <xs:element name="style" type="namedStyleType"/> + + <xs:element name="a" type="linkType"/> + + <xs:element name="image" type="imageType"/> + + </xs:choice> + + <xs:attribute ref="xml:lang"/> + + <xs:attribute name="name" type="xs:token" use="required"/> + + </xs:complexType> + + <xs:complexType name="linkType" mixed="true"> + + <xs:annotation> + + <xs:documentation>Generic hyperlinks. Cannot be nested. Footnotes should be implemented by links referring to additional bodies in the same document</xs:documentation> + + </xs:annotation> + + <xs:choice minOccurs="0" maxOccurs="unbounded"> + + <xs:element name="strong" type="styleLinkType"/> + + <xs:element name="emphasis" type="styleLinkType"/> + + <xs:element name="style" type="styleLinkType"/> + + </xs:choice> + + <xs:attribute ref="xlink:type" use="optional"/> + + <xs:attribute ref="xlink:href" use="required"/> + + <xs:attribute name="type" type="xs:token" use="optional"/> + + </xs:complexType> + + <xs:complexType name="styleLinkType" mixed="true"> + + <xs:annotation> + + <xs:documentation>Markup</xs:documentation> + + </xs:annotation> + + <xs:choice minOccurs="0" maxOccurs="unbounded"> + + <xs:element name="strong" type="styleLinkType"/> + + <xs:element name="emphasis" type="styleLinkType"/> + + <xs:element name="style" type="styleLinkType"/> + + </xs:choice> + + </xs:complexType> + + <xs:complexType name="sequenceType"> + + <xs:annotation> + + <xs:documentation>Book sequences</xs:documentation> + + </xs:annotation> + + <xs:sequence> + + <xs:element name="sequence" type="sequenceType" minOccurs="0" maxOccurs="unbounded"/> + + </xs:sequence> + + <xs:attribute name="name" type="xs:string" use="required"/> + + <xs:attribute name="number" type="xs:integer" use="optional"/> + + <xs:attribute ref="xml:lang"/> + + </xs:complexType> + + <xs:complexType name="tableType"> + + <xs:annotation> + + <xs:documentation>Basic html-like tables</xs:documentation> + + </xs:annotation> + + <xs:sequence> + + <xs:element name="tr" maxOccurs="unbounded"> + + <xs:complexType> + + <xs:sequence> + + <xs:element name="td" type="pType" maxOccurs="unbounded"/> + + </xs:sequence> + + <xs:attribute name="align" type="alignType" use="optional" default="left"/> + + </xs:complexType> + + </xs:element> + + </xs:sequence> + + </xs:complexType> + + <xs:simpleType name="alignType"> + + <xs:restriction base="xs:token"> + + <xs:enumeration value="left"/> + + <xs:enumeration value="right"/> + + <xs:enumeration value="center"/> + + </xs:restriction> + + </xs:simpleType> + +</xs:schema> \ No newline at end of file Added: trunk/fb2-perl-tools/XSD/FB2.0/FictionBookGenres.xsd =================================================================== --- trunk/fb2-perl-tools/XSD/FB2.0/FictionBookGenres.xsd (rev 0) +++ trunk/fb2-perl-tools/XSD/FB2.0/FictionBookGenres.xsd 2008-01-26 22:41:33 UTC (rev 54) @@ -0,0 +1,393 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- edited with XML Spy v4.2 U (http://www.xmlspy.com) by * (*) --> +<xs:schema targetNamespace="http://www.gribuser.ru/xml/fictionbook/2.0/genres" xmlns="http://www.gribuser.ru/xml/fictionbook/2.0/genres" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> + <xs:simpleType name="genreType"> + <xs:restriction base="xs:token"> + <xs:enumeration value="architecture"/> + <xs:enumeration value="art"/> + <xs:enumeration value="art_instr"/> + <xs:enumeration value="artists"/> + <xs:enumeration value="fashion"/> + <xs:enumeration value="graph_design"/> + <xs:enumeration value="performance"/> + <xs:enumeration value="photography"/> + <xs:enumeration value="people"/> + <xs:enumeration value="biography"/> + <xs:enumeration value="biogr_arts"/> + <xs:enumeration value="biogr_ethnic"/> + <xs:enumeration value="biogr_family"/> + <xs:enumeration value="biogr_historical"/> + <xs:enumeration value="biogr_leaders"/> + <xs:enumeration value="biogr_professionals"/> + <xs:enumeration value="biogr_sports"/> + <xs:enumeration value="biogr_travel"/> + <xs:enumeration value="business"/> + <xs:enumeration value="biz_accounting"/> + <xs:enumeration value="biz_beogr"/> + <xs:enumeration value="biz_life"/> + <xs:enumeration value="biz_careers"/> + <xs:enumeration value="biz_economics"/> + <xs:enumeration value="biz_finance"/> + <xs:enumeration value="biz_international"/> + <xs:enumeration value="biz_professions"/> + <xs:enumeration value="biz_investing"/> + <xs:enumeration value="biz_management"/> + <xs:enumeration value="biz_sales"/> + <xs:enumeration value="biz_personal_fin"/> + <xs:enumeration value="biz_ref"/> + <xs:enumeration value="biz_small_biz"/> + <xs:enumeration value="child_3"/> + <xs:enumeration value="child_4"/> + <xs:enumeration value="child_9"/> + <xs:enumeration value="child_animals"/> + <xs:enumeration value="child_art"/> + <xs:enumeration value="child_computers"/> + <xs:enumeration value="child_edu"/> + <xs:enumeration value="child_history"/> + <xs:enumeration value="child_obsessions"/> + <xs:enumeration value="child_people"/> + <xs:enumeration value="child_characters"/> + <xs:enumeration value="child_ref"/> + <xs:enumeration value="child_religion"/> + <xs:enumeration value="child_nature"/> + <xs:enumeration value="child_series"/> + <xs:enumeration value="child_sports"/> + <xs:enumeration value="chris_bibles"/> + <xs:enumeration value="chris_pravoslavie"/> + <xs:enumeration value="chris_catholicism"/> + <xs:enumeration value="chris_living"/> + <xs:enumeration value="chris_history"/> + <xs:enumeration value="chris_clergy"/> + <xs:enumeration value="chris_edu"/> + <xs:enumeration value="chris_evangelism"/> + <xs:enumeration value="chris_fiction"/> + <xs:enumeration value="chris_holidays"/> + <xs:enumeration value="chris_jesus"/> + <xs:enumeration value="chris_mormonism"/> + <xs:enumeration value="chris_orthodoxy"/> + <xs:enumeration value="chris_protestantism"/> + <xs:enumeration value="chris_ref"/> + <xs:enumeration value="chris_theology"/> + <xs:enumeration value="chris_devotion"/> + <xs:enumeration value="computers"/> + <xs:enumeration value="comp_office"/> + <xs:enumeration value="comp_cert"/> + <xs:enumeration value="comp_games"/> + <xs:enumeration value="comp_sci"/> + <xs:enumeration value="comp_db"/> + <xs:enumeration value="comp_biz"/> + <xs:enumeration value="comp_graph"/> + <xs:enumeration value="comp_hardware"/> + <xs:enumeration value="comp_microsoft"/> + <xs:enumeration value="comp_networking"/> + <xs:enumeration value="comp_os"/> + <xs:enumeration value="comp_programming"/> + <xs:enumeration value="comp_software"/> + <xs:enumeration value="comp_www"/> + <xs:enumeration value="cooking"/> + <xs:enumeration value="cook_baking"/> + <xs:enumeration value="cook_can"/> + <xs:enumeration value="cook_art"/> + <xs:enumeration value="cook_drink"/> + <xs:enumeration value="cook_gastronomy"/> + <xs:enumeration value="cook_meals"/> + <xs:enumeration value="cook_natural"/> + <xs:enumeration value="cook_outdoor"/> + <xs:enumeration value="cook_pro"/> + <xs:enumeration value="cook_quick"/> + <xs:enumeration value="cook_ref"/> + <xs:enumeration value="cook_regional"/> + <xs:enumeration value="cook_appliances"/> + <xs:enumeration value="cook_diet"/> + <xs:enumeration value="cook_spec"/> + <xs:enumeration value="cook_veget"/> + <xs:enumeration value="entertainment"/> + <xs:enumeration value="entert_comics"/> + <xs:enumeration value="entert_games"/> + <xs:enumeration value="entert_humor"/> + <xs:enumeration value="entert_movies"/> + <xs:enumeration value="entert_music"/> + <xs:enumeration value="performance"/> + <xs:enumeration value="nonfiction_pop_culture"/> + <xs:enumeration value="entert_radio"/> + <xs:enumeration value="entert_tv"/> + <xs:enumeration value="gay_biogr"/> + <xs:enumeration value="history_gay"/> + <xs:enumeration value="literature_gay"/> + <xs:enumeration value="gay_mystery"/> + <xs:enumeration value="gay_nonfiction"/> + <xs:enumeration value="gay_parenting"/> + <xs:enumeration value="gay_travel"/> + <xs:enumeration value="health"/> + <xs:enumeration value="health_aging"/> + <xs:enumeration value="health_alt_medicine"/> + <xs:enumeration value="health_beauty"/> + <xs:enumeration value="health_cancer"/> + <xs:enumeration value="health_death"/> + <xs:enumeration value="health_diets"/> + <xs:enumeration value="health_dideases"/> + <xs:enumeration value="health_fitness"/> + <xs:enumeration value="health_men"/> + <xs:enumeration value="health_mental"/> + <xs:enumeration value="health_nutrition"/> + <xs:enumeration value="health_personal"/> + <xs:enumeration value="health_psy"/> + <xs:enumeration value="health_recovery"/> + <xs:enumeration value="health_ref"/> + <xs:enumeration value="health_rel"/> + <xs:enumeration value="health_first_aid"/> + <xs:enumeration value="health_self_help"/> + <xs:enumeration value="health_sex"/> + <xs:enumeration value="health_women"/> + <xs:enumeration value="history_africa"/> + <xs:enumeration value="history_america"/> + <xs:enumeration value="history_ancient"/> + <xs:enumeration value="history_asia"/> + <xs:enumeration value="history_australia"/> + <xs:enumeration value="history_europe"/> + <xs:enumeration value="history_study"/> + <xs:enumeration value="history_jewish"/> + <xs:enumeration value="history_middle_east"/> + <xs:enumeration value="histor_military"/> + <xs:enumeration value="history_military_science"/> + <xs:enumeration value="history_russia"/> + <xs:enumeration value="history_usa"/> + <xs:enumeration value="history_world"/> + <xs:enumeration value="history_gay"/> + <xs:enumeration value="home_pets"/> + <xs:enumeration value="home_collect"/> + <xs:enumeration value="home_crafts"/> + <xs:enumeration value="home_entertain"/> + <xs:enumeration value="home_expert"/> + <xs:enumeration value="home_garden"/> + <xs:enumeration value="home_design"/> + <xs:enumeration value="home_howto"/> + <xs:enumeration value="home_interior_design"/> + <xs:enumeration value="home_cottage"/> + <xs:enumeration value="home_weddings"/> + <xs:enumeration value="horror"/> + <xs:enumeration value="horror_antology"/> + <xs:enumeration value="horror_british"/> + <xs:enumeration value="horror_fantasy"/> + <xs:enumeration value="horror_erotic"/> + <xs:enumeration value="horror_ghosts"/> + <xs:enumeration value="horror_graphic"/> + <xs:enumeration value="horror_occult"/> + <xs:enumeration value="horror_ref"/> + <xs:enumeration value="horror_usa"/> + <xs:enumeration value="horror_vampires"/> + <xs:enumeration value="literature"/> + <xs:enumeration value="literature_books"/> + <xs:enumeration value="literature_british"/> + <xs:enumeration value="literature_classics"/> + <xs:enumeration value="literature_drama"/> + <xs:enumeration value="literature_essay"/> + <xs:enumeration value="literature_adv"/> + <xs:enumeration value="literature_antology"/> + <xs:enumeration value="literature_erotica"/> + <xs:enumeration value="literature_fairy"/> + <xs:enumeration value="literature_saga"/> + <xs:enumeration value="literature_gay"/> + <xs:enumeration value="literature_history"/> + <xs:enumeration value="literature_men_advent"/> + <xs:enumeration value="literature_political"/> + <xs:enumeration value="literature_religion"/> + <xs:enumeration value="literature_sea"/> + <xs:enumeration value="literature_sports"/> + <xs:enumeration value="literature_war"/> + <xs:enumeration value="literature_western"/> + <xs:enumeration value="literature_critic"/> + <xs:enumeration value="literature_letters"/> + <xs:enumeration value="literature_poetry"/> + <xs:enumeration value="literature_short"/> + <xs:enumeration value="literature_usa"/> + <xs:enumeration value="literature_women"/> + <xs:enumeration value="literature_world"/> + <xs:enumeration value="literature_rus_classsic"/> + <xs:enumeration value="literature_su_classics"/> + <xs:enumeration value="mystery"/> + <xs:enumeration value="thriller_mystery"/> + <xs:enumeration value="thriller_police"/> + <xs:enumeration value="thriller"/> + <xs:enumeration value="nonfiction_avto"/> + <xs:enumeration value="nonfiction_crime"/> + <xs:enumeration value="nonfiction_events"/> + <xs:enumeration value="biz_economics"/> + <xs:enumeration value="nonfiction_edu"/> + <xs:enumeration value="nonfiction_gov"/> + <xs:enumeration value="nonfiction_holidays"/> + <xs:enumeration value="nonfiction_law"/> + <xs:enumeration value="nonfiction_philosophy"/> + <xs:enumeration value="nonfiction_politics"/> + <xs:enumeration value="nonfiction_social_sci"/> + <xs:enumeration value="nonfiction_antropology"/> + <xs:enumeration value="science_archaeology"/> + <xs:enumeration value="nonfiction_traditions"/> + <xs:enumeration value="nonfiction_demography"/> + <xs:enumeration value="nonfiction_racism"/> + <xs:enumeration value="nonfiction_emigration"/> + <xs:enumeration value="nonfiction_ethnology"/> + <xs:enumeration value="nonfiction_folklor"/> + <xs:enumeration value="nonfiction_gender"/> + <xs:enumeration value="nonfiction_gerontology"/> + <xs:enumeration value="nonfiction_hum_geogr"/> + <xs:enumeration value="nonfiction_methodology"/> + <xs:enumeration value="nonfiction_philantropy"/> + <xs:enumeration value="nonfiction_pop_culture"/> + <xs:enumeration value="nonfiction_pornography"/> + <xs:enumeration value="nonfiction_ref"/> + <xs:enumeration value="nonfiction_research"/> + <xs:enumeration value="nonfiction_social_work"/> + <xs:enumeration value="nonfiction_sociology"/> + <xs:enumeration value="nonfiction_spec_group"/> + <xs:enumeration value="nonfiction_stat"/> + <xs:enumeration value="health_psy"/> + <xs:enumeration value="nonfiction_transportation"/> + <xs:enumeration value="nonfiction_true_accounts"/> + <xs:enumeration value="nonfiction_urban"/> + <xs:enumeration value="nonfiction_women"/> + <xs:enumeration value="outdoors_birdwatching"/> + <xs:enumeration value="outdoors_conservation"/> + <xs:enumeration value="outdoors_ecology"/> + <xs:enumeration value="outdoors_ecosystems"/> + <xs:enumeration value="outdoors_env"/> + <xs:enumeration value="outdoors_fauna"/> + <xs:enumeration value="outdoors_field_guides"/> + <xs:enumeration value="outdoors_flora"/> + <xs:enumeration value="outdoors_hiking"/> + <xs:enumeration value="outdoors_hunt_fish"/> + <xs:enumeration value="outdoors_resources"/> + <xs:enumeration value="outdoors_nature_writing"/> + <xs:enumeration value="outdoors_outdoor_recreation"/> + <xs:enumeration value="outdoors_ref"/> + <xs:enumeration value="outdoors_survive"/> + <xs:enumeration value="outdoors_travel"/> + <xs:enumeration value="family"/> + <xs:enumeration value="family_adoption"/> + <xs:enumeration value="family_aging_parents"/> + <xs:enumeration value="family_edu"/> + <xs:enumeration value="family_activities"/> + <xs:enumeration value="family_health"/> + <xs:enumeration value="family_relations"/> + <xs:enumeration value="family_fertility"/> + <xs:enumeration value="family_humor"/> + <xs:enumeration value="family_lit_guide"/> + <xs:enumeration value="family_parenting"/> + <xs:enumeration value="family_pregnancy"/> + <xs:enumeration value="family_ref"/> + <xs:enumeration value="family_special_needs"/> + <xs:enumeration value="professional_finance"/> + <xs:enumeration value="architecture"/> + <xs:enumeration value="professional_management"/> + <xs:enumeration value="professional_edu"/> + <xs:enumeration value="professional_enginering"/> + <xs:enumeration value="professional_law"/> + <xs:enumeration value="professional_medical"/> + <xs:enumeration value="professional_sci"/> + <xs:enumeration value="references"/> + <xs:enumeration value="ref_almanacs"/> + <xs:enumeration value="biz_ref"/> + <xs:enumeration value="ref_careers"/> + <xs:enumeration value="ref_catalogs"/> + <xs:enumeration value="ref_cons_guides"/> + <xs:enumeration value="ref_dict"/> + <xs:enumeration value="ref_edu"/> + <xs:enumeration value="ref_encyclopedia"/> + <xs:enumeration value="ref_etiquette"/> + <xs:enumeration value="ref_langs"/> + <xs:enumeration value="ref_fun"/> + <xs:enumeration value="ref_genealogy"/> + <xs:enumeration value="nonfiction_law"/> + <xs:enumeration value="ref_books"/> + <xs:enumeration value="ref_quotations"/> + <xs:enumeration value="ref_study_guides"/> + <xs:enumeration value="ref_words"/> + <xs:enumeration value="ref_writing"/> + <xs:enumeration value="religion"/> + <xs:enumeration value="religion_bibles"/> + <xs:enumeration value="religion_buddhism"/> + <xs:enumeration value="religion_earth"/> + <xs:enumeration value="religion_fiction"/> + <xs:enumeration value="religion_hinduism"/> + <xs:enumeration value="religion_islam"/> + <xs:enumeration value="religion_judaism"/> + <xs:enumeration value="religion_new_age"/> + <xs:enumeration value="religion_occult"/> + <xs:enumeration value="religion_religious_studies"/> + <xs:enumeration value="religion_spirituality"/> + <xs:enumeration value="religion_east"/> + <xs:enumeration value="religion_other"/> + <xs:enumeration value="romance"/> + <xs:enumeration value="romance_anthologies"/> + <xs:enumeration value="romance_contemporary"/> + <xs:enumeration value="romance_fantasy"/> + <xs:enumeration value="romance_sf"/> + <xs:enumeration value="romance_historical"/> + <xs:enumeration value="romance_multicultural"/> + <xs:enumeration value="romance_regency"/> + <xs:enumeration value="romance_religion"/> + <xs:enumeration value="romance_romantic_suspense"/> + <xs:enumeration value="romance_series"/> + <xs:enumeration value="romance_time_travel"/> + <xs:enumeration value="ref_writing"/> + <xs:enumeration value="science"/> + <xs:enumeration value="science_agri"/> + <xs:enumeration value="science_archaeology"/> + <xs:enumeration value="science_astronomy"/> + <xs:enumeration value="science_behavioral sciences"/> + <xs:enumeration value="science_psy"/> + <xs:enumeration value="science_biolog"/> + <xs:enumeration value="science_chemistry"/> + <xs:enumeration value="science_earth"/> + <xs:enumeration value="science_edu"/> + <xs:enumeration value="science_evolution"/> + <xs:enumeration value="science_measurement"/> + <xs:enumeration value="science_history_philosophy"/> + <xs:enumeration value="science_math"/> + <xs:enumeration value="science_medicine"/> + <xs:enumeration value="science_eco"/> + <xs:enumeration value="science_physics"/> + <xs:enumeration value="science_ref"/> + <xs:enumeration value="science_technology"/> + <xs:enumeration value="romance_sf"/> + <xs:enumeration value="romance_fantasy"/> + <xs:enumeration value="gaming"/> + <xs:enumeration value="sf_writing"/> + <xs:enumeration value="fantasy_alt_hist"/> + <xs:enumeration value="sf_cyber_punk"/> + <xs:enumeration value="sport"/> + <xs:enumeration value="teens_beogr"/> + <xs:enumeration value="teens_health"/> + <xs:enumeration value="teens_history"/> + <xs:enumeration value="teens_horror"/> + <xs:enumeration value="teens_literature"/> + <xs:enumeration value="teens_mysteries"/> + <xs:enumeration value="teens_ref"/> + <xs:enumeration value="teens_religion"/> + <xs:enumeration value="teens_school_sports"/> + <xs:enumeration value="teens_sf"/> + <xs:enumeration value="teens_tech"/> + <xs:enumeration value="teens_series"/> + <xs:enumeration value="teens_social"/> + <xs:enumeration value="travel"/> + <xs:enumeration value="travel_africa"/> + <xs:enumeration value="travel_asia"/> + <xs:enumeration value="travel_australia"/> + <xs:enumeration value="travel_canada"/> + <xs:enumeration value="travel_caribbean"/> + <xs:enumeration value="travel_europe"/> + <xs:enumeration value="travel_guidebook_series"/> + <xs:enumeration value="travel_lat_am"/> + <xs:enumeration value="travel_middle_east"/> + <xs:enumeration value="travel_polar"/> + <xs:enumeration value="travel_spec"/> + <xs:enumeration value="travel_usa"/> + <xs:enumeration value="travel_rus"/> + <xs:enumeration value="travel_ex_ussr"/> + <xs:enumeration value="women_divorce"/> + <xs:enumeration value="women_domestic"/> + <xs:enumeration value="women_child"/> + <xs:enumeration value="women_single"/> + </xs:restriction> + </xs:simpleType> +</xs:schema> Added: trunk/fb2-perl-tools/XSD/FB2.0/FictionBookLang.xsd =================================================================== --- trunk/fb2-perl-tools/XSD/FB2.0/FictionBookLang.xsd (rev 0) +++ trunk/fb2-perl-tools/XSD/FB2.0/FictionBookLang.xsd 2008-01-26 22:41:33 UTC (rev 54) @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- edited with XML Spy v4.4 U (http://www.xmlspy.com) by Dmitry Gribov (DDS) --> + +<xs:schema targetNamespace="http://www.w3.org/XML/1998/namespace" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/XML/1998/namespace" elementFormDefault="qualified" attributeFormDefault="unqualified"> + + <xs:attribute name="lang" type="xs:language"> + + <xs:annotation> + + <xs:documentation>Element content's languige</xs:documentation> + + </xs:annotation> + + </xs:attribute> + +</xs:schema> + Added: trunk/fb2-perl-tools/XSD/FB2.0/FictionBookLinks.xsd =================================================================== --- trunk/fb2-perl-tools/XSD/FB2.0/FictionBookLinks.xsd (rev 0) +++ trunk/fb2-perl-tools/XSD/FB2.0/FictionBookLinks.xsd 2008-01-26 22:41:33 UTC (rev 54) @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- edited with XML Spy v4.2 U (http://www.xmlspy.com) by * (*) --> + +<xs:schema targetNamespace="http://www.w3.org/1999/xlink" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/1999/xlink" elementFormDefault="qualified" attributeFormDefault="unqualified"> + + <xs:attribute name="type" type="xs:string" fixed="simple"> + + <xs:annotation> + + <xs:documentation>link type</xs:documentation> + + </xs:annotation> + + </xs:attribute> + + <xs:attribute name="href" type="xs:string"> + + <xs:annotation> + + <xs:documentation>link target</xs:documentation> + + </xs:annotation> + + </xs:attribute> + +</xs:schema> + Added: trunk/fb2-perl-tools/XSD/FB2.1/FictionBook.xsd =================================================================== --- trunk/fb2-perl-tools/XSD/FB2.1/FictionBook.xsd (rev 0) +++ trunk/fb2-perl-tools/XSD/FB2.1/FictionBook.xsd 2008-01-26 22:41:33 UTC (rev 54) @@ -0,0 +1,655 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- edited with XML Spy v4.4 U (http://www.xmlspy.com) by GribUser (Moscow) --> +<xs:schema targetNamespace="http://www.gribuser.ru/xml/fictionbook/2.0" xmlns:genre="http://www.gribuser.ru/xml/fictionbook/2.0/genres" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.gribuser.ru/xml/fictionbook/2.0" elementFormDefault="qualified" attributeFormDefault="unqualified"> + <xs:import namespace="http://www.w3.org/1999/xlink" schemaLocation="FictionBookLinks.xsd"/> + <xs:import namespace="http://www.gribuser.ru/xml/fictionbook/2.0/genres" schemaLocation="FictionBookGenres.xsd"/> + <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="FictionBookLang.xsd"/> + <xs:element name="FictionBook"> + <xs:annotation> + <xs:documentation>Root element</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:sequence> + <xs:element name="stylesheet" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>This element contains an arbitrary stylesheet that is intepreted by a some processing programs, e.g. text/css stylesheets can be used by XSLT stylesheets to generate better looking html</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="type" type="xs:string" use="required"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + <xs:element name="description"> + <xs:complexType> + <xs:sequence> + <xs:element name="title-info" type="title-infoType"> + <xs:annotation> + <xs:documentation>Generic information about the book</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="src-title-info" type="title-infoType" minOccurs="0"> + <xs:annotation> + <xs:documentation>Generic information about the original book (for translations) </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="document-info"> + <xs:annotation> + <xs:documentation>Information about this particular (xml) document</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:sequence> + <xs:element name="author" type="authorType" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>Author(s) of this particular document</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="program-used" type="textFieldType" minOccurs="0"> + <xs:annotation> + <xs:documentation>Any software used in preparation of this document, in free format</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="date" type="dateType"> + <xs:annotation> + <xs:documentation>Date this document was created, same guidelines as in the <title-info> section apply</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="src-url" type="xs:string" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>Source URL if this document is a conversion of some other (online) document</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="src-ocr" type="textFieldType" minOccurs="0"> + <xs:annotation> + <xs:documentation>Author of the original (online) document, if this is a conversion</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="id" type="xs:token"> + <xs:annotation> + <xs:documentation>this is a unique identifier for a document. this must not change</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="version" type="xs:float"> + <xs:annotation> + <xs:documentation>Document version, in free format, should be incremented if the document is changed and re-released to the public</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="history" type="annotationType" minOccurs="0"> + <xs:annotation> + <xs:documentation>Short description for all changes made to this document, like "Added missing chapter 6", in free form.</xs:documentation> + </xs:annotation> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="publish-info" minOccurs="0"> + <xs:annotation> + <xs:documentation>Information about some paper/outher published document, that was used as a source of this xml document</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:sequence> + <xs:element name="book-name" type="textFieldType" minOccurs="0"> + <xs:annotation> + <xs:documentation>Original (paper) book name</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="publisher" type="textFieldType" minOccurs="0"> + <xs:annotation> + <xs:documentation>Original (paper) book publisher</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="city" type="textFieldType" minOccurs="0"> + <xs:annotation> + <xs:documentation>City where the original (paper) book was published</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="year" type="xs:gYear" minOccurs="0"> + <xs:annotation> + <xs:documentation>Year of the original (paper) publication</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="isbn" type="textFieldType" minOccurs="0"/> + <xs:element name="sequence" type="sequenceType" minOccurs="0" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="custom-info" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>Any other information about the book/document that didnt fit in the above groups</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="textFieldType"> + <xs:attribute name="info-type" type="xs:string" use="required"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + <xs:element name="output" type="shareInstructionType" minOccurs="0" maxOccurs="2"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="body" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>Main content of the book, multiple bodies are used for additional information, like footnotes, that do not appear in the main book flow. The first body is presented to the reader by default, and content in the other bodies should be accessible by hyperlinks. Name attribute should describe the meaning of this body, this is optional for the main body.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:sequence> + <xs:element name="image" type="imageType" minOccurs="0"> + <xs:annotation> + <xs:documentation>Image to be displayed at the top of this section</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="title" type="titleType" minOccurs="0"> + <xs:annotation> + <xs:documentation>A fancy title for the entire book, should be used if the simple text version in <description> is not adequate, e.g. the book title has multiple paragraphs and/or character styles</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="epigraph" type="epigraphType" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>Epigraph(s) for the entire book, if any</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="section" type="sectionType" maxOccurs="unbounded"/> + </xs:sequence> + <xs:attribute name="name" type="xs:string" use="optional"/> + <xs:attribute ref="xml:lang"/> + </xs:complexType> + </xs:element> + <xs:element name="binary" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>Any binary data that is required for the presentation of this book in base64 format. Currently only images are used.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:base64Binary"> + <xs:attribute name="content-type" type="xs:string" use="required"/> + <xs:attribute name="id" type="xs:ID" use="required"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:complexType name="authorType"> + <xs:annotation> + <xs:documentation>Information about a single author</xs:documentation> + </xs:annotation> + <xs:choice> + <xs:sequence> + <xs:element name="first-name" type="textFieldType"/> + <xs:element name="middle-name" type="textFieldType" minOccurs="0"/> + <xs:element name="last-name" type="textFieldType"/> + <xs:element name="nickname" type="textFieldType" minOccurs="0"/> + <xs:element name="home-page" type="xs:string" minOccurs="0" maxOccurs="unbounded"/> + <xs:element name="email" type="xs:string" minOccurs="0" maxOccurs="unbounded"/> + </xs:sequence> + <xs:sequence> + <xs:element name="nickname" type="textFieldType"/> + <xs:element name="home-page" type="xs:string" minOccurs="0" maxOccurs="unbounded"/> + <xs:element name="email" type="xs:string" minOccurs="0" maxOccurs="unbounded"/> + </xs:sequence> + </xs:choice> + </xs:complexType> + <xs:complexType name="textFieldType"> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute ref="xml:lang"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + <xs:complexType name="dateType"> + <xs:annotation> + <xs:documentation>A human readable date, maybe not exact, with an optional computer readable variant</xs:documentation> + </xs:annotation> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="value" type="xs:date" use="optional"/> + <xs:attribute ref="xml:lang"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + <xs:complexType name="titleType"> + <xs:annotation> + <xs:documentation>A title, used in sections, poems and body elements</xs:documentation> + </xs:annotation> + <xs:choice minOccurs="0" maxOccurs="unbounded"> + <xs:element name="p" type="pType"/> + <xs:element name="empty-line"/> + </xs:choice> + <xs:attribute ref="xml:lang"/> + </xs:complexType> + <xs:complexType name="imageType"> + <xs:annotation> + <xs:documentation>An empty element with an image name as an attribute</xs:documentation> + </xs:annotation> + <xs:attribute ref="xlink:type"/> + <xs:attribute ref="xlink:href"/> + <xs:attribute name="alt" type="xs:string" use="optional"/> + <xs:attribute name="title" type="xs:string" use="optional"/> + <xs:attribute name="id" type="xs:ID" use="optional"/> + </xs:complexType> + <xs:complexType name="pType" mixed="true"> + <xs:annotation> + <xs:documentation>A basic paragraph, may include simple formatting inside</xs:documentation> + </xs:annotation> + <xs:complexContent mixed="true"> + <xs:extension base="styleType"> + <xs:attribute name="id" type="xs:ID" use="optional"/> + <xs:attribute name="style" type="xs:string" use="optional"/> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="citeType"> + <xs:annotation> + <xs:documentation>A citation with an optional citation author at the end</xs:documentation> + </xs:annotation> + <xs:sequence> + <xs:choice minOccurs="0" maxOccurs="unbounded"> + <xs:element name="p" type="pType"/> + <xs:element name="poem" type="poemType"/> + <xs:element name="empty-line"/> + <xs:element name="subtitle" type="pType"/> + <xs:element name="table" type="tableType"/> + </xs:choice> + <xs:element name="text-author" type="pType" minOccurs="0" maxOccurs="unbounded"/> + </xs:sequence> + <xs:attribute name="id" type="xs:ID" use="optional"/> + <xs:attribute ref="xml:lang"/> + </xs:complexType> + <xs:complexType name="poemType"> + <xs:annotation> + <xs:documentation>A poem</xs:documentation> + </xs:annotation> + <xs:sequence> + <xs:element name="title" type="titleType" minOccurs="0"> + <xs:annotation> + <xs:documentation>Poem title</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="epigraph" type="epigraphType" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>Poem epigraph(s), if any</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="stanza" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>Each poem should have at least one stanza. Stanzas are usually separated with empty lines by user agents.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:sequence> + <xs:element name="title" type="titleType" minOccurs="0"/> + <xs:element name="subtitle" type="pType" minOccurs="0"/> + <xs:element name="v" type="pType" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>An individual line in a stanza</xs:documentation> + </xs:annotation> + </xs:element> + </xs:sequence> + <xs:attribute ref="xml:lang"/> + </xs:complexType> + </xs:element> + <xs:element name="text-author" type="pType" minOccurs="0" maxOccurs="unbounded"/> + <xs:element name="date" type="dateType" minOccurs="0"> + <xs:annotation> + <xs:documentation>Date this poem was written.</xs:documentation> + </xs:annotation> + </xs:element> + </xs:sequence> + <xs:attribute name="id" type="xs:ID" use="optional"/> + <xs:attribute ref="xml:lang"/> + </xs:complexType> + <xs:complexType name="epigraphType"> + <xs:annotation> + <xs:documentation>An epigraph</xs:documentation> + </xs:annotation> + <xs:sequence> + <xs:choice minOccurs="0" maxOccurs="unbounded"> + <xs:element name="p" type="pType"/> + <... [truncated message content] |
From: <sh...@us...> - 2007-11-07 12:18:49
|
Revision: 53 http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=53&view=rev Author: shaplov Date: 2007-11-07 04:18:45 -0800 (Wed, 07 Nov 2007) Log Message: ----------- That Will allow convert multiline comments into footnotes Modified Paths: -------------- trunk/fb2-perl-tools/fb2/Footnotes.pm Modified: trunk/fb2-perl-tools/fb2/Footnotes.pm =================================================================== --- trunk/fb2-perl-tools/fb2/Footnotes.pm 2007-10-14 15:47:25 UTC (rev 52) +++ trunk/fb2-perl-tools/fb2/Footnotes.pm 2007-11-07 12:18:45 UTC (rev 53) @@ -82,11 +82,11 @@ if ($_->nodeType == XML_COMMENT_NODE) { my $node=$_; - if ( $node->data()=~/^\s*$keyword(.*)/ ) + if ( $node->data()=~/^\s*$keyword(.*)/s ) { my $text=$1; my $number = int(rand(10000)); - if ($use_number && ($text=~/^(\d+)\s+(.*)$/) ) + if ($use_number && ($text=~/^(\d+)\s+(.*)$/s) ) { $text = $2; $number = $1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ki...@us...> - 2007-10-14 15:47:26
|
Revision: 52 http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=52&view=rev Author: kir666 Date: 2007-10-14 08:47:25 -0700 (Sun, 14 Oct 2007) Log Message: ----------- fb2:subtitle to docbook:bridgeahead; add date-time to docbook output; more checks at gen_infos Modified Paths: -------------- trunk/fb2-perl-tools/xslt/fb2docbook.xsl trunk/fb2-perl-tools/xslt/fb2docbook_gen_infos.xsl trunk/fb2-perl-tools/xslt/l10n/en.xml trunk/fb2-perl-tools/xslt/l10n/ru.xml Modified: trunk/fb2-perl-tools/xslt/fb2docbook.xsl =================================================================== --- trunk/fb2-perl-tools/xslt/fb2docbook.xsl 2007-09-04 12:11:02 UTC (rev 51) +++ trunk/fb2-perl-tools/xslt/fb2docbook.xsl 2007-10-14 15:47:25 UTC (rev 52) @@ -1,14 +1,14 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- - -Copyright 2007 by KiR Jakobson ( http://kir666.ru/fb2docbook/ ) - -This library is free software; you can redistribute it and/or modify -it under the terms of the General Public License (GPL). For -more information, see http://www.fsf.org/licenses/gpl.txt - ---> - +<!-- + + Copyright 2007 by KiR Jakobson ( http://kir666.ru/fb2docbook/ ) + + This library is free software; you can redistribute it and/or modify + it under the terms of the General Public License (GPL). For + more information, see http://www.fsf.org/licenses/gpl.txt + +--> + <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:fb="http://www.gribuser.ru/xml/fictionbook/2.0" xmlns:exsl="http://exslt.org/common" xmlns:redirect="http://xml.apache.org/xalan/redirect" @@ -390,7 +390,7 @@ </xsl:template> <xsl:template name="a_xref"> <xsl:param name="href_id"/> - <xref linkend="{$href_id}"/> + <xref linkend="{$href_id}"/> </xsl:template> <xsl:template name="metadata_author"> <xsl:choose> @@ -411,37 +411,56 @@ <xsl:text>"</xsl:text> </xsl:if> </xsl:otherwise> - </xsl:choose> + </xsl:choose> </xsl:template> <xsl:template name="write_binaries_tree"> <conversion_info> <page> <dpi> - <width><xsl:value-of select="$output.dpi.width"/></width> - <height><xsl:value-of select="$output.dpi.height"/></height> + <width> + <xsl:value-of select="$output.dpi.width"/> + </width> + <height> + <xsl:value-of select="$output.dpi.height"/> + </height> </dpi> <size> - <width><xsl:value-of select="$page.width"/></width> - <height><xsl:value-of select="$page.height"/></height> + <width> + <xsl:value-of select="$page.width"/> + </width> + <height> + <xsl:value-of select="$page.height"/> + </height> </size> <max_image_margin> - <width><xsl:value-of select="$output.max_image_margin.width"/></width> - <height><xsl:value-of select="$output.max_image_margin.height"/></height> + <width> + <xsl:value-of select="$output.max_image_margin.width"/> + </width> + <height> + <xsl:value-of select="$output.max_image_margin.height"/> + </height> </max_image_margin> <images_mode> - <resize><xsl:value-of select="$output.images_mode.resize"/></resize> - <mode><xsl:value-of select="$output.images_mode.mode"/></mode> - </images_mode> + <resize> + <xsl:value-of select="$output.images_mode.resize"/> + </resize> + <mode> + <xsl:value-of select="$output.images_mode.mode"/> + </mode> + </images_mode> </page> - <metadata> + <metadata> <Title> - <xsl:value-of select="/fb:FictionBook/fb:description/fb:title-info/fb:book-title"/> + <xsl:value-of + select="/fb:FictionBook/fb:description/fb:title-info/fb:book-title"/> </Title> <Author> - <xsl:for-each select="/fb:FictionBook/fb:description/fb:title-info/fb:author[position() = 1]"> + <xsl:for-each + select="/fb:FictionBook/fb:description/fb:title-info/fb:author[position() = 1]"> <xsl:call-template name="metadata_author"/> </xsl:for-each> - <xsl:for-each select="/fb:FictionBook/fb:description/fb:title-info/fb:author[position() > 1]"> + <xsl:for-each + select="/fb:FictionBook/fb:description/fb:title-info/fb:author[position() > 1]"> <xsl:text>; </xsl:text> <xsl:call-template name="metadata_author"/> </xsl:for-each> @@ -684,15 +703,10 @@ </xsl:element> </xsl:template> <xsl:template match="fb:subtitle"> - <simpara> + <bridgehead> <xsl:apply-templates select="@xml:lang|@id"/> - <emphasis role="{$fb2.subtitle.role}"> - <xsl:apply-templates/> - </emphasis> - </simpara> - <xsl:processing-instruction name="dbfo"> - <xsl:text>keep-together="always"</xsl:text> - </xsl:processing-instruction> + <xsl:apply-templates/> + </bridgehead> </xsl:template> <xsl:template match="fb:style"> <xsl:comment> == style <xsl:value-of select="@name"/> == </xsl:comment> Modified: trunk/fb2-perl-tools/xslt/fb2docbook_gen_infos.xsl =================================================================== --- trunk/fb2-perl-tools/xslt/fb2docbook_gen_infos.xsl 2007-09-04 12:11:02 UTC (rev 51) +++ trunk/fb2-perl-tools/xslt/fb2docbook_gen_infos.xsl 2007-10-14 15:47:25 UTC (rev 52) @@ -1,18 +1,19 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- - -Copyright 2007 by KiR Jakobson ( http://kir666.ru/fb2docbook/ ) - -This library is free software; you can redistribute it and/or modify -it under the terms of the General Public License (GPL). For -more information, see http://www.fsf.org/licenses/gpl.txt - ---> - +<!-- + + Copyright 2007 by KiR Jakobson ( http://kir666.ru/fb2docbook/ ) + + This library is free software; you can redistribute it and/or modify + it under the terms of the General Public License (GPL). For + more information, see http://www.fsf.org/licenses/gpl.txt + +--> + <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:fb="http://www.gribuser.ru/xml/fictionbook/2.0" - xmlns:exsl="http://exslt.org/common" xmlns:redirect="http://xml.apache.org/xalan/redirect" - extension-element-prefixes="exsl redirect" version="1.1"> + xmlns:exsl="http://exslt.org/common" xmlns:date="http://exslt.org/dates-and-times" + xmlns:redirect="http://xml.apache.org/xalan/redirect" + extension-element-prefixes="exsl date redirect" version="1.1"> <xsl:import href="l10n/gentext.xsl"/> <xsl:template name="technical-appendix"> <appendix id="{concat('tappendix', generate-id())}"> @@ -29,12 +30,21 @@ <xsl:text>: </xsl:text> <ulink url="{system-property('xsl:vendor-url')}"> <xsl:value-of select="system-property('xsl:vendor')"/> - </ulink> (XSLT version <xsl:value-of select="system-property('xsl:version')"/>). - </para> + </ulink> (XSLT version <xsl:value-of select="system-property('xsl:version')"/>). </para> + <xsl:if test="function-available('date:date-time')"> + <para> + <xsl:call-template name="gentext.info.param"> + <xsl:with-param name="context" select="'technical-appendix'"/> + <xsl:with-param name="param" select="'conversion-date-time'"/> + </xsl:call-template> + <xsl:text>: </xsl:text> + <xsl:value-of select="date:date-time()"/> + </para> + </xsl:if> </appendix> </xsl:template> <xsl:template name="title-info-appendix"> - <xsl:if test="count(fb:description/fb:title-info)"> + <xsl:if test="count(fb:description/fb:title-info) and count(fb:description/fb:title-info/*)"> <xsl:for-each select="fb:description/fb:title-info"> <xsl:call-template name="title-info-appendix-wrk"> <xsl:with-param name="my_id" @@ -48,7 +58,8 @@ </xsl:if> </xsl:template> <xsl:template name="src-title-info-appendix"> - <xsl:if test="count(fb:description/fb:src-title-info)"> + <xsl:if + test="count(fb:description/fb:src-title-info) and count(fb:description/fb:src-title-info/*)"> <xsl:for-each select="fb:description/fb:src-title-info"> <xsl:call-template name="title-info-appendix-wrk"> <xsl:with-param name="my_id" @@ -333,7 +344,8 @@ </simpara> </xsl:template> <xsl:template name="document-info-appendix"> - <xsl:if test="count(fb:description/fb:document-info)"> + <xsl:if + test="count(fb:description/fb:document-info) and count(fb:description/fb:document-info/*)"> <xsl:for-each select="fb:description/fb:document-info"> <xsl:call-template name="document-info-appendix-wrk"/> </xsl:for-each> @@ -457,7 +469,8 @@ <xsl:apply-templates select="fb:history/*"/> </xsl:template> <xsl:template name="publish-info-appendix"> - <xsl:if test="count(fb:description/fb:publish-info)"> + <xsl:if + test="count(fb:description/fb:publish-info) and count(fb:description/fb:publish-info/*)"> <xsl:for-each select="fb:description/fb:publish-info"> <xsl:call-template name="publish-info-appendix-wrk"/> </xsl:for-each> @@ -540,7 +553,8 @@ </appendix> </xsl:template> <xsl:template name="custom-info-appendix"> - <xsl:if test="count(fb:description/fb:custom-info)"> + <xsl:if + test="count(fb:description/fb:custom-info) and count(fb:description/fb:custom-info/*)"> <appendix id="{concat('custom-info-appendix', generate-id())}"> <xsl:for-each select="fb:description/fb:custom-info[1]"> <title> Modified: trunk/fb2-perl-tools/xslt/l10n/en.xml =================================================================== --- trunk/fb2-perl-tools/xslt/l10n/en.xml 2007-09-04 12:11:02 UTC (rev 51) +++ trunk/fb2-perl-tools/xslt/l10n/en.xml 2007-10-14 15:47:25 UTC (rev 52) @@ -1,14 +1,4 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- - -Copyright 2007 by KiR Jakobson ( http://kir666.ru/fb2docbook/ ) - -This library is free software; you can redistribute it and/or modify -it under the terms of the General Public License (GPL). For -more information, see http://www.fsf.org/licenses/gpl.txt - ---> - <l10n language="en" english-language-name="English"> <param name="SeeAbr" text="See"/> <param name="seeabr" text="see"/> @@ -77,5 +67,6 @@ <context name="technical-appendix"> <title text="Information about conversion"/> <param name="xslt.processor" text="XSLT processor"/> + <param name="conversion-date-time" text="Date and time of transformation Fictionbook2 — Docbook"/> </context> </l10n> Modified: trunk/fb2-perl-tools/xslt/l10n/ru.xml =================================================================== --- trunk/fb2-perl-tools/xslt/l10n/ru.xml 2007-09-04 12:11:02 UTC (rev 51) +++ trunk/fb2-perl-tools/xslt/l10n/ru.xml 2007-10-14 15:47:25 UTC (rev 52) @@ -1,14 +1,4 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- - -Copyright 2007 by KiR Jakobson ( http://kir666.ru/fb2docbook/ ) - -This library is free software; you can redistribute it and/or modify -it under the terms of the General Public License (GPL). For -more information, see http://www.fsf.org/licenses/gpl.txt - ---> - <l10n language="ru" english-language-name="Russian"> <param name="SeeAbr" text="См."/> <param name="seeabr" text="см."/> @@ -77,5 +67,6 @@ <context name="technical-appendix"> <title text="Информация о конвертации"/> <param name="xslt.processor" text="XSLT процессор"/> + <param name="conversion-date-time" text="Дата и время трансформации Fictionbook2 — Docbook"/> </context> </l10n> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2007-09-04 12:11:10
|
Revision: 51 http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=51&view=rev Author: shaplov Date: 2007-09-04 05:11:02 -0700 (Tue, 04 Sep 2007) Log Message: ----------- Now remove communiware dependences... Modified Paths: -------------- trunk/fb2-perl-tools/RTF/Control.pm trunk/fb2-perl-tools/RTF/HTML/ansi trunk/fb2-perl-tools/rtf2html Modified: trunk/fb2-perl-tools/RTF/Control.pm =================================================================== --- trunk/fb2-perl-tools/RTF/Control.pm 2007-09-04 12:09:14 UTC (rev 50) +++ trunk/fb2-perl-tools/RTF/Control.pm 2007-09-04 12:11:02 UTC (rev 51) @@ -56,12 +56,10 @@ process_char_props reset_char_props - set_input_charset - set_output_charset - $InMapper - $OutMapper from_unicode - ); + ); + + ########################################################################### %do_on_event = (); # output routines @@ -107,14 +105,14 @@ die "Bad params for accept options" unless ref($optdef) eq 'HASH'; my %opts = %$optdef; - # \xF0\xD2\xCF\xD7\xC5\xD2\xD1\xC5\xCD \xD7\xD3\xC5 \xD0\xC5\xD2\xC5\xC4\xC1\xCE\xCE\xD9\xC5 \xCF\xD0\xC3\xC9\xC9 + # Проверяем все переданные опции while (my ($key, $value) = each %arg) { next unless exists $opts{$key}; $self->{$key} = $value; delete $opts{$key}; } - # \xE9 \xCF\xD0\xD2\xC5\xC4\xC5\xCC\xC9\xCD \xD5\xCD\xCF\xCC\xDE\xC1\xCE\xC9\xD1 + # И определим умолчания while (my ($key, $value) = each %opts) { next unless defined $value; $self->{$key} = $value unless exists $self->{$key}; @@ -129,18 +127,16 @@ ( { Output => \*STDOUT, - InputCharset => 'cp1251', # \xEB\xC1\xCB\xCF\xCA \xD0\xD2\xC9\xCE\xD1\xD4\xD8 \xD7\xC8\xCF\xC4\xCE\xD9\xCD \xC5\xD3\xCC\xC9 \xCE\xC5\xD4 ansicpg - StrictInputCharset => '', # \xE5\xD3\xCC\xC9 \xDA\xC1\xC4\xC1\xCE - \xD4\xCF \xD0\xCC\xC5\xD7\xC1\xD4\xD8 \xCE\xC1 InCharset - OutputCharset => 'koi8-r', # \xF7 \xCB\xC1\xCB\xCF\xCD charset-\xC5 \xD7\xD9\xD7\xCF\xC4\xC9\xD4\xD8 + InputCharset => 'cp1251', # Какой принять входным если нет ansicpg + StrictInputCharset => '', # Если задан - то плевать на InCharset + OutputCharset => 'utf-8', # В каком charset-е выводить CatdocCharsets => '/usr/local/lib/catdoc', }, @_ ); set_top_output_to($self->{Output}); set_catdoc_libs($self->{CatdocCharsets}); - require Communiware::Charset; - Communiware::Charset::init_charset($self->{OutputCharset}) - unless ($Communiware::Charset::replace_string); + $self; } @@ -163,83 +159,37 @@ ########################################################################### -# \xF0\xCF\xC4\xC4\xC5\xD2\xD6\xCB\xC1 \xD0\xC5\xD2\xC5\xCB\xCF\xC4\xC9\xD2\xCF\xD7\xCF\xCB +# Поддержка перекодировок +use Encode; use vars qw/ - $InMapper $InCharset - $OutMapper $OutCharset - @directMapper $CatdocCharsets /; -# \xE7\xC4\xC5 \xCC\xC5\xD6\xC1\xD4 \xC6\xC1\xCA\xCC\xD9 \xDE\xC1\xD2\xD3\xC5\xD4\xCF\xD7 -($InMapper, $OutMapper, $InCharset, $OutCharset, $CatdocCharsets) = - (undef, undef, '', '', ''); +# Где лежат файлы чарсетов +($InCharset, $OutCharset, $CatdocCharsets) = + ('', '', ''); sub set_catdoc_libs {$CatdocCharsets = $_[0]} -sub set_input_charset { - my $charset= shift; - return if ($InCharset eq $charset); - my ($code,$unicode); - my $chrsname = "$CatdocCharsets/$charset.txt"; - die "Cannot set input charset to $charset, no $chrsname" unless -f $chrsname; - open CHARSET, $chrsname; - $InMapper = {}; - while (<CHARSET>) { - next unless /^\s*(0x[0-9A-Fa-f]{2})\s+((0x)?[0-9A-Fa-f]{4})/; - $code = hex($1); $unicode = hex($2); - $InMapper->{$unicode}=chr($code); - $directMapper[$code] = $unicode; - } - close CHARSET; - $InCharset = $charset; -} +sub from_unicode { + return $_[0]; +# Этого момента я не понял... Что бы мы не возвращали, все равно все работает правильно :-/ +# Разбираться пока леть... Работает же ;-) +# Шаплов. -sub set_output_charset { - my $charset= shift; - return if ($OutCharset eq $charset); - my ($code,$unicode); - my $chrsname = "$CatdocCharsets/$charset.txt"; - die "Cannot set output charset to $charset, no $chrsname" unless -f $chrsname; - open CHARSET, $chrsname; - $OutMapper = {}; - while (<CHARSET>) { - next unless /^\s*(0x[0-9A-Fa-f]{2})\s+((0x)?[0-9A-Fa-f]{4})/; - $code = chr(hex($1)); $unicode = hex($2); - $OutMapper->{$unicode} =$code; - } - close CHARSET; - $OutCharset = $charset; +# return "b"; +# return ($InMapper->{$_[0]} || '"'); } -sub make_direct_map { - my $i; - foreach $i (grep {defined} @directMapper) { - - $i = $OutMapper->{$i} || '"'; - } -} -sub from_unicode { - return ($InMapper->{$_[0]} || '"'); -} - -sub recode_char { - my $char= $directMapper[ord($_[0])]; - $char = $Communiware::Charset::escaping{$char} - if exists $Communiware::Charset::escaping{$char}; - return $char; -} - sub recode_string { - local $_ = shift; - s/([\200-\377])/$directMapper[ord($1)]/eg; - s/([$Communiware::Charset::replace_string])/$Communiware::Charset::escaping{$1}/eg; - - return $_; + my $in_str = shift; + my $utf8_str = Encode::decode($InCharset,$in_str); + my $out_str = Encode::encode($OutCharset,$utf8_str,Encode::FB_XMLCREF); + return $out_str; } ########################################################################### # Utils @@ -317,7 +267,7 @@ # the default prints on the selected output filehandle sub flush_top_output { - # \xF0\xC5\xDE\xC1\xD4\xC1\xD4\xD8 \xC9\xCC\xC9 \xCB\xC1\xCB \xC5\xD3\xD4\xD8, \xC9\xCC\xC9 \xD3 \xD0\xC5\xD2\xC5\xCB\xCF\xC4\xC9\xD2\xCF\xD7\xCB\xCF\xCA + # Печатать или как есть, или с перекодировкой my $o = ($InCharset eq $OutCharset) ? $output_stack[TOP] : recode_string( $output_stack[TOP]); print $o; @@ -1252,7 +1202,6 @@ } use constant PARSE_START_END => 0; - sub parse_start { my $self = shift; @@ -1261,10 +1210,12 @@ %fonttbl = (); %colortbl = (); %stylesheet = (); - - set_input_charset($self->{StrictInputCharset} || $self->{InputCharset}); - set_output_charset($self->{OutputCharset}); - make_direct_map(); + $InCharset = $self->{StrictInputCharset} || $self->{InputCharset}; + $OutCharset = $self->{OutputCharset}; + +# set_input_charset($self->{StrictInputCharset} || $self->{InputCharset}); +# set_output_charset($self->{OutputCharset}); +# make_direct_map(); push_output(); if (defined (my $action = $do_on_event{'document'})) { $event = 'start'; @@ -1273,7 +1224,6 @@ flush_top_output(); push_output(); } - sub parse_end { my $self = shift; my $action = ''; Modified: trunk/fb2-perl-tools/RTF/HTML/ansi =================================================================== --- trunk/fb2-perl-tools/RTF/HTML/ansi 2007-09-04 12:09:14 UTC (rev 50) +++ trunk/fb2-perl-tools/RTF/HTML/ansi 2007-09-04 12:11:02 UTC (rev 51) @@ -25,8 +25,8 @@ 93 `` 94 '' 95 · -96 - -97 -- +96 – +97 — 98 ~ 99 [tm] 9a s Modified: trunk/fb2-perl-tools/rtf2html =================================================================== --- trunk/fb2-perl-tools/rtf2html 2007-09-04 12:09:14 UTC (rev 50) +++ trunk/fb2-perl-tools/rtf2html 2007-09-04 12:11:02 UTC (rev 51) @@ -74,13 +74,8 @@ =cut require 5.004; -use lib qw(/cmw/perllib /cmw/perllib/i386-linux-thread-multi); use strict; -BEGIN { - delete $ENV{MOD_PERL}; -}; - use File::Basename; use Getopt::Long; @@ -134,16 +129,17 @@ $opt{tables} and $par{CatdocCharsets} = $opt{tables}; -if (defined $par{OutputCharset} && !-f "$par{CatdocCharsets}/$par{OutputCharset}.txt") { - open F, "$par{CatdocCharsets}/charset.map" or die "$par{CatdocCharsets}/charset.map:$!"; - while (<F>) { - next if /^\s*#/ || /^\s*$/; - my ($mime_name,$table_name) = split; - $par{OutputCharset}=$table_name if $mime_name eq $par{OutputCharset}; - } -} +#if (defined $par{OutputCharset} && !-f "$par{CatdocCharsets}/$par{OutputCharset}.txt") { +# open F, "$par{CatdocCharsets}/charset.map" or die "$par{CatdocCharsets}/charset.map:$!"; +# while (<F>) { +# next if /^\s*#/ || /^\s*$/; +# my ($mime_name,$table_name) = split; +# $par{OutputCharset}=$table_name if $mime_name eq $par{OutputCharset}; +# } +# } -die "Unknown output charset $par{OutputCharset}" if $par{OutputCharset} && ! -f "$par{CatdocCharsets}/$par{OutputCharset}.txt"; +# die "Unknown output charset $par{OutputCharset}" if $par{OutputCharset} && ! -f "$par{CatdocCharsets}/$par{OutputCharset}.txt"; + unless (defined $ARGV[0]) { # stdin -> stdout $cnv = new RTF::HTML::Converter(%par); @@ -163,8 +159,8 @@ } -# \xF0\xD2\xC5\xCF\xC2\xD2\xC1\xDA\xCF\xD7\xC1\xCE\xC9\xC5 \xCB\xC1\xD2\xD4\xC9\xCE\xCF\xCB - \xD4\xCF\xCC\xD8\xCB\xCF \xC5\xD3\xCC\xC9 \xC9\xC8 \xCB\xCF\xCE\xD7\xC5\xD2\xD4\xC1\xC3\xC9\xD1 \xD0\xCF\xC4\xC4\xC5\xD2\xD6\xC9\xD7\xC1\xC5\xD4\xD3\xD1 \xD7 \xD4\xC5\xCB\xD5\xDD\xC5\xCA -# \xCB\xCF\xCE\xC6\xC9\xC7\xD5\xD2\xC1\xC3\xC9\xC9 +# Преобразование картинок - только если их конвертация поддерживается в текущей +# конфигурации if ($par{ImageDir} ne 'NONE') { my %job = $cnv->files2convert(); @@ -173,7 +169,7 @@ next unless $to =~ /\.png$/; die "No source file $from" unless -f $from; - # \xF5\xC4\xC1\xCC\xD1\xC5\xCD dst + # Удаляем dst unlink $to; die "Dst file $to cannot be deleted before converting" if -f $to; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2007-08-11 09:23:37
|
Revision: 49 http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=49&view=rev Author: shaplov Date: 2007-08-11 02:23:36 -0700 (Sat, 11 Aug 2007) Log Message: ----------- Oups... should be <body name="notes">, not <body type="note">. One shuold drink less beer before coding ;-) Modified Paths: -------------- trunk/fb2-perl-tools/fb2/Footnotes.pm Modified: trunk/fb2-perl-tools/fb2/Footnotes.pm =================================================================== --- trunk/fb2-perl-tools/fb2/Footnotes.pm 2007-08-09 20:20:29 UTC (rev 48) +++ trunk/fb2-perl-tools/fb2/Footnotes.pm 2007-08-11 09:23:36 UTC (rev 49) @@ -146,7 +146,7 @@ my $node = $_; foreach ($node->attributes()) { - if ( ($_->nodeName eq 'type') && ($_->value eq 'note')) + if ( ($_->nodeName eq 'name') && ($_->value eq 'notes')) { # It's assumed that there is only one note-body in the book $note_body = $node; @@ -156,7 +156,7 @@ if (! $note_body) { $note_body = $doc->createElement('body'); - $note_body->setAttribute('type','note'); + $note_body->setAttribute('name','notes'); $book->appendChild($doc->createTextNode(' ')); $book->appendChild($note_body); $book->appendChild($doc->createTextNode("\n")); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2007-08-09 20:20:31
|
Revision: 48 http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=48&view=rev Author: shaplov Date: 2007-08-09 13:20:29 -0700 (Thu, 09 Aug 2007) Log Message: ----------- Move from XML::DOM to XML::LibXML, and some more fixes... Modified Paths: -------------- trunk/fb2-perl-tools/fb2/Description/Extend.pm Added Paths: ----------- trunk/fb2-perl-tools/fb2_descr Removed Paths: ------------- trunk/fb2-perl-tools/fb2_descr_extend.pl Modified: trunk/fb2-perl-tools/fb2/Description/Extend.pm =================================================================== --- trunk/fb2-perl-tools/fb2/Description/Extend.pm 2007-08-08 14:51:24 UTC (rev 47) +++ trunk/fb2-perl-tools/fb2/Description/Extend.pm 2007-08-09 20:20:29 UTC (rev 48) @@ -1,7 +1,9 @@ package fb2::Description::Extend; use strict; -use XML::DOM; +use XML::LibXML; +use XML::LibXML::Common; +our $VERSION=0.02; =head2 extend @@ -110,7 +112,7 @@ my $par=shift; my $node=shift; - my $name=$node->getNodeName(); + my $name=$node->nodeName(); my $doc=$node->getOwnerDocument; my $children_info=_get_node_children_info($name); @@ -126,11 +128,11 @@ foreach my $child ($node->getChildNodes) # Loops all child nodes { - if ($child->getNodeType == ELEMENT_NODE) # When element node is found + if ($child->nodeType == ELEMENT_NODE()) # When element node is found { - my $num = $name_to_num{$child->getNodeName}; # Get it's number in children_info array - die "Node '".$child->getNodeName."' is not allowed inside '".$node->getNodeName."'" unless defined $num; - die "Invalid child node order inside '".$node->getNodeName."'" if $num<$last_processed_child_num; + my $num = $name_to_num{$child->nodeName}; # Get it's number in children_info array + die "Node '".$child->nodeName."' is not allowed inside '".$node->nodeName."'" unless defined $num; + die "Invalid child node order inside '".$node->nodeName."'" if $num<$last_processed_child_num; for(my $i=$last_processed_child_num+1;$i<$num;$i++) # If there shuld be children between { # current child and last processed @@ -175,13 +177,13 @@ } } - if ($node->getFirstChild && $node->getFirstChild->getNodeType == ELEMENT_NODE) # If first node is element_node + if ($node->getFirstChild && $node->getFirstChild->nodeType == ELEMENT_NODE) # If first node is element_node { # then add an offset, for better view my $offset_node = $doc->createTextNode("\n".(' ' x $par->{'offset'})); $node->insertBefore($offset_node,$node->getFirstChild); } - if ($node->getLastChild && $node->getLastChild->getNodeType == ELEMENT_NODE) # If last node is element_node + if ($node->getLastChild && $node->getLastChild->nodeType == ELEMENT_NODE) # If last node is element_node { # then add an offset, for better view my $offset_node = $doc->createTextNode("\n".(' ' x ($par->{'offset'} - $par->{'offset_step'}))); $node->appendChild($offset_node); Copied: trunk/fb2-perl-tools/fb2_descr (from rev 47, trunk/fb2-perl-tools/fb2_descr_extend.pl) =================================================================== --- trunk/fb2-perl-tools/fb2_descr (rev 0) +++ trunk/fb2-perl-tools/fb2_descr 2007-08-09 20:20:29 UTC (rev 48) @@ -0,0 +1,103 @@ +#!/usr/bin/perl + +use fb2::Description::Extend; +use XML::LibXML; +use Encode; +use Getopt::Long qw(HelpMessage VersionMessage); + +use strict; +our $VERSION=0.02; + +=head1 NAME + +fb2_descr - extend description of fb2 file with all possible elements + +=head1 SYNOPSIS + +B<fb2_descr.pl> extend I<filename.fb2> + +=cut + + +my $Command = shift @ARGV; + +do_extend() if $Command eq 'extend'; +HelpMessage() if ! $Command || $Command eq 'help'; + +exit; + + + +sub do_extend +{ + my $opts={}; + GetOptions( + help => sub {HelpMessage(); }, + version => sub {VersionMessage(); }, +# "keyword|w=s" => \$opts->{'keyword'}, +# "use-number|n" => \$opts->{'use_number'}, + ); + my $file_name = $ARGV[0]; + my $doc; + + if ($file_name) + { + $doc = _parse_file($file_name); + } else + { + $doc = _parse_stdin(); + } + + my ($desc) = $doc->getElementsByTagName("description",0); + fb2::Description::Extend::extend({'description'=>$desc}); + +# if (! $changes_flag ) +# { +# print STDERR "No changes were made\n"; +# return 0 unless $changes_flag; +# } + + if ($file_name) + { + _update_file($file_name,$doc); + } else + { + print $doc->toString(); + } + + print STDERR "Description successfully extended\n"; + +} + +sub _parse_file +{ + my $file_name=shift; + my $parser = XML::LibXML->new(); + + my $doc = $parser->parse_file($file_name); + return $doc; +} + +sub _parse_stdin +{ + my $parser = XML::LibXML->new(); + my $doc = $parser->parse_fh(\*STDIN); + return $doc; +} + +sub _update_file +{ + my $file_name = shift; + my $doc = shift; + + my $backup = $file_name . "~"; + unlink $backup; + rename $file_name, $backup or die("Cannot make backup copy: $!"); + my $encoding=$doc->encoding(); + # This call of Encode::decode fixes problem in XML::DOM which do not + # mark entire output utf8 correctly. + my $data = decode("utf8",$doc->toString); + open DST,">:encoding($encoding)",$file_name; + print DST $data; + close DST; +} \ No newline at end of file Deleted: trunk/fb2-perl-tools/fb2_descr_extend.pl =================================================================== --- trunk/fb2-perl-tools/fb2_descr_extend.pl 2007-08-08 14:51:24 UTC (rev 47) +++ trunk/fb2-perl-tools/fb2_descr_extend.pl 2007-08-09 20:20:29 UTC (rev 48) @@ -1,44 +0,0 @@ -#!/usr/bin/perl - -use fb2::Description::Extend; -use XML::DOM; -use Encode; -use strict; -our $VERSION=0.01; - -=head1 NAME - -fb2_descr_extend.pl - extend description of fb2 file with all possible elements - -=head1 SYNOPSIS - -B<fix_descr.pl> I<filename.fb2> - -=cut - -my $file_name = $ARGV[0]; - -my $parser = new XML::DOM::Parser; - -my $doc = $parser->parsefile($file_name); -my $root = $doc->getDocumentElement(); - - -my ($desc) = $root->getElementsByTagName("description",0); - -fb2::Description::Extend::extend({'description'=>$desc}); - - -my $backup = $file_name . "~"; -unlink $backup; -rename $file_name, $backup or warn("Cannot make backup copy: $!"); -my $encoding=$doc->getXMLDecl()->getEncoding(); - -# This call of Encode::decode fixes problem in XML::DOM which do not -# mark entire output utf8 correctly. -my $data = decode("utf8",$doc->toString); -open DST,">:encoding($encoding)",$file_name; -print DST $data; -close DST; - -print "All OK\n"; \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2007-08-08 14:51:31
|
Revision: 47 http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=47&view=rev Author: shaplov Date: 2007-08-08 07:51:24 -0700 (Wed, 08 Aug 2007) Log Message: ----------- Copyright notice added to fb2_docbook Modified Paths: -------------- trunk/fb2-perl-tools/xslt/fb2docbook.xsl trunk/fb2-perl-tools/xslt/fb2docbook_gen_infos.xsl trunk/fb2-perl-tools/xslt/l10n/en.xml trunk/fb2-perl-tools/xslt/l10n/gentext.xsl trunk/fb2-perl-tools/xslt/l10n/l10n.xml trunk/fb2-perl-tools/xslt/l10n/ru.xml trunk/fb2-perl-tools/xslt/params/system_params.xsl Modified: trunk/fb2-perl-tools/xslt/fb2docbook.xsl =================================================================== --- trunk/fb2-perl-tools/xslt/fb2docbook.xsl 2007-08-08 14:34:35 UTC (rev 46) +++ trunk/fb2-perl-tools/xslt/fb2docbook.xsl 2007-08-08 14:51:24 UTC (rev 47) @@ -1,4 +1,14 @@ <?xml version="1.0" encoding="UTF-8"?> +<!-- + +Copyright 2007 by KiR Jakobson ( http://kir666.ru/fb2docbook/ ) + +This library is free software; you can redistribute it and/or modify +it under the terms of the General Public License (GPL). For +more information, see http://www.fsf.org/licenses/gpl.txt + +--> + <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:fb="http://www.gribuser.ru/xml/fictionbook/2.0" xmlns:exsl="http://exslt.org/common" xmlns:redirect="http://xml.apache.org/xalan/redirect" Modified: trunk/fb2-perl-tools/xslt/fb2docbook_gen_infos.xsl =================================================================== --- trunk/fb2-perl-tools/xslt/fb2docbook_gen_infos.xsl 2007-08-08 14:34:35 UTC (rev 46) +++ trunk/fb2-perl-tools/xslt/fb2docbook_gen_infos.xsl 2007-08-08 14:51:24 UTC (rev 47) @@ -1,4 +1,14 @@ <?xml version="1.0" encoding="UTF-8"?> +<!-- + +Copyright 2007 by KiR Jakobson ( http://kir666.ru/fb2docbook/ ) + +This library is free software; you can redistribute it and/or modify +it under the terms of the General Public License (GPL). For +more information, see http://www.fsf.org/licenses/gpl.txt + +--> + <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:fb="http://www.gribuser.ru/xml/fictionbook/2.0" xmlns:exsl="http://exslt.org/common" xmlns:redirect="http://xml.apache.org/xalan/redirect" Modified: trunk/fb2-perl-tools/xslt/l10n/en.xml =================================================================== --- trunk/fb2-perl-tools/xslt/l10n/en.xml 2007-08-08 14:34:35 UTC (rev 46) +++ trunk/fb2-perl-tools/xslt/l10n/en.xml 2007-08-08 14:51:24 UTC (rev 47) @@ -1,4 +1,14 @@ <?xml version="1.0" encoding="UTF-8"?> +<!-- + +Copyright 2007 by KiR Jakobson ( http://kir666.ru/fb2docbook/ ) + +This library is free software; you can redistribute it and/or modify +it under the terms of the General Public License (GPL). For +more information, see http://www.fsf.org/licenses/gpl.txt + +--> + <l10n language="en" english-language-name="English"> <param name="SeeAbr" text="See"/> <param name="seeabr" text="see"/> Modified: trunk/fb2-perl-tools/xslt/l10n/gentext.xsl =================================================================== --- trunk/fb2-perl-tools/xslt/l10n/gentext.xsl 2007-08-08 14:34:35 UTC (rev 46) +++ trunk/fb2-perl-tools/xslt/l10n/gentext.xsl 2007-08-08 14:51:24 UTC (rev 47) @@ -1,4 +1,14 @@ <?xml version="1.0" encoding="UTF-8"?> +<!-- + +Copyright 2007 by KiR Jakobson ( http://kir666.ru/fb2docbook/ ) + +This library is free software; you can redistribute it and/or modify +it under the terms of the General Public License (GPL). For +more information, see http://www.fsf.org/licenses/gpl.txt + +--> + <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:fb="http://www.gribuser.ru/xml/fictionbook/2.0"> <xsl:param name="l10n.xml" select="document('l10n.xml')"/> Modified: trunk/fb2-perl-tools/xslt/l10n/l10n.xml =================================================================== --- trunk/fb2-perl-tools/xslt/l10n/l10n.xml 2007-08-08 14:34:35 UTC (rev 46) +++ trunk/fb2-perl-tools/xslt/l10n/l10n.xml 2007-08-08 14:51:24 UTC (rev 47) @@ -1,4 +1,14 @@ <?xml version='1.0' encoding="UTF-8"?> +<!-- + +Copyright 2007 by KiR Jakobson ( http://kir666.ru/fb2docbook/ ) + +This library is free software; you can redistribute it and/or modify +it under the terms of the General Public License (GPL). For +more information, see http://www.fsf.org/licenses/gpl.txt + +--> + <!DOCTYPE i18n SYSTEM "l10n.dtd" [ <!ENTITY en SYSTEM "en.xml"> <!ENTITY ru SYSTEM "ru.xml"> Modified: trunk/fb2-perl-tools/xslt/l10n/ru.xml =================================================================== --- trunk/fb2-perl-tools/xslt/l10n/ru.xml 2007-08-08 14:34:35 UTC (rev 46) +++ trunk/fb2-perl-tools/xslt/l10n/ru.xml 2007-08-08 14:51:24 UTC (rev 47) @@ -1,4 +1,14 @@ <?xml version="1.0" encoding="UTF-8"?> +<!-- + +Copyright 2007 by KiR Jakobson ( http://kir666.ru/fb2docbook/ ) + +This library is free software; you can redistribute it and/or modify +it under the terms of the General Public License (GPL). For +more information, see http://www.fsf.org/licenses/gpl.txt + +--> + <l10n language="ru" english-language-name="Russian"> <param name="SeeAbr" text="См."/> <param name="seeabr" text="см."/> Modified: trunk/fb2-perl-tools/xslt/params/system_params.xsl =================================================================== --- trunk/fb2-perl-tools/xslt/params/system_params.xsl 2007-08-08 14:34:35 UTC (rev 46) +++ trunk/fb2-perl-tools/xslt/params/system_params.xsl 2007-08-08 14:51:24 UTC (rev 47) @@ -1,4 +1,14 @@ <?xml version="1.0" encoding="UTF-8"?> +<!-- + +Copyright 2007 by KiR Jakobson ( http://kir666.ru/fb2docbook/ ) + +This library is free software; you can redistribute it and/or modify +it under the terms of the General Public License (GPL). For +more information, see http://www.fsf.org/licenses/gpl.txt + +--> + <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.1"> <xsl:variable name="fb2.mime-types"> <mime-type id="image/jpeg" docbook-format="JPEG"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2007-08-08 14:34:42
|
Revision: 46 http://fb2-perl-tools.svn.sourceforge.net/fb2-perl-tools/?rev=46&view=rev Author: shaplov Date: 2007-08-08 07:34:35 -0700 (Wed, 08 Aug 2007) Log Message: ----------- An XSLT transformation fb2_to_docbook by KiR Jakobson Someone should later write perl warp... Added Paths: ----------- trunk/fb2-perl-tools/xslt/ trunk/fb2-perl-tools/xslt/fb2docbook.xsl trunk/fb2-perl-tools/xslt/fb2docbook_gen_infos.xsl trunk/fb2-perl-tools/xslt/l10n/ trunk/fb2-perl-tools/xslt/l10n/en.xml trunk/fb2-perl-tools/xslt/l10n/gentext.xsl trunk/fb2-perl-tools/xslt/l10n/l10n.dtd trunk/fb2-perl-tools/xslt/l10n/l10n.xml trunk/fb2-perl-tools/xslt/l10n/ru.xml trunk/fb2-perl-tools/xslt/params/ trunk/fb2-perl-tools/xslt/params/system_params.xsl Added: trunk/fb2-perl-tools/xslt/fb2docbook.xsl =================================================================== --- trunk/fb2-perl-tools/xslt/fb2docbook.xsl (rev 0) +++ trunk/fb2-perl-tools/xslt/fb2docbook.xsl 2007-08-08 14:34:35 UTC (rev 46) @@ -0,0 +1,800 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:fb="http://www.gribuser.ru/xml/fictionbook/2.0" + xmlns:exsl="http://exslt.org/common" xmlns:redirect="http://xml.apache.org/xalan/redirect" + extension-element-prefixes="exsl redirect" exclude-result-prefixes="fb exsl redirect xlink" + version="1.1"> + <xsl:import href="params/system_params.xsl"/> + <xsl:import href="l10n/gentext.xsl"/> + <xsl:import href="fb2docbook_gen_infos.xsl"/> + <xsl:param name="conv_info_idx"/> + <xsl:param name="document-element"/> + <xsl:output encoding="UTF-8" indent="yes" method="xml" + doctype-system="http://www.docbook.org/xml/4.4/docbookx.dtd" + doctype-public="-//OASIS//DTD DocBook XML V4.4//EN"/> + <xsl:key name="note-link" match="fb:section" use="@id"/> + <xsl:key name="binary-link" match="fb:binary" use="@id"/> + <xsl:template name="gen_binary_asciiname"> + <xsl:param name="bin_href"/> + <xsl:value-of select="concat($bin_href, '.base64')"/> + </xsl:template> + <xsl:template name="gen_fname"> + <xsl:param name="href"/> + <xsl:choose> + <xsl:when test="starts-with($href,'#')"> + <xsl:value-of select="substring-after($href,'#')"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$href"/> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + <xsl:template name="get_docbook_format"> + <xsl:param name="content-type"/> + <xsl:value-of + select="exsl:node-set($fb2.mime-types)/mime-type[@id=$content-type]/@docbook-format"/> + </xsl:template> + <xsl:template name="get_part_name"> + <xsl:param name="level"/> + <xsl:variable name="num_levels" select="count(exsl:node-set($fb2.book-parts)/part)"/> + <xsl:choose> + <xsl:when test="$level > 0 and $level < $num_levels"> + <xsl:value-of + select="exsl:node-set($fb2.book-parts)/part[@level=string($level)]/@name"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="exsl:node-set($fb2.book-parts)/part[last()]/@name"/> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + <xsl:template name="get_part_intro_name"> + <xsl:param name="level"/> + <xsl:variable name="num_levels" select="count(exsl:node-set($fb2.book-parts)/part)"/> + <xsl:choose> + <xsl:when test="$level > 0 and $level < $num_levels"> + <xsl:value-of + select="exsl:node-set($fb2.book-parts)/part[@level=string($level)]/@intro-name" + /> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="exsl:node-set($fb2.book-parts)/part[last()]/@intro-name"/> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + <xsl:template match="fb:FictionBook"> + <xsl:variable name="blang"> + <xsl:choose> + <xsl:when test="fb:description/fb:title-info/fb:lang/text() != ''"> + <xsl:value-of select="fb:description/fb:title-info/fb:lang/text()"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$fb2.default.language"/> + </xsl:otherwise> + </xsl:choose> + </xsl:variable> + <book xml:lang="{$blang}"> + <xsl:for-each select="fb:description"> + <xsl:call-template name="bookinfo"/> + </xsl:for-each> + <xsl:apply-templates select="fb:body[not (@name = 'notes' or @name = 'footnotes')]"/> + + <xsl:if test="$fb2.print.infos"> + <xsl:call-template name="title-info-appendix"/> + <xsl:call-template name="src-title-info-appendix"/> + <xsl:call-template name="document-info-appendix"/> + <xsl:call-template name="publish-info-appendix"/> + <xsl:call-template name="custom-info-appendix"/> + <xsl:call-template name="technical-appendix"/> + </xsl:if> + + <xsl:call-template name="binaries_index"> + <xsl:with-param name="idx_fname"> + <xsl:value-of select="$conv_info_idx"/> + </xsl:with-param> + </xsl:call-template> + <xsl:apply-templates select="fb:binary"/> + <!--xsl:apply-templates select="fb:body[(@name = 'notes')]"/--> + </book> + </xsl:template> + <xsl:template name="bookinfo"> + <bookinfo> + <xsl:if test="count(fb:title-info/fb:coverpage|fb:title-info/fb:annotation)"> + <abstract id="preface_annotation" xml:lang="{fb:title-info/fb:lang/text()}"> + <para> + <xsl:apply-templates select="fb:title-info/fb:coverpage/fb:image"/> + </para> + <xsl:for-each select="fb:title-info/fb:annotation/*"> + <xsl:choose> + <xsl:when + test="local-name(.) = 'cite' or local-name(.) = 'empty-line' or local-name(.) = 'table'"> + <para> + <xsl:apply-templates select="."/> + </para> + </xsl:when> + <xsl:otherwise> + <xsl:apply-templates select="."/> + </xsl:otherwise> + </xsl:choose> + </xsl:for-each> + </abstract> + </xsl:if> + <xsl:if test="count(fb:src-title-info/fb:coverpage|fb:src-title-info/fb:annotation)"> + <abstract id="preface_annotation_original" + xml:lang="{fb:src-title-info/fb:lang/text()}"> + <para> + <xsl:apply-templates select="fb:src-title-info/fb:coverpage/fb:image"/> + </para> + <xsl:for-each select="fb:src-title-info/fb:annotation/*"> + <xsl:choose> + <xsl:when + test="local-name(.) = 'cite' or local-name(.) = 'empty-line' or local-name(.) = 'table'"> + <para> + <xsl:apply-templates select="."/> + </para> + </xsl:when> + <xsl:otherwise> + <xsl:apply-templates select="."/> + </xsl:otherwise> + </xsl:choose> + </xsl:for-each> + <!--xsl:apply-templates select="fb:src-title-info/fb:annotation/*"/--> + </abstract> + </xsl:if> + <title> + <xsl:value-of select="fb:title-info/fb:book-title"/> + </title> + <xsl:choose> + <xsl:when test="count(fb:title-info/fb:author) > 1"> + <authorgroup> + <xsl:apply-templates select="fb:title-info/fb:author" mode="bookinfo"/> + </authorgroup> + </xsl:when> + <xsl:otherwise> + <xsl:apply-templates select="fb:title-info/fb:author" mode="bookinfo"/> + </xsl:otherwise> + </xsl:choose> + <xsl:apply-templates select="fb:title-info/fb:translator" mode="bookinfo"/> + <xsl:call-template name="bookinfo-sequence"/> + <xsl:call-template name="bookinfo-date"/> + <xsl:call-template name="bookinfo-publish"/> + </bookinfo> + </xsl:template> + <xsl:template name="bookinfo-publish"> + <xsl:if test="count(fb:publish-info/fb:publisher)"> + <publishername> + <xsl:value-of select="fb:publish-info/fb:publisher/text()"/> + </publishername> + </xsl:if> + <xsl:if test="count(fb:publish-info/fb:isbn)"> + <bibliosource class="isbn"> + <xsl:value-of select="fb:publish-info/fb:isbn/text()"/> + </bibliosource> + </xsl:if> + <xsl:if test="count(fb:publish-info/fb:year)"> + <pubdate> + <xsl:value-of select="fb:publish-info/fb:year/text()"/> + </pubdate> + </xsl:if> + </xsl:template> + <xsl:template name="bookinfo-date"> + <date> + <xsl:choose> + <xsl:when test="fb:title-info/fb:date/text() = ''"> + <xsl:value-of select="fb:title-info/fb:date/@value"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="fb:title-info/fb:date/text()"/> + </xsl:otherwise> + </xsl:choose> + </date> + </xsl:template> + <xsl:template name="bookinfo-sequence"> + <xsl:if test="count(fb:title-info/fb:sequence)"> + <seriesvolnums> + <xsl:value-of select="fb:title-info/fb:sequence/@name"/> + </seriesvolnums> + <volumenum> + <xsl:value-of select="fb:title-info/fb:sequence/@number"/> + </volumenum> + </xsl:if> + </xsl:template> + <xsl:template match="fb:body"> + <xsl:apply-templates select="@xml:lang|@id"/> + <xsl:if test="count(fb:image) or count(fb:epigraph)"> + <preface id="{concat('preface_preface', generate-id())}"> + <title id="{concat('prefacetitle', generate-id())}"> + <xsl:call-template name="gentext.param"> + <xsl:with-param name="param" select="'Preface'"/> + </xsl:call-template> + </title> + <xsl:apply-templates select="fb:image"/> + <xsl:apply-templates select="fb:epigraph"/> + </preface> + </xsl:if> + <xsl:for-each select="fb:section"> + <xsl:call-template name="fb-section"> + <xsl:with-param name="level" select="1"/> + </xsl:call-template> + </xsl:for-each> + </xsl:template> + <xsl:template name="fb-section"> + <xsl:param name="level"/> + <xsl:variable name="part-name"> + <xsl:call-template name="get_part_name"> + <xsl:with-param name="level" select="$level"/> + </xsl:call-template> + </xsl:variable> + <xsl:variable name="part-intro-name"> + <xsl:call-template name="get_part_intro_name"> + <xsl:with-param name="level" select="$level"/> + </xsl:call-template> + </xsl:variable> + <xsl:element name="{$part-name}"> + <xsl:apply-templates select="@xml:lang|@id"/> + <xsl:call-template name="section_title"/> + <xsl:choose> + <!-- если нет section в part, не загонять все в partintro; пустой partintro !!! --> + <xsl:when test="$part-intro-name != ''"> + <xsl:element name="{$part-intro-name}"> + <xsl:apply-templates + select="*[local-name(.) != 'section' and local-name(.) != 'title']"/> + </xsl:element> + </xsl:when> + <xsl:otherwise> + <xsl:apply-templates + select="*[local-name(.) != 'section' and local-name(.) != 'title']"/> + </xsl:otherwise> + </xsl:choose> + <xsl:for-each select="fb:section"> + <xsl:call-template name="fb-section"> + <xsl:with-param name="level" select="$level + 1"/> + </xsl:call-template> + </xsl:for-each> + </xsl:element> + </xsl:template> + <xsl:template name="section_title"> + <xsl:param name="role" select="''"/> + <title> + <xsl:if test="$role != ''"> + <xsl:attribute name="role"> + <xsl:value-of select="$role"/> + </xsl:attribute> + </xsl:if> + <xsl:for-each select="fb:title/fb:p"> + <xsl:apply-templates/> + <xsl:text xml:space="preserve"> </xsl:text> + </xsl:for-each> + </title> + </xsl:template> + <xsl:template match="fb:p"> + <para> + <xsl:if test="local-name(..) = 'section'"> + <xsl:attribute name="role">p</xsl:attribute> + </xsl:if> + <xsl:apply-templates select="@xml:lang|@id"/> + <xsl:apply-templates/> + </para> + </xsl:template> + <xsl:template match="fb:p" mode="epigraph"> + <para role="epigraph"> + <xsl:apply-templates select="@xml:lang|@id"/> + <xsl:apply-templates/> + </para> + </xsl:template> + <!--xsl:template match="fb:epigraph"> + <xsl:element name="epigraph"> + <xsl:apply-templates select="@xml:lang|@id"/> + <xsl:if test="count(fb:text-author) != 0"> + <attribution> + <xsl:apply-templates select="fb:text-author"/> + </attribution> + </xsl:if> + <xsl:apply-templates select="fb:p|fb:poem|fb:cite|fb:empty-line" mode="epigraph"/> + </xsl:element> + </xsl:template--> + <xsl:template match="fb:epigraph"> + <xsl:element name="blockquote"> + <xsl:apply-templates select="@xml:lang|@id"/> + <xsl:if test="count(fb:text-author) != 0"> + <attribution> + <xsl:apply-templates select="fb:text-author"/> + </attribution> + </xsl:if> + <xsl:apply-templates select="*[local-name(.) != 'text-author']"/> + </xsl:element> + </xsl:template> + <xsl:template match="fb:empty-line" name="empty-line"> + <literallayout/> + </xsl:template> + <xsl:template match="fb:empty-line" mode="epigraph"> + <xsl:call-template name="empty-line"/> + </xsl:template> + <xsl:template match="fb:a"> + <xsl:variable name="href_id"> + <xsl:call-template name="gen_fname"> + <xsl:with-param name="href" select="@xlink:href"/> + </xsl:call-template> + </xsl:variable> + <xsl:choose> + <xsl:when test="@type = 'note'"> + <xsl:call-template name="a_footnote"> + <xsl:with-param name="href_id" select="$href_id"/> + <xsl:with-param name="label" select="text()"/> + </xsl:call-template> + </xsl:when> + <xsl:when test="starts-with($href_id,'#')"> + <xsl:call-template name="a_xref"> + <xsl:with-param name="href_id" select="$href_id"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise> + <xsl:call-template name="a_ulink"> + <xsl:with-param name="href_id" select="$href_id"/> + </xsl:call-template> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + <xsl:template name="a_footnote"> + <xsl:param name="href_id"/> + <xsl:param name="label"/> + <xsl:element name="footnote"> + <xsl:attribute name="id"> + <xsl:value-of select="$href_id"/> + </xsl:attribute> + <xsl:for-each select="key('note-link', $href_id)"> + <!-- == work for XEP, in FOP only work labels without spaces == --> + <!--xsl:attribute name="label"> + <xsl:choose> + <xsl:when test="$label = ''"> + <xsl:value-of select="fb:title/fb:p/text()"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$label"/> + </xsl:otherwise> + </xsl:choose> + </xsl:attribute--> + <xsl:apply-templates select="fb:p"/> + </xsl:for-each> + <xsl:if test="count(key('note-link', $href_id)) = 0"> + <xsl:message> Footnote body not found <xsl:value-of select="$href_id"/>!</xsl:message> + <para> + <xsl:call-template name="gentext.param"> + <xsl:with-param name="param" select="'error.bad.note'"/> + </xsl:call-template> + <xsl:value-of select="$href_id"/> + <xsl:text>!</xsl:text> + </para> + </xsl:if> + </xsl:element> + </xsl:template> + <xsl:template name="a_ulink"> + <xsl:param name="href_id"/> + <ulink url="{$href_id}"> + <xsl:if test="@xlink:type != ''"> + <xsl:attribute name="xlink:type"> + <xsl:value-of select="@xlink:type"/> + </xsl:attribute> + </xsl:if> + <xsl:apply-templates/> + </ulink> + </xsl:template> + <xsl:template name="a_xref"> + <xsl:param name="href_id"/> + <xref linkend="{$href_id}"/> + </xsl:template> + <xsl:template name="metadata_author"> + <xsl:choose> + <xsl:when test="count(fb:nickname) and count(fb:first-name) = 0"> + <xsl:value-of select="fb:nickname"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="fb:first-name"/> + <xsl:if test="count(fb:middle-name)"> + <xsl:text> </xsl:text> + <xsl:value-of select="fb:middle-name"/> + </xsl:if> + <xsl:text> </xsl:text> + <xsl:value-of select="fb:last-name"/> + <xsl:if test="count(fb:nickname)"> + <xsl:text> "</xsl:text> + <xsl:value-of select="fb:nickname"/> + <xsl:text>"</xsl:text> + </xsl:if> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + <xsl:template name="write_binaries_tree"> + <conversion_info> + <page> + <dpi> + <width><xsl:value-of select="$output.dpi.width"/></width> + <height><xsl:value-of select="$output.dpi.height"/></height> + </dpi> + <size> + <width><xsl:value-of select="$page.width"/></width> + <height><xsl:value-of select="$page.height"/></height> + </size> + <max_image_margin> + <width><xsl:value-of select="$output.max_image_margin.width"/></width> + <height><xsl:value-of select="$output.max_image_margin.height"/></height> + </max_image_margin> + <images_mode> + <resize><xsl:value-of select="$output.images_mode.resize"/></resize> + <mode><xsl:value-of select="$output.images_mode.mode"/></mode> + </images_mode> + </page> + <metadata> + <Title> + <xsl:value-of select="/fb:FictionBook/fb:description/fb:title-info/fb:book-title"/> + </Title> + <Author> + <xsl:for-each select="/fb:FictionBook/fb:description/fb:title-info/fb:author[position() = 1]"> + <xsl:call-template name="metadata_author"/> + </xsl:for-each> + <xsl:for-each select="/fb:FictionBook/fb:description/fb:title-info/fb:author[position() > 1]"> + <xsl:text>; </xsl:text> + <xsl:call-template name="metadata_author"/> + </xsl:for-each> + </Author> + </metadata> + <binaries> + <xsl:for-each select="fb:binary"> + <xsl:variable name="bin_ascii_name"> + <xsl:call-template name="gen_binary_asciiname"> + <xsl:with-param name="bin_href" select="@id"/> + </xsl:call-template> + </xsl:variable> + <binary href_binary="{@id}" href_ascii="{$bin_ascii_name}" + content-type="{@content-type}"/> + </xsl:for-each> + </binaries> + </conversion_info> + </xsl:template> + <xsl:template name="binaries_index"> + <xsl:param name="idx_fname"/> + <xsl:choose> + <xsl:when test="$document-element = 'exsl:document'"> + <exsl:document href="{$idx_fname}" method="xml" encoding="UTF-8"> + <xsl:call-template name="write_binaries_tree"/> + </exsl:document> + </xsl:when> + <xsl:when test="$document-element = 'xsl:document'"> + <xsl:document href="{$idx_fname}" method="xml" encoding="UTF-8"> + <xsl:call-template name="write_binaries_tree"/> + </xsl:document> + </xsl:when> + <xsl:when test="$document-element = 'redirect:write'"> + <redirect:write file="{$idx_fname}"> + <xsl:call-template name="write_binaries_tree"/> + </redirect:write> + </xsl:when> + <xsl:otherwise> + <xsl:message> Unknown xsl:document element!!! </xsl:message> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + <xsl:template match="fb:binary"> + <xsl:variable name="bin_ascii_name"> + <xsl:call-template name="gen_binary_asciiname"> + <xsl:with-param name="bin_href" select="@id"/> + </xsl:call-template> + </xsl:variable> + <xsl:choose> + <xsl:when test="$document-element = 'exsl:document'"> + <exsl:document href="{$bin_ascii_name}" method="text" indent="no"> + <xsl:value-of select="text()"/> + </exsl:document> + </xsl:when> + <xsl:when test="$document-element = 'xsl:document'"> + <xsl:document href="{$bin_ascii_name}" method="text" indent="no"> + <xsl:value-of select="text()"/> + </xsl:document> + </xsl:when> + <xsl:when test="$document-element = 'redirect:write'"> + <redirect:write file="{$bin_ascii_name}"> + <xsl:value-of select="text()"/> + </redirect:write> + </xsl:when> + <xsl:otherwise> + <xsl:message> Unknown xsl:document element!!! </xsl:message> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + <xsl:template match="fb:image"> + <xsl:variable name="href_id"> + <xsl:call-template name="gen_fname"> + <xsl:with-param name="href" select="@xlink:href"/> + </xsl:call-template> + </xsl:variable> + <xsl:variable name="content-type" select="key('binary-link', $href_id)/@content-type"/> + <xsl:variable name="docbook-format"> + <xsl:call-template name="get_docbook_format"> + <xsl:with-param name="content-type" select="$content-type"/> + </xsl:call-template> + </xsl:variable> + <xsl:variable name="media_element"> + <xsl:choose> + <xsl:when + test="local-name(..) = 'section' or local-name(..) = 'body' or local-name(..) = 'coverpage'" + >mediaobject</xsl:when> + <xsl:otherwise>inlinemediaobject</xsl:otherwise> + </xsl:choose> + + </xsl:variable> + <xsl:element name="{$media_element}"> + <xsl:apply-templates select="@xml:lang|@id"/> + <imageobject> + <imagedata align="{$fb2.image.align}" valign="{$fb2.image.valign}" + fileref="{$href_id}" format="{$docbook-format}"/> + </imageobject> + <xsl:if test="@alt != ''"> + <textobject> + <xsl:value-of select="@alt"/> + </textobject> + </xsl:if> + <xsl:if test="@title != ''"> + <caption> + <para> + <xsl:value-of select="@title"/> + </para> + </caption> + </xsl:if> + </xsl:element> + </xsl:template> + <xsl:template match="fb:emphasis"> + <emphasis> + <xsl:apply-templates/> + </emphasis> + </xsl:template> + <xsl:template match="fb:strong"> + <emphasis role="strong"> + <xsl:apply-templates/> + </emphasis> + </xsl:template> + <xsl:template match="fb:strikethrough"> + <emphasis role="strikethrough"> + <xsl:apply-templates/> + </emphasis> + </xsl:template> + <xsl:template match="fb:sub"> + <subscript> + <xsl:apply-templates/> + </subscript> + </xsl:template> + <xsl:template match="fb:sup"> + <superscript> + <xsl:apply-templates/> + </superscript> + </xsl:template> + <xsl:template match="fb:code"> + <code> + <xsl:apply-templates select="@xml:lang|@id"/> + <xsl:apply-templates/> + </code> + </xsl:template> + <xsl:template match="fb:cite" name="cite"> + <blockquote> + <xsl:apply-templates select="@xml:lang|@id"/> + <xsl:if test="count(fb:text-author) != 0"> + <attribution> + <xsl:apply-templates select="fb:text-author"/> + </attribution> + </xsl:if> + <xsl:apply-templates select="*[local-name(.) != 'text-author']"/> + </blockquote> + </xsl:template> + <xsl:template match="fb:cite" mode="epigraph"> + <xsl:call-template name="cite"/> + </xsl:template> + <xsl:template match="fb:text-author"> + <author> + <personname> + <othername> + <xsl:value-of select="text()"/> + </othername> + </personname> + </author> + </xsl:template> + <xsl:template match="fb:poem" mode="epigraph"> + <xsl:call-template name="poem"/> + </xsl:template> + <xsl:template match="fb:poem" name="poem"> + <xsl:choose> + <xsl:when test="count(fb:title) > 0"> + <formalpara role="poem"> + <xsl:apply-templates select="@xml:lang|@id"/> + <xsl:call-template name="section_title"> + <xsl:with-param name="role" select="'poem'"/> + </xsl:call-template> + <xsl:apply-templates select="fb:epigraph"/> + <para role="poem"> + <xsl:apply-templates select="fb:stanza"/> + <xsl:apply-templates select="fb:text-author"/> + <xsl:apply-templates select="fb:date"/> + </para> + </formalpara> + </xsl:when> + <xsl:otherwise> + <para role="poem"> + <xsl:apply-templates select="@xml:lang|@id"/> + <xsl:apply-templates select="fb:epigraph"/> + <xsl:apply-templates select="fb:stanza"/> + <xsl:apply-templates select="fb:text-author"/> + <xsl:apply-templates select="fb:date"/> + </para> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + <xsl:template match="fb:stanza"> + <xsl:choose> + <xsl:when test="count(fb:title) > 0"> + <formalpara role="poem"> + <xsl:call-template name="section_title"/> + <para role="poem"> + <xsl:apply-templates select="@xml:lang|@id"/> + <literallayout xml:space="preserve" role="poem"> + <xsl:apply-templates select="fb:v"/> + </literallayout> + </para> + </formalpara> + </xsl:when> + <xsl:otherwise> + <literallayout xml:space="preserve" role="poem"><xsl:apply-templates select="@xml:lang|@id"/><xsl:apply-templates select="fb:v"/></literallayout> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + <xsl:template match="fb:v"> + <xsl:choose> + <xsl:when test="local-name(..) = 'stanza'"> + <xsl:apply-templates/> + <xsl:text xml:space="preserve">
</xsl:text> + </xsl:when> + <xsl:otherwise> + <xsl:message> + <xsl:text>Bad parent of tag v (must be stanza)!!!</xsl:text> + </xsl:message> + <simpara> + <literal> + <xsl:apply-templates/> + <xsl:text xml:space="preserve">
</xsl:text> + </literal> + </simpara> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + <xsl:template match="fb:table"> + <informaltable> + <xsl:apply-templates/> + </informaltable> + </xsl:template> + <xsl:template match="fb:tr|fb:th|fb:td"> + <xsl:element name="{local-name(.)}"> + <xsl:apply-templates select="@*"/> + <xsl:apply-templates/> + </xsl:element> + </xsl:template> + <xsl:template match="fb:subtitle"> + <simpara> + <xsl:apply-templates select="@xml:lang|@id"/> + <emphasis role="{$fb2.subtitle.role}"> + <xsl:apply-templates/> + </emphasis> + </simpara> + <xsl:processing-instruction name="dbfo"> + <xsl:text>keep-together="always"</xsl:text> + </xsl:processing-instruction> + </xsl:template> + <xsl:template match="fb:style"> + <xsl:comment> == style <xsl:value-of select="@name"/> == </xsl:comment> + <xsl:choose> + <xsl:when test="@xml:lang != ''"> + <foreignphrase> + <xsl:apply-templates select="@xml:lang"/> + <xsl:apply-templates/> + </foreignphrase> + </xsl:when> + <xsl:otherwise> + <xsl:apply-templates/> + </xsl:otherwise> + </xsl:choose> + <xsl:comment> == style_end <xsl:value-of select="@name"/> == </xsl:comment> + </xsl:template> + <xsl:template name="bookinfo-person"> + <xsl:param name="person-element"/> + <xsl:param name="person-class"/> + <xsl:element name="{$person-element}"> + <xsl:if test="$person-class != ''"> + <xsl:attribute name="class"> + <xsl:value-of select="$person-class"/> + </xsl:attribute> + </xsl:if> + <xsl:apply-templates + select="*[local-name(.) != 'id' and local-name(.) != 'nickname' and local-name(.) != 'home-page' and local-name(.) != 'email']" + mode="description"/> + <xsl:if test="count(fb:first-name) = 0 and count(fb:last-name) = 0"> + <xsl:comment> == Bad author, only nickname! == </xsl:comment> + <surname> + <xsl:value-of select="fb:nickname/text()"/> + </surname> + </xsl:if> + <xsl:call-template name="authorblurb"/> + <xsl:apply-templates select="fb:email" mode="description"/> + </xsl:element> + </xsl:template> + <xsl:template match="fb:author" mode="bookinfo"> + <xsl:call-template name="bookinfo-person"> + <xsl:with-param name="person-element">author</xsl:with-param> + </xsl:call-template> + </xsl:template> + <xsl:template match="fb:translator" mode="bookinfo"> + <xsl:call-template name="bookinfo-person"> + <xsl:with-param name="person-element">othercredit</xsl:with-param> + <xsl:with-param name="person-class">translator</xsl:with-param> + </xsl:call-template> + </xsl:template> + <xsl:template match="fb:first-name" mode="description"> + <firstname> + <xsl:value-of select="text()"/> + </firstname> + </xsl:template> + <xsl:template match="fb:last-name" mode="description"> + <surname> + <xsl:value-of select="text()"/> + </surname> + </xsl:template> + <xsl:template match="fb:middle-name" mode="description"> + <lineage> + <xsl:value-of select="text()"/> + </lineage> + </xsl:template> + <xsl:template match="fb:email" mode="description"> + <email> + <xsl:value-of select="text()"/> + </email> + </xsl:template> + <xsl:template name="authorblurb"> + <xsl:if test="count(fb:nickname) or count(fb:home-page)"> + <authorblurb> + <para> + <itemizedlist spacing="compact"> + <xsl:apply-templates select="fb:nickname|fb:home-page" mode="authorblurb"/> + </itemizedlist> + </para> + </authorblurb> + </xsl:if> + </xsl:template> + <xsl:template match="fb:nickname" mode="authorblurb"> + <listitem> + <simpara> + <xsl:call-template name="gentext.param"> + <xsl:with-param name="param" select="'Nickname'"/> + </xsl:call-template> + <xsl:text>: </xsl:text> + <xsl:value-of select="text()"/> + </simpara> + </listitem> + </xsl:template> + <xsl:template match="fb:home-page" mode="authorblurb"> + <listitem> + <simpara> + <xsl:call-template name="gentext.param"> + <xsl:with-param name="param" select="'Сайт'"/> + </xsl:call-template> + <xsl:text>: </xsl:text> + <ulink url="{text()}"> + <xsl:value-of select="text()"/> + </ulink> + </simpara> + </listitem> + </xsl:template> + + <xsl:template match="@id"> + <xsl:copy/> + </xsl:template> + <xsl:template match="@xml:lang"> + <xsl:copy/> + </xsl:template> + <xsl:template match="@*"> + <xsl:copy/> + </xsl:template> +</xsl:stylesheet> Added: trunk/fb2-perl-tools/xslt/fb2docbook_gen_infos.xsl =================================================================== --- trunk/fb2-perl-tools/xslt/fb2docbook_gen_infos.xsl (rev 0) +++ trunk/fb2-perl-tools/xslt/fb2docbook_gen_infos.xsl 2007-08-08 14:34:35 UTC (rev 46) @@ -0,0 +1,586 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:fb="http://www.gribuser.ru/xml/fictionbook/2.0" + xmlns:exsl="http://exslt.org/common" xmlns:redirect="http://xml.apache.org/xalan/redirect" + extension-element-prefixes="exsl redirect" version="1.1"> + <xsl:import href="l10n/gentext.xsl"/> + <xsl:template name="technical-appendix"> + <appendix id="{concat('tappendix', generate-id())}"> + <title id="{concat('tappendix_title', generate-id())}"> + <xsl:call-template name="gentext.info.title"> + <xsl:with-param name="context" select="'technical-appendix'"/> + </xsl:call-template> + </title> + <para> + <xsl:call-template name="gentext.info.param"> + <xsl:with-param name="context" select="'technical-appendix'"/> + <xsl:with-param name="param" select="'xslt.processor'"/> + </xsl:call-template> + <xsl:text>: </xsl:text> + <ulink url="{system-property('xsl:vendor-url')}"> + <xsl:value-of select="system-property('xsl:vendor')"/> + </ulink> (XSLT version <xsl:value-of select="system-property('xsl:version')"/>). + </para> + </appendix> + </xsl:template> + <xsl:template name="title-info-appendix"> + <xsl:if test="count(fb:description/fb:title-info)"> + <xsl:for-each select="fb:description/fb:title-info"> + <xsl:call-template name="title-info-appendix-wrk"> + <xsl:with-param name="my_id" + select="concat('title-info-appendix', generate-id())"/> + <xsl:with-param name="my_title"> + <xsl:call-template name="gentext.info.title"/> + </xsl:with-param> + <xsl:with-param name="my_annotation_id" select="'preface_annotation'"/> + </xsl:call-template> + </xsl:for-each> + </xsl:if> + </xsl:template> + <xsl:template name="src-title-info-appendix"> + <xsl:if test="count(fb:description/fb:src-title-info)"> + <xsl:for-each select="fb:description/fb:src-title-info"> + <xsl:call-template name="title-info-appendix-wrk"> + <xsl:with-param name="my_id" + select="concat('src-title-info-appendix', generate-id())"/> + <xsl:with-param name="my_title"> + <xsl:call-template name="gentext.info.title"/> + </xsl:with-param> + <xsl:with-param name="my_annotation_id" select="'preface_annotation_original'"/> + </xsl:call-template> + </xsl:for-each> + </xsl:if> + </xsl:template> + <xsl:template name="entry-tbl-title"> + <entry align="left"> + <simpara> + <emphasis role="strong"> + <xsl:call-template name="gentext.info.param"/> + </emphasis> + </simpara> + </entry> + </xsl:template> + <xsl:template name="title-info-appendix-wrk"> + <xsl:param name="my_id"/> + <xsl:param name="my_title"/> + <xsl:param name="my_annotation_id"/> + <appendix id="{$my_id}"> + <title> + <xsl:value-of select="$my_title"/> + </title> + <informaltable align="center" frame="topbot" colsep="0" rowsep="1"> + <tgroup cols="2"> + <colspec colnum="1" colname="col1" colwidth="1*"/> + <colspec colnum="2" colname="col2" colwidth="2*"/> + <tbody> + <xsl:if test="count(fb:genre)"> + <row> + <xsl:for-each select="fb:genre[1]"> + <xsl:call-template name="entry-tbl-title"/> + </xsl:for-each> + <entry align="left"> + <xsl:call-template name="title-info-genres"/> + </entry> + </row> + </xsl:if> + <xsl:if test="count(fb:author)"> + <row> + <xsl:for-each select="fb:author[1]"> + <xsl:call-template name="entry-tbl-title"/> + </xsl:for-each> + <entry align="left"> + <xsl:call-template name="title-info-authors"/> + </entry> + </row> + </xsl:if> + <xsl:if test="count(fb:book-title)"> + <row> + <xsl:for-each select="fb:book-title[1]"> + <xsl:call-template name="entry-tbl-title"/> + </xsl:for-each> + <entry align="left"> + <simpara> + <xsl:value-of select="fb:book-title/text()"/> + </simpara> + </entry> + </row> + </xsl:if> + <xsl:if test="count(fb:annotation)"> + <row> + <xsl:for-each select="fb:annotation[1]"> + <xsl:call-template name="entry-tbl-title"/> + </xsl:for-each> + <entry align="left"> + <xsl:call-template name="title-info-annotation"> + <xsl:with-param name="my_annotation_id" + select="$my_annotation_id"/> + </xsl:call-template> + </entry> + </row> + </xsl:if> + <xsl:if test="count(fb:keywords)"> + <row> + <xsl:for-each select="fb:keywords[1]"> + <xsl:call-template name="entry-tbl-title"/> + </xsl:for-each> + <entry align="left"> + <xsl:call-template name="title-info-keywords"/> + </entry> + </row> + </xsl:if> + <xsl:if test="count(fb:date)"> + <row> + <xsl:for-each select="fb:date[1]"> + <xsl:call-template name="entry-tbl-title"/> + </xsl:for-each> + <entry align="left"> + <xsl:call-template name="title-info-date"/> + </entry> + </row> + </xsl:if> + <xsl:if test="count(fb:coverpage)"> + <row> + <xsl:for-each select="fb:coverpage[1]"> + <xsl:call-template name="entry-tbl-title"/> + </xsl:for-each> + <entry align="left"> + <xsl:call-template name="title-info-coverpage"> + <xsl:with-param name="my_annotation_id" + select="$my_annotation_id"/> + </xsl:call-template> + </entry> + </row> + </xsl:if> + <xsl:if test="count(fb:lang)"> + <row> + <xsl:for-each select="fb:lang[1]"> + <xsl:call-template name="entry-tbl-title"/> + </xsl:for-each> + <entry align="left"> + <xsl:call-template name="title-info-lang"/> + </entry> + </row> + </xsl:if> + <xsl:if test="count(fb:src-lang)"> + <row> + <xsl:for-each select="fb:src-lang[1]"> + <xsl:call-template name="entry-tbl-title"/> + </xsl:for-each> + <entry align="left"> + <xsl:call-template name="title-info-src-lang"/> + </entry> + </row> + </xsl:if> + <xsl:if test="count(fb:translator)"> + <row> + <xsl:for-each select="fb:translator[1]"> + <xsl:call-template name="entry-tbl-title"/> + </xsl:for-each> + <entry align="left"> + <xsl:call-template name="title-info-translators"/> + </entry> + </row> + </xsl:if> + <xsl:if test="count(fb:sequence)"> + <row> + <xsl:for-each select="fb:sequence[1]"> + <xsl:call-template name="entry-tbl-title"/> + </xsl:for-each> + <entry align="left"> + <xsl:call-template name="title-info-sequence"/> + </entry> + </row> + </xsl:if> + </tbody> + </tgroup> + </informaltable> + </appendix> + </xsl:template> + <xsl:template name="title-info-genres"> + <xsl:choose> + <xsl:when test="count(fb:genre) > 1"> + <itemizedlist spacing="compact"> + <xsl:for-each select="fb:genre"> + <listitem> + <simpara> + <xsl:value-of select="text()"/> + <xsl:if test="@match != ''"> (<xsl:value-of select="@match" + />%)</xsl:if> + </simpara> + </listitem> + </xsl:for-each> + </itemizedlist> + </xsl:when> + <xsl:otherwise> + <simpara> + <xsl:for-each select="fb:genre"> + <xsl:value-of select="text()"/> + <xsl:if test="@match != ''"> (<xsl:value-of select="@match"/>%)</xsl:if> + </xsl:for-each> + </simpara> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + <xsl:template name="title-info-authors"> + <xsl:choose> + <xsl:when test="count(fb:author) > 1"> + <itemizedlist spacing="compact"> + <xsl:for-each select="fb:author"> + <listitem> + <simpara> + <xsl:apply-templates mode="bookinfo"/> + </simpara> + </listitem> + </xsl:for-each> + </itemizedlist> + </xsl:when> + <xsl:otherwise> + <simpara> + <xsl:for-each select="fb:author"> + <xsl:apply-templates mode="bookinfo"/> + </xsl:for-each> + </simpara> + </xsl:otherwise> + </xsl:choose> + + </xsl:template> + <xsl:template name="title-info-annotation"> + <xsl:param name="my_annotation_id"/> + <simpara> + <xsl:call-template name="gentext.param"> + <xsl:with-param name="param" select="'SeeAbr'"/> + </xsl:call-template> + <xsl:text> </xsl:text> + <xref linkend="{$my_annotation_id}"/> + </simpara> + </xsl:template> + <xsl:template name="title-info-keywords"> + <simpara> + <xsl:value-of select="fb:keywords/text()"/> + </simpara> + </xsl:template> + <xsl:template name="title-info-date"> + <simpara> + <xsl:value-of select="fb:date/text()"/> + <xsl:if test="fb:date/@value"> (<xsl:value-of select="fb:date/@value"/>)</xsl:if> + </simpara> + </xsl:template> + <xsl:template name="title-info-coverpage"> + <xsl:param name="my_annotation_id"/> + <simpara> + <xsl:call-template name="gentext.param"> + <xsl:with-param name="param" select="'SeeAbr'"/> + </xsl:call-template> + <xsl:text> </xsl:text> + <xref linkend="{$my_annotation_id}"/> + </simpara> + </xsl:template> + <xsl:template name="title-info-lang"> + <simpara> + <xsl:value-of select="fb:lang/text()"/> + </simpara> + </xsl:template> + <xsl:template name="title-info-src-lang"> + <simpara> + <xsl:value-of select="fb:src-lang/text()"/> + </simpara> + </xsl:template> + <xsl:template name="title-info-translators"> + <xsl:choose> + <xsl:when test="count(fb:translator) > 1"> + <itemizedlist spacing="compact"> + <xsl:for-each select="fb:translator"> + <listitem> + <simpara> + <xsl:apply-templates mode="bookinfo"/> + </simpara> + </listitem> + </xsl:for-each> + </itemizedlist> + </xsl:when> + <xsl:otherwise> + <simpara> + <xsl:for-each select="fb:translator"> + <xsl:apply-templates mode="bookinfo"/> + </xsl:for-each> + </simpara> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + <xsl:template name="title-info-sequence"> + <simpara> + <xsl:value-of select="fb:sequence/@name"/> + </simpara> + <simpara> + <xsl:if test="fb:sequence/@number"> + <xsl:call-template name="gentext.info.param"> + <xsl:with-param name="context" select="'title-info'"/> + <xsl:with-param name="param" select="'sequence.number'"/> + </xsl:call-template> + <xsl:text>: </xsl:text> + <xsl:value-of select="fb:sequence/@number"/> + </xsl:if> + </simpara> + </xsl:template> + <xsl:template name="document-info-appendix"> + <xsl:if test="count(fb:description/fb:document-info)"> + <xsl:for-each select="fb:description/fb:document-info"> + <xsl:call-template name="document-info-appendix-wrk"/> + </xsl:for-each> + </xsl:if> + </xsl:template> + <xsl:template name="document-info-appendix-wrk"> + <appendix id="{concat('document-info-appendix', generate-id())}"> + <title> + <xsl:call-template name="gentext.info.title"/> + </title> + <informaltable align="center" frame="topbot" colsep="0" rowsep="1"> + <tgroup cols="2"> + <colspec colnum="1" colname="col1" colwidth="1*"/> + <colspec colnum="2" colname="col2" colwidth="2*"/> + <tbody> + <xsl:if test="count(fb:author)"> + <row> + <xsl:for-each select="fb:author[1]"> + <xsl:call-template name="entry-tbl-title"/> + </xsl:for-each> + <entry align="left"> + <xsl:call-template name="title-info-authors"/> + </entry> + </row> + </xsl:if> + <xsl:if test="count(fb:program-used)"> + <row> + <xsl:for-each select="fb:program-used[1]"> + <xsl:call-template name="entry-tbl-title"/> + </xsl:for-each> + <entry align="left"> + <simpara> + <xsl:value-of select="fb:program-used/text()"/> + </simpara> + </entry> + </row> + </xsl:if> + <xsl:if test="count(fb:date)"> + <row> + <xsl:for-each select="fb:date[1]"> + <xsl:call-template name="entry-tbl-title"/> + </xsl:for-each> + <entry align="left"> + <xsl:call-template name="title-info-date"/> + </entry> + </row> + </xsl:if> + <xsl:if test="count(fb:src-url)"> + <row> + <xsl:for-each select="fb:src-url[1]"> + <xsl:call-template name="entry-tbl-title"/> + </xsl:for-each> + <entry align="left"> + <xsl:call-template name="document-info-src-url"/> + </entry> + </row> + </xsl:if> + <xsl:if test="count(fb:src-ocr)"> + <row> + <xsl:for-each select="fb:src-ocr[1]"> + <xsl:call-template name="entry-tbl-title"/> + </xsl:for-each> + <entry align="left"> + <simpara> + <xsl:value-of select="fb:src-ocr/text()"/> + </simpara> + </entry> + </row> + </xsl:if> + <xsl:if test="count(fb:id)"> + <row> + <xsl:for-each select="fb:id[1]"> + <xsl:call-template name="entry-tbl-title"/> + </xsl:for-each> + <entry align="left"> + <simpara> + <code> + <?db-font-size 50% ?> + <xsl:value-of select="fb:id/text()"/> + </code> + </simpara> + </entry> + </row> + </xsl:if> + <xsl:if test="count(fb:version)"> + <row> + <xsl:for-each select="fb:version[1]"> + <xsl:call-template name="entry-tbl-title"/> + </xsl:for-each> + <entry align="left"> + <simpara> + <xsl:value-of select="fb:version/text()"/> + </simpara> + </entry> + </row> + </xsl:if> + <xsl:if test="count(fb:history)"> + <row> + <!-- TODO to bookinfo, xref + publisher element--> + <xsl:for-each select="fb:history[1]"> + <xsl:call-template name="entry-tbl-title"/> + </xsl:for-each> + <entry align="left"> + <xsl:call-template name="document-info-history"/> + </entry> + </row> + </xsl:if> + </tbody> + </tgroup> + </informaltable> + </appendix> + </xsl:template> + <xsl:template name="document-info-src-url"> + <simpara> + <ulink url="{fb:src-url/text()}"> + <xsl:value-of select="fb:src-url/text()"/> + </ulink> + </simpara> + </xsl:template> + <xsl:template name="document-info-history"> + <xsl:apply-templates select="fb:history/*"/> + </xsl:template> + <xsl:template name="publish-info-appendix"> + <xsl:if test="count(fb:description/fb:publish-info)"> + <xsl:for-each select="fb:description/fb:publish-info"> + <xsl:call-template name="publish-info-appendix-wrk"/> + </xsl:for-each> + </xsl:if> + </xsl:template> + <xsl:template name="publish-info-appendix-wrk"> + <appendix id="{concat('publish-info-appendix', generate-id())}"> + <title> + <xsl:call-template name="gentext.info.title"/> + </title> + <informaltable align="center" frame="topbot" colsep="0" rowsep="1"> + <tgroup cols="2"> + <colspec colnum="1" colname="col1" colwidth="1*"/> + <colspec colnum="2" colname="col2" colwidth="2*"/> + <tbody> + <xsl:if test="count(fb:book-name)"> + <row> + <xsl:for-each select="fb:book-name[1]"> + <xsl:call-template name="entry-tbl-title"/> + </xsl:for-each> + <entry align="left"> + <simpara> + <xsl:value-of select="fb:book-name/text()"/> + </simpara> + </entry> + </row> + </xsl:if> + <xsl:if test="count(fb:publisher)"> + <row> + <xsl:for-each select="fb:publisher[1]"> + <xsl:call-template name="entry-tbl-title"/> + </xsl:for-each> + <entry align="left"> + <simpara> + <xsl:value-of select="fb:publisher/text()"/> + </simpara> + </entry> + </row> + </xsl:if> + <xsl:if test="count(fb:city)"> + <row> + <xsl:for-each select="fb:city[1]"> + <xsl:call-template name="entry-tbl-title"/> + </xsl:for-each> + <entry align="left"> + <simpara> + <xsl:value-of select="fb:city/... [truncated message content] |