mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Various fixes to markdown found by the automatic python checker
This commit is contained in:
parent
33d6ae3486
commit
c7bf67e6c3
@ -63,10 +63,10 @@ class Check(Command):
|
||||
for f in x[-1]:
|
||||
y = self.j(x[0], f)
|
||||
mtime = os.stat(y).st_mtime
|
||||
if f.endswith('.py') and f not in ('ptempfile.py', 'feedparser.py',
|
||||
'pyparsing.py', 'markdown.py') and \
|
||||
'genshi' not in y and cache.get(y, 0) != mtime and \
|
||||
'prs500/driver.py' not in y:
|
||||
if (f.endswith('.py') and f not in ('ptempfile.py', 'feedparser.py',
|
||||
'pyparsing.py', 'markdown.py') and
|
||||
'genshi' not in y and cache.get(y, 0) != mtime and
|
||||
'prs500/driver.py' not in y):
|
||||
yield y, mtime
|
||||
|
||||
for x in os.walk(self.j(self.d(self.SRC), 'recipes')):
|
||||
|
@ -355,7 +355,7 @@ class HashHeaderProcessor(BlockProcessor):
|
||||
blocks.insert(0, after)
|
||||
else:
|
||||
# This should never happen, but just in case...
|
||||
message(CRITICAL, "We've got a problem header!")
|
||||
print("We've got a problem header!")
|
||||
|
||||
|
||||
class SetextHeaderProcessor(BlockProcessor):
|
||||
@ -407,7 +407,7 @@ class HRProcessor(BlockProcessor):
|
||||
# Recursively parse lines before hr so they get parsed first.
|
||||
self.parser.parseBlocks(parent, ['\n'.join(prelines)])
|
||||
# create hr
|
||||
hr = markdown.etree.SubElement(parent, 'hr')
|
||||
markdown.etree.SubElement(parent, 'hr')
|
||||
# check for lines in block after hr.
|
||||
lines = lines[len(prelines)+1:]
|
||||
if len(lines):
|
||||
|
@ -9,7 +9,7 @@ Markdown is called from the command line.
|
||||
import markdown
|
||||
import sys
|
||||
import logging
|
||||
from logging import DEBUG, INFO, WARN, ERROR, CRITICAL
|
||||
from logging import DEBUG, INFO, CRITICAL
|
||||
|
||||
EXECUTABLE_NAME_FOR_USAGE = "python markdown.py"
|
||||
""" The name used in the usage statement displayed for python versions < 2.3.
|
||||
|
@ -8,9 +8,11 @@ def importETree():
|
||||
etree_in_c = None
|
||||
try: # Is it Python 2.5+ with C implemenation of ElementTree installed?
|
||||
import xml.etree.cElementTree as etree_in_c
|
||||
etree_in_c
|
||||
except ImportError:
|
||||
try: # Is it Python 2.5+ with Python implementation of ElementTree?
|
||||
import xml.etree.ElementTree as etree
|
||||
etree
|
||||
except ImportError:
|
||||
try: # An earlier version of Python with cElementTree installed?
|
||||
import cElementTree as etree_in_c
|
||||
|
@ -80,7 +80,7 @@ class DefListIndentProcessor(markdown.blockprocessors.ListIndentProcessor):
|
||||
ITEM_TYPES = ['dd']
|
||||
LIST_TYPES = ['dl']
|
||||
|
||||
def create_item(parent, block):
|
||||
def create_item(self, parent, block):
|
||||
""" Create a new dd and parse the block with it as the parent. """
|
||||
dd = markdown.etree.SubElement(parent, 'dd')
|
||||
self.parser.parseBlocks(dd, [block])
|
||||
|
@ -106,7 +106,7 @@ class FootnoteExtension(markdown.Extension):
|
||||
|
||||
div = etree.Element("div")
|
||||
div.set('class', 'footnote')
|
||||
hr = etree.SubElement(div, "hr")
|
||||
etree.SubElement(div, "hr")
|
||||
ol = etree.SubElement(div, "ol")
|
||||
|
||||
for id in self.footnotes.keys():
|
||||
@ -199,7 +199,6 @@ class FootnotePreprocessor(markdown.preprocessors.Preprocessor):
|
||||
|
||||
"""
|
||||
items = []
|
||||
item = -1
|
||||
i = 0 # to keep track of where we are
|
||||
|
||||
def detab(line):
|
||||
@ -277,7 +276,6 @@ class FootnoteTreeprocessor(markdown.treeprocessors.Treeprocessor):
|
||||
ind = element.getchildren().find(child)
|
||||
element.getchildren().insert(ind + 1, footnotesDiv)
|
||||
child.tail = None
|
||||
fnPlaceholder.parent.replaceChild(fnPlaceholder, footnotesDiv)
|
||||
else:
|
||||
root.append(footnotesDiv)
|
||||
|
||||
|
@ -66,7 +66,6 @@ Dependencies:
|
||||
"""
|
||||
|
||||
import calibre.ebooks.markdown.markdown as markdown
|
||||
from calibre.ebooks.markdown.markdown import etree
|
||||
import re
|
||||
from string import ascii_lowercase, digits, punctuation
|
||||
|
||||
@ -119,7 +118,7 @@ class HeaderIdProcessor(markdown.blockprocessors.BlockProcessor):
|
||||
blocks.insert(0, after)
|
||||
else:
|
||||
# This should never happen, but just in case...
|
||||
message(CRITICAL, "We've got a problem header!")
|
||||
print ("We've got a problem header!")
|
||||
|
||||
def _get_meta(self):
|
||||
""" Return meta data suported by this ext as a tuple """
|
||||
|
@ -47,6 +47,7 @@ from urlparse import urlparse, urlunparse
|
||||
import sys
|
||||
if sys.version >= "3.0":
|
||||
from html import entities as htmlentitydefs
|
||||
htmlentitydefs
|
||||
else:
|
||||
import htmlentitydefs
|
||||
|
||||
@ -215,7 +216,6 @@ class HtmlPattern (Pattern):
|
||||
""" Store raw inline html and return a placeholder. """
|
||||
def handleMatch (self, m):
|
||||
rawhtml = m.group(2)
|
||||
inline = True
|
||||
place_holder = self.markdown.htmlStash.store(rawhtml)
|
||||
return place_holder
|
||||
|
||||
|
@ -156,7 +156,7 @@ class OrderedDict(dict):
|
||||
self.keyOrder.insert(i, key)
|
||||
else:
|
||||
self.keyOrder.append(key)
|
||||
except Error:
|
||||
except Exception as e:
|
||||
# restore to prevent data loss and reraise
|
||||
self.keyOrder.insert(n, key)
|
||||
raise Error
|
||||
raise e
|
||||
|
@ -185,7 +185,7 @@ class InlineProcessor(Treeprocessor):
|
||||
result.append(node)
|
||||
|
||||
else: # wrong placeholder
|
||||
end = index + len(prefix)
|
||||
end = index + len(self.__placeholder_prefix)
|
||||
linkText(data[strartIndex:end])
|
||||
strartIndex = end
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user