mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix Bug #1228905 Calibre does not create a valid .bib file
This commit is contained in:
parent
ab4f53331e
commit
45aec8c2e1
@ -179,6 +179,8 @@ class BIBTEX(CatalogPlugin):
|
|||||||
#\n removal
|
#\n removal
|
||||||
item = item.replace(u'\r\n',u' ')
|
item = item.replace(u'\r\n',u' ')
|
||||||
item = item.replace(u'\n',u' ')
|
item = item.replace(u'\n',u' ')
|
||||||
|
# unmatched brace removal (users should use \leftbrace or \rightbrace for single braces)
|
||||||
|
item = bibtexdict.stripUnmatchedSyntax(item, u'{', u'}')
|
||||||
#html to text
|
#html to text
|
||||||
try:
|
try:
|
||||||
item = html2text(item)
|
item = html2text(item)
|
||||||
|
@ -2902,3 +2902,31 @@ class BibTeX:
|
|||||||
"""
|
"""
|
||||||
return self.utf8ToBibtex(u' and '.join([author for author in item]))
|
return self.utf8ToBibtex(u' and '.join([author for author in item]))
|
||||||
|
|
||||||
|
def stripUnmatchedSyntax(self, text, open_character, close_character):
|
||||||
|
"""
|
||||||
|
Strips unmatched BibTeX syntax
|
||||||
|
"""
|
||||||
|
stack = list()
|
||||||
|
|
||||||
|
if len(open_character) > 1 or len(close_character) > 1:
|
||||||
|
raise ValueError("Only single characters accepted")
|
||||||
|
|
||||||
|
for i in text:
|
||||||
|
if i == open_character:
|
||||||
|
stack.append(open_character)
|
||||||
|
# if there is already an orphan closing character strip everything
|
||||||
|
elif i == close_character and not stack:
|
||||||
|
text = text.replace(open_character, u'')
|
||||||
|
text = text.replace(close_character, u'')
|
||||||
|
return text
|
||||||
|
elif i == close_character and stack:
|
||||||
|
stack.pop()
|
||||||
|
|
||||||
|
# if there are still open_tokens on the stack they have not been closed strip everything
|
||||||
|
if stack:
|
||||||
|
text = text.replace(open_character, u'')
|
||||||
|
text = text.replace(close_character, u'')
|
||||||
|
return text
|
||||||
|
# if nothing left on stack all characters matched and do nothing
|
||||||
|
else:
|
||||||
|
return text
|
||||||
|
Loading…
x
Reference in New Issue
Block a user