Skip to content

Commit

Permalink
Colorize kana in anki
Browse files Browse the repository at this point in the history
Now do stroke order diagrams in anki when the character consists of a single
kana.  Retains behavior of diagrams for only kanji in full sentences.

Fixes issue #20 and issue #32
  • Loading branch information
cayennes committed Oct 11, 2014
1 parent 9aa6583 commit aa5945d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions anki/kanji_colorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,21 @@ def modelIsCorrectType(model):
srcField in fields and
dstField in fields)


def characters_to_colorize(s):
'''
Given a string, returns a lost of characters to colorize
If the string consists of only a single character, returns a list
containing that character. If it is longer, returns a list of only the
kanji.
'''
if len(s) <= 1:
return list(s)
return [c for c in s if ord(c) >= 19968 and ord(c) <= 40879]


def addKanji(note, flag=False, currentFieldIndex=None):
'''
Checks to see if a kanji should be added, and adds it if so.
Expand All @@ -121,10 +136,7 @@ def addKanji(note, flag=False, currentFieldIndex=None):

dst=''
#srcTxt = string.replace(srcTxt, u'\uff5e', u'\u301c').encode('euc-jp')
for character in unicode(srcTxt):
if ord(character) < 19968: # only add kanjis
continue

for character in characters_to_colorize(unicode(srcTxt)):
# write to file; anki works in the media directory by default
try:
filename = KanjiVG(character).ascii_filename
Expand Down
2 changes: 1 addition & 1 deletion pavement.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
description='script and module to create colored stroke order '
'diagrams based on KanjiVG data',
long_description=open('README.rst').read(),
version='0.8.0',
version='0.9',
author='Cayenne',
author_email='cayennes@gmail.com',
url='http://github.com/cayennes/kanji-colorize',
Expand Down

0 comments on commit aa5945d

Please sign in to comment.