本文整理汇总了Python中anki.utils.stripHTML方法的典型用法代码示例。如果您正苦于以下问题:Python utils.stripHTML方法的具体用法?Python utils.stripHTML怎么用?Python utils.stripHTML使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anki.utils
的用法示例。
在下文中一共展示了utils.stripHTML方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _updateListItems
# 需要导入模块: from anki import utils [as 别名]
# 或者: from anki.utils import stripHTML [as 别名]
def _updateListItems(self):
cardInfo = self._getCardInfo(self.did)
self.cardListWidget.clear()
posWidth = len(str(len(cardInfo) + 1))
for i, card in enumerate(cardInfo, start=1):
if self.settings['prioEnabled']:
info = card['priority']
else:
info = str(i).zfill(posWidth)
title = sub(r'\s+', ' ', stripHTML(card['title']))
text = self.settings['organizerFormat'].format(
info=info, title=title
)
item = QListWidgetItem(text)
item.setData(Qt.UserRole, card)
self.cardListWidget.addItem(item)
示例2: fieldToTags
# 需要导入模块: from anki import utils [as 别名]
# 或者: from anki.utils import stripHTML [as 别名]
def fieldToTags(self, nids, field):
"""Add field contents to to note tags"""
edited = 0
for nid in nids:
note = self.mw.col.getNote(nid)
if field not in note:
continue
html = note[field]
text = stripHTML(html).strip()
if not text:
continue
tag = SEPARATOR.join(text.split())
if note.hasTag(tag):
continue
note.addTag(tag)
note.flush()
edited += 1
return edited
示例3: hanzi_context
# 需要导入模块: from anki import utils [as 别名]
# 或者: from anki.utils import stripHTML [as 别名]
def hanzi_context(
txt: str, field_name: str, filter_name: str, context: TemplateRenderContext,
) -> str:
if not filter_name.startswith("hanzi_context"):
# not our filter, return string unchanged
return txt
'''
For use on a Hanzi field.
Return a list of all the other Hanzi synonyms, with the common characters hidden,
to allow the user to identify the correct hanzi from a note.
'''
other_hanzi = []
for k, v in context.iteritems():
if re.match(r'Hanzi.*', k, flags=re.IGNORECASE) and v != txt :
other_hanzi += [k]
if len(other_hanzi)<1:
return ""
other_hanzi.sort()
other_hanzi_values = []
for v in other_hanzi:
value = stripHTML(re.sub(r, r'\1', no_sound(context[v])))
if len(value)>0:
other_hanzi_values += [value]
if len(other_hanzi_values)<1:
return ""
def concat(a, b):
return a + " / " + b
context_string = reduce(concat, other_hanzi_values)
for h in txt:
if h >= u'\u4e00' and h <= u'\u9fff':
context_string = re.sub(h, " _ ", context_string)
context_string = re.sub(" ", " ", context_string)
return context_string
#legacy
示例4: hanzi_context
# 需要导入模块: from anki import utils [as 别名]
# 或者: from anki.utils import stripHTML [as 别名]
def hanzi_context(txt, extra, context, tag, fullname):
'''
For use on a Hanzi field.
Return a list of all the other Hanzi synonyms, with the common characters hidden,
to allow the user to identify the correct hanzi from a note.
'''
other_hanzi = []
for k, v in context.iteritems():
if re.match(r'Hanzi.*', k, flags=re.IGNORECASE) and v != txt :
other_hanzi += [k]
if len(other_hanzi)<1:
return ""
other_hanzi.sort()
other_hanzi_values = []
for v in other_hanzi:
value = stripHTML(re.sub(r, r'\1', no_sound(context[v])))
if len(value)>0:
other_hanzi_values += [value]
if len(other_hanzi_values)<1:
return ""
def concat(a, b):
return a + " / " + b
context_string = reduce(concat, other_hanzi_values)
for h in txt:
if h >= u'\u4e00' and h <= u'\u9fff':
context_string = re.sub(h, " _ ", context_string)
context_string = re.sub(" ", " ", context_string)
return context_string
示例5: ruby_top_text
# 需要导入模块: from anki import utils [as 别名]
# 或者: from anki.utils import stripHTML [as 别名]
def ruby_top_text(txt, *args):
return stripHTML(re.sub(r, r'\2 ', no_sound(no_comments(txt))))
示例6: ruby_bottom_text
# 需要导入模块: from anki import utils [as 别名]
# 或者: from anki.utils import stripHTML [as 别名]
def ruby_bottom_text(txt, *args):
return stripHTML(re.sub(r, r'\1', no_sound(no_comments(txt))))
示例7: _get_characters
# 需要导入模块: from anki import utils [as 别名]
# 或者: from anki.utils import stripHTML [as 别名]
def _get_characters(card: Card, config: DeckConfig) -> tuple:
""" Extracts the characters to write from `card`.
Returns:
characters (tuple[list[str], list[str])): The characters contained in field `config.field` of `card`, and
possibly the tones (extracted from css classes)
Raises:
MaobiException:
- If there is no field called `deck.field` in `card`.
- If the field called `config.field` is empty.
- If the field called `config.field` contains more than one character.
"""
# Check that the character field is really there
note = card.note()
note_type = note.model()["name"]
field_name = config.field
if field_name not in note:
raise MaobiException(f"There is no field '{field_name}' in note type {note_type}!")
characters_html = note[field_name]
characters = stripHTML(characters_html)
# extract tones, if possible
tones = []
if "span" in characters_html:
# this is the 'colors' field which has tone information as tone1...4 css classes
tones = list(re.findall("tone[12345]", characters_html))
if len(tones) != len(characters):
tones = []
# Check that the character is one or more characters
if len(characters) == 0:
raise MaobiException(f"Field '{field_name}' was empty!")
return [c for c in characters], tones
示例8: historyRestore
# 需要导入模块: from anki import utils [as 别名]
# 或者: from anki.utils import stripHTML [as 别名]
def historyRestore(self, mode, results, model, fld):
field = model['flds'][fld]['name']
last_val = {}
keys = []
for nid in results[:100]:
oldNote = self.note.col.getNote(nid)
if field in oldNote:
html = oldNote[field]
else:
try:
html = oldNote.fields[fld]
except IndexError:
pass
if html.strip():
text = stripHTML(html)
else:
text = None
if text and text not in last_val:
keys.append(text)
last_val[text] = html
if not last_val:
tooltip("No prior entries for this field found.")
return False
txt = "Set field to:"
(text, ret) = myGetField(self.parentWindow,
txt, keys, title="Field History")
if not ret or not text.strip() or text not in last_val:
return False
self.note[field] = last_val[text]
示例9: parseNoteSettings
# 需要导入模块: from anki import utils [as 别名]
# 或者: from anki.utils import stripHTML [as 别名]
def parseNoteSettings(html):
"""Return note settings. Fall back to defaults if necessary."""
options, settings, opts, sets = None, None, None, None
dflt_set, dflt_opt = config["synced"]["dflts"], config["synced"]["dflto"]
field = stripHTML(html)
lines = field.replace(" ", "").split("|")
if not lines:
return (dflt_set, dflt_opt)
settings = lines[0].split(",")
if len(lines) > 1:
options = lines[1].split(",")
if not options and not settings:
return (dflt_set, dflt_opt)
if not settings:
sets = dflt_set
else:
sets = []
for idx, item in enumerate(settings[:3]):
try:
sets.append(int(item))
except ValueError:
sets.append(None)
length = len(sets)
if length == 3 and isinstance(sets[1], int):
pass
elif length == 2 and isinstance(sets[0], int):
sets = [sets[1], sets[0], sets[1]]
elif length == 1 and isinstance(sets[0], int):
sets = [dflt_set[0], sets[0], dflt_set[2]]
else:
sets = dflt_set
if not options:
opts = dflt_opt
else:
opts = []
for i in range(4):
try:
if options[i] == "y":
opts.append(True)
else:
opts.append(False)
except IndexError:
opts.append(dflt_opt[i])
return (sets, opts)