mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Support for text-indent
This commit is contained in:
parent
7d8f1f7eb3
commit
3064a0666b
@ -231,11 +231,11 @@ class HTMLConverter(object):
|
|||||||
|
|
||||||
# Defaults for various formatting tags
|
# Defaults for various formatting tags
|
||||||
css = dict(
|
css = dict(
|
||||||
h1 = {"font-size" :"xx-large", "font-weight":"bold"},
|
h1 = {"font-size" :"xx-large", "font-weight":"bold", 'text-indent':'0pt'},
|
||||||
h2 = {"font-size" :"x-large", "font-weight":"bold"},
|
h2 = {"font-size" :"x-large", "font-weight":"bold", 'text-indent':'0pt'},
|
||||||
h3 = {"font-size" :"large", "font-weight":"bold"},
|
h3 = {"font-size" :"large", "font-weight":"bold", 'text-indent':'0pt'},
|
||||||
h4 = {"font-size" :"large"},
|
h4 = {"font-size" :"large", 'text-indent':'0pt'},
|
||||||
h5 = {"font-weight" :"bold"},
|
h5 = {"font-weight" :"bold", 'text-indent':'0pt'},
|
||||||
b = {"font-weight" :"bold"},
|
b = {"font-weight" :"bold"},
|
||||||
strong = {"font-weight" :"bold"},
|
strong = {"font-weight" :"bold"},
|
||||||
i = {"font-style" :"italic"},
|
i = {"font-style" :"italic"},
|
||||||
@ -282,9 +282,6 @@ class HTMLConverter(object):
|
|||||||
self.scaled_images = {} #: Temporary files with scaled version of images
|
self.scaled_images = {} #: Temporary files with scaled version of images
|
||||||
self.max_link_levels = max_link_levels #: Number of link levels to process recursively
|
self.max_link_levels = max_link_levels #: Number of link levels to process recursively
|
||||||
self.link_level = link_level #: Current link level
|
self.link_level = link_level #: Current link level
|
||||||
self.justification_styles = dict(head=book.create_text_style(align='head'),
|
|
||||||
foot=book.create_text_style(align='foot'),
|
|
||||||
center=book.create_text_style(align='center'))
|
|
||||||
self.blockquote_style = book.create_block_style(sidemargin=60,
|
self.blockquote_style = book.create_block_style(sidemargin=60,
|
||||||
topskip=20, footskip=20)
|
topskip=20, footskip=20)
|
||||||
self.unindented_style = book.create_text_style(parindent=0)
|
self.unindented_style = book.create_text_style(parindent=0)
|
||||||
@ -595,8 +592,11 @@ class HTMLConverter(object):
|
|||||||
if align != self.current_block.textStyle.attrs['align']:
|
if align != self.current_block.textStyle.attrs['align']:
|
||||||
self.current_para.append_to(self.current_block)
|
self.current_para.append_to(self.current_block)
|
||||||
self.current_block.append_to(self.current_page)
|
self.current_block.append_to(self.current_page)
|
||||||
|
ts = self.book.create_text_style(**self.current_block.textStyle.attrs)
|
||||||
|
ts.attrs['align'] = align
|
||||||
self.current_block = self.book.create_text_block(
|
self.current_block = self.book.create_text_block(
|
||||||
textStyle=self.justification_styles[align])
|
blockStyle=self.current_block.blockStyle,
|
||||||
|
textStyle=ts)
|
||||||
self.current_para = Paragraph()
|
self.current_para = Paragraph()
|
||||||
try:
|
try:
|
||||||
self.current_para.append(Span(src, self.sanctify_css(css), self.memory,\
|
self.current_para.append(Span(src, self.sanctify_css(css), self.memory,\
|
||||||
@ -609,7 +609,7 @@ class HTMLConverter(object):
|
|||||||
""" Make css safe for use in a SPAM Xylog tag """
|
""" Make css safe for use in a SPAM Xylog tag """
|
||||||
for key in css.keys():
|
for key in css.keys():
|
||||||
test = key.lower()
|
test = key.lower()
|
||||||
if test.startswith('margin') or 'indent' in test or \
|
if test.startswith('margin') or \
|
||||||
'padding' in test or 'border' in test or 'page-break' in test \
|
'padding' in test or 'border' in test or 'page-break' in test \
|
||||||
or test.startswith('mso') or test.startswith('background')\
|
or test.startswith('mso') or test.startswith('background')\
|
||||||
or test in ['color', 'display', 'text-decoration', \
|
or test in ['color', 'display', 'text-decoration', \
|
||||||
@ -636,7 +636,8 @@ class HTMLConverter(object):
|
|||||||
self.current_para.append_to(self.current_block)
|
self.current_para.append_to(self.current_block)
|
||||||
self.current_block.append_to(self.current_page)
|
self.current_block.append_to(self.current_page)
|
||||||
self.current_para = Paragraph()
|
self.current_para = Paragraph()
|
||||||
self.current_block = self.book.create_text_block()
|
self.current_block = self.book.create_text_block(textStyle=self.current_block.textStyle,
|
||||||
|
blockStyle=self.current_block.blockStyle)
|
||||||
|
|
||||||
def parse_tag(self, tag, parent_css):
|
def parse_tag(self, tag, parent_css):
|
||||||
try:
|
try:
|
||||||
@ -687,7 +688,8 @@ class HTMLConverter(object):
|
|||||||
break
|
break
|
||||||
if target and not isinstance(target, (TextBlock, ImageBlock)):
|
if target and not isinstance(target, (TextBlock, ImageBlock)):
|
||||||
if isinstance(target, RuledLine):
|
if isinstance(target, RuledLine):
|
||||||
target = self.book.create_text_block()
|
target = self.book.create_text_block(textStyle=self.current_block.textStyle,
|
||||||
|
blockStyle=self.current_block.blockStyle)
|
||||||
target.Paragraph(' ')
|
target.Paragraph(' ')
|
||||||
self.current_page.append(target)
|
self.current_page.append(target)
|
||||||
else:
|
else:
|
||||||
@ -768,7 +770,8 @@ class HTMLConverter(object):
|
|||||||
self.current_block.append(self.current_para)
|
self.current_block.append(self.current_para)
|
||||||
self.current_page.append(self.current_block)
|
self.current_page.append(self.current_block)
|
||||||
self.current_para = Paragraph()
|
self.current_para = Paragraph()
|
||||||
self.current_block = self.book.create_text_block()
|
self.current_block = self.book.create_text_block(textStyle=self.current_block.textStyle,
|
||||||
|
blockStyle=self.current_block.blockStyle)
|
||||||
im = ImageBlock(self.images[path], x1=width, y1=height,
|
im = ImageBlock(self.images[path], x1=width, y1=height,
|
||||||
xsize=width, ysize=height)
|
xsize=width, ysize=height)
|
||||||
self.current_page.append(im)
|
self.current_page.append(im)
|
||||||
@ -795,6 +798,7 @@ class HTMLConverter(object):
|
|||||||
self.end_current_para()
|
self.end_current_para()
|
||||||
self.current_block.append_to(self.current_page)
|
self.current_block.append_to(self.current_page)
|
||||||
self.current_block = self.book.create_text_block(
|
self.current_block = self.book.create_text_block(
|
||||||
|
blockStyle=self.current_block.blockStyle,
|
||||||
textStyle=self.unindented_style)
|
textStyle=self.unindented_style)
|
||||||
src = ''.join([str(i) for i in tag.contents])
|
src = ''.join([str(i) for i in tag.contents])
|
||||||
lines = src.split('\n')
|
lines = src.split('\n')
|
||||||
@ -809,6 +813,7 @@ class HTMLConverter(object):
|
|||||||
self.in_ol = 1 if tagname == 'ol' else 0
|
self.in_ol = 1 if tagname == 'ol' else 0
|
||||||
self.end_current_block()
|
self.end_current_block()
|
||||||
self.current_block = self.book.create_text_block(
|
self.current_block = self.book.create_text_block(
|
||||||
|
blockStyle=self.current_block.blockStyle,
|
||||||
textStyle=self.unindented_style)
|
textStyle=self.unindented_style)
|
||||||
self.process_children(tag, tag_css)
|
self.process_children(tag, tag_css)
|
||||||
self.in_ol = 0
|
self.in_ol = 0
|
||||||
@ -824,7 +829,7 @@ class HTMLConverter(object):
|
|||||||
self.process_children(tag, tag_css)
|
self.process_children(tag, tag_css)
|
||||||
if self.in_ol:
|
if self.in_ol:
|
||||||
self.in_ol += 1
|
self.in_ol += 1
|
||||||
elif tagname in ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']:
|
elif False and tagname in ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']:
|
||||||
self.end_current_para()
|
self.end_current_para()
|
||||||
if self.current_block.contents:
|
if self.current_block.contents:
|
||||||
self.current_block.append(CR())
|
self.current_block.append(CR())
|
||||||
@ -834,17 +839,39 @@ class HTMLConverter(object):
|
|||||||
elif tagname == 'blockquote':
|
elif tagname == 'blockquote':
|
||||||
self.current_para.append_to(self.current_block)
|
self.current_para.append_to(self.current_block)
|
||||||
self.current_block.append_to(self.current_page)
|
self.current_block.append_to(self.current_page)
|
||||||
|
pb = self.current_block
|
||||||
self.current_para = Paragraph()
|
self.current_para = Paragraph()
|
||||||
|
ts = self.book.create_text_style(**self.current_block.textStyle.attrs)
|
||||||
|
ts.attrs['parindent'] = 0
|
||||||
|
bs = self.book.create_block_style(**self.current_block.blockStyle.attrs)
|
||||||
|
bs.attrs['sidemargin'], bs.attrs['topskip'], bs.attrs['footskip'] = \
|
||||||
|
60, 20, 20
|
||||||
self.current_block = self.book.create_text_block(
|
self.current_block = self.book.create_text_block(
|
||||||
blockStyle=self.blockquote_style,
|
blockStyle=bs, textStyle=ts)
|
||||||
textStyle=self.unindented_style)
|
|
||||||
self.process_children(tag, tag_css)
|
self.process_children(tag, tag_css)
|
||||||
self.end_current_block()
|
self.current_para.append_to(self.current_block)
|
||||||
elif tagname in ['p', 'div']:
|
self.current_block.append_to(self.current_page)
|
||||||
|
self.current_para = Paragraph()
|
||||||
|
self.current_block = self.book.create_text_block(textStyle=pb.textStyle,
|
||||||
|
blockStyle=pb.blockStyle)
|
||||||
|
elif tagname in ['p', 'div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6']:
|
||||||
self.end_current_para()
|
self.end_current_para()
|
||||||
self.lstrip_toggle = True
|
self.lstrip_toggle = True
|
||||||
|
if tag_css.has_key('text-indent'):
|
||||||
|
indent = Span.unit_convert(tag_css['text-indent'])
|
||||||
|
tag_css.pop('text-indent')
|
||||||
|
else:
|
||||||
|
indent = self.book.defaultTextStyle.attrs['parindent']
|
||||||
|
if indent != self.current_block.textStyle.attrs['parindent']:
|
||||||
|
self.current_block.append_to(self.current_page)
|
||||||
|
ts = self.book.create_text_style(**self.current_block.textStyle.attrs)
|
||||||
|
ts.attrs['parindent'] = indent
|
||||||
|
self.current_block = self.book.create_text_block(blockStyle=self.current_block.blockStyle,
|
||||||
|
textStyle=ts)
|
||||||
self.process_children(tag, tag_css)
|
self.process_children(tag, tag_css)
|
||||||
self.end_current_para()
|
self.end_current_para()
|
||||||
|
if tagname.startswith('h'):
|
||||||
|
self.current_block.append(CR())
|
||||||
elif tagname in ['b', 'strong', 'i', 'em', 'span']:
|
elif tagname in ['b', 'strong', 'i', 'em', 'span']:
|
||||||
self.process_children(tag, tag_css)
|
self.process_children(tag, tag_css)
|
||||||
elif tagname == 'font':
|
elif tagname == 'font':
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
<html>
|
<html>
|
||||||
|
<head>
|
||||||
|
<style type='text/css'>
|
||||||
|
.toc { page-break-after: always; text-indent: 0em; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
<h1>Demo of <span style='font-family:monospace'>html2lrf</span></h1>
|
<h1>Demo of <span style='font-family:monospace'>html2lrf</span></h1>
|
||||||
<p>
|
<p>
|
||||||
This file contains a demonstration of the capabilities of <span style='font-family:monospace'>html2lrf,</span> the HTML to LRF converter from <em>libprs500.</em> To obtain libprs500 visit <span style='font:sans-serif'>https://libprs500.kovidgoyal.net</span>
|
This file contains a demonstration of the capabilities of <span style='font-family:monospace'>html2lrf,</span> the HTML to LRF converter from <em>libprs500.</em> To obtain libprs500 visit <span style='font:sans-serif'>https://libprs500.kovidgoyal.net</span>
|
||||||
</p>
|
</p>
|
||||||
|
<br/>
|
||||||
<h2><a name='toc'>Table of Contents</a></h2>
|
<h2><a name='toc'>Table of Contents</a></h2>
|
||||||
<ul style='page-break-after:always'>
|
<ul style='page-break-after:always'>
|
||||||
<li><a href='#lists'>Demonstration of Lists</a></li>
|
<li><a href='#lists'>Demonstration of Lists</a></li>
|
||||||
@ -29,7 +35,7 @@
|
|||||||
<p>
|
<p>
|
||||||
Note that nested lists are not supported.
|
Note that nested lists are not supported.
|
||||||
</p>
|
</p>
|
||||||
<p style='page-break-after:always'>
|
<p class='toc'>
|
||||||
<hr />
|
<hr />
|
||||||
<a href='#toc'>Table of Contents</a>
|
<a href='#toc'>Table of Contents</a>
|
||||||
</p>
|
</p>
|
||||||
@ -49,27 +55,33 @@
|
|||||||
<center>A centered phrase</center>
|
<center>A centered phrase</center>
|
||||||
<span style='text-align:right'>A right aligned phrase</span>
|
<span style='text-align:right'>A right aligned phrase</span>
|
||||||
A normal phrase
|
A normal phrase
|
||||||
<br/>
|
|
||||||
<hr />
|
<hr />
|
||||||
<p> A paragraph containing a <em><blockquote></em>
|
<p> A paragraph containing a <em><blockquote></em>
|
||||||
<blockquote>This is blockquoted text. It is rendered in a separate block with margins.</blockquote>The above text should be distinct from the rest of the paragraph.
|
<blockquote>This is blockquoted text. It is rendered in a separate block with margins.</blockquote>The above text should be distinct from the rest of the paragraph.
|
||||||
<p style='page-break-after:always'>
|
</p>
|
||||||
|
<hr/>
|
||||||
|
<p style='text-indent:30em'>A very indented paragraph</p>
|
||||||
|
<p style='text-indent:0em'>An unindented paragraph</p>
|
||||||
|
<p>A default indented paragrpah</p>
|
||||||
|
<p class='toc'>
|
||||||
<hr />
|
<hr />
|
||||||
<a href='#toc'>Table of Contents</a>
|
<a href='#toc'>Table of Contents</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h2 style='page-break-before:always'><a name='images'>Inline images</a></h2>
|
<h2><a name='images'>Inline images</a></h2>
|
||||||
<p>
|
<p>
|
||||||
Here I demonstrate the use of inline images in the midst of text. Here is a small image <img src='small.jpg' /> embedded in a sentence. Now we have a slightly larger image that is automatically put in its own block <img src='medium.jpg' /> and finally we have a large image which is automatically placed on a page by itself and prevented from being autoscaled when the user changes from S to M to L. Try changing sizes and see how the different embedding styles behave. <img src='large.jpg' />
|
Here I demonstrate the use of inline images in the midst of text. Here is a small image <img src='small.jpg' /> embedded in a sentence. Now we have a slightly larger image that is automatically put in its own block <img src='medium.jpg' /> and finally we have a large image which is automatically placed on a page by itself and prevented from being autoscaled when the user changes from S to M to L. Try changing sizes and see how the different embedding styles behave. <img src='large.jpg' />
|
||||||
</p>
|
</p>
|
||||||
<p style='page-break-after:always'>
|
<p class='toc'>
|
||||||
<hr />
|
<hr />
|
||||||
<a href='#toc'>Table of Contents</a>
|
<a href='#toc'>Table of Contents</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h2 style='page-break-before:always'><a name='recursive'>Recursive link following</a></h2>
|
<h2><a name='recursive'>Recursive link following</a></h2>
|
||||||
|
<p>
|
||||||
<span style='font:monospace'>html2lrf</span> follows links in HTML files that point to other files, recursively. Thus it can be used to convert a whole tree of HTML files into a single LRF file.
|
<span style='font:monospace'>html2lrf</span> follows links in HTML files that point to other files, recursively. Thus it can be used to convert a whole tree of HTML files into a single LRF file.
|
||||||
<p style='page-break-after:always'>
|
</p>
|
||||||
|
<p class='toc'>
|
||||||
<hr />
|
<hr />
|
||||||
<a href='#toc'>Table of Contents</a>
|
<a href='#toc'>Table of Contents</a>
|
||||||
</p>
|
</p>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user