Commit graph

51 commits

Author SHA1 Message Date
Damien Elmes
8a06ab7bfe break on div start, not end 2012-10-26 19:30:01 +09:00
Damien Elmes
c9b3d89d44 better message when bad latex word encountered 2012-10-25 18:48:28 +09:00
Damien Elmes
958967f3c3 log the generated .tex for debugging, and add \n on </div> 2012-10-24 22:29:01 +09:00
Damien Elmes
b66d1479c2 stripHTML() handles entity replacement, which should be done post-strip 2012-09-07 04:54:59 +09:00
Damien Elmes
c394886af8 fix nbsp handling in latex 2012-06-15 01:09:16 +09:00
Damien Elmes
f3a1916c07 replace <div> with spaces in latex 2012-06-14 06:29:25 +09:00
Damien Elmes
68da292ddb copy2->copyfile
copy2() will throw an OSError on Linux+fat32 partitions, and we don't really
need the original mode bits or stat data anyway.
2012-04-22 07:33:04 +09:00
Damien Elmes
2012d0de39 don't try and replace nbsp 2011-12-20 12:47:56 +09:00
Damien Elmes
279a942642 deck -> collection 2011-11-23 17:47:44 +09:00
Damien Elmes
e99e7baa3c need to keep latex in unicode until preamble concat 2011-10-29 21:36:29 +09:00
Damien Elmes
ed7367d67f fix reporting of latex errors; catch some bad commands 2011-10-29 15:12:57 +09:00
Damien Elmes
7e1df75cc2 simplify media.py
- drop mediaPrefix & the mediaURL-based downloading
- always create the media folder
- remove move() in preparation for a single collection approach
2011-09-11 00:25:22 +09:00
Damien Elmes
d3a3edb707 move models into the deck table
Like the previous change, models have been moved from a separate DB table to
an entry in the deck. We need them for many operations including reviewing,
and it's easier to keep them in memory than half on disk with a cache that
gets cleared every time we .reset(). This means they are easily serialized as
well - previously they were part Python and part JSON, which made access
confusing.

Because the data is all pulled from JSON now, the instance methods have been
moved to the model registry. Eg:
  model.addField(...) -> deck.models.addField(model, ...).

- IDs are now timestamped as with groups et al.

- The data field for plugins was also removed. Config info can be added to
  deck.conf; larger data should be stored externally.

- Upgrading needs to be updated for the new model structure.

- HexifyID() now accepts strings as well, as our IDs get converted to strings
  in the serialization process.
2011-08-27 22:27:09 +09:00
Damien Elmes
7afe6a9a7d convert groups to json; use timestamp ids for all but default
Rather than use a combination of id lookups on the groups table and a group
configuration cache in the scheduler, I've moved the groups and group config
into json objects on the deck table. This results in a net saving of code and
saves one or more DB lookups on each card answer, in exchange for a small
increase in deck load/save work.

I did a quick survey of AnkiWeb, and the vast majority of decks use less than
100 tags, and it's safe to assume groups will follow a similar pattern.

All groups and group configs except the default one will use integer
timestamps now, to simplify merging when syncing and importing.

defaultGroup() has been removed in favour of keeping the models up to date
(not yet done).
2011-08-27 17:13:04 +09:00
Damien Elmes
5856ad7545 make latex pre/postamble a model property 2011-04-28 09:24:05 +09:00
Damien Elmes
4a568a83be strip html from latex so clozes work properly
in the future we could look at replacing the cloze html with something
prettier, but it might cause latex errors
2011-04-28 09:24:03 +09:00
Damien Elmes
344b111b80 centralize all tmp dir access 2011-04-28 09:24:03 +09:00
Damien Elmes
2dfdfad6f2 update license link 2011-04-28 09:24:01 +09:00
Damien Elmes
8fcc6b3085 gpl3->agpl 2011-04-28 09:24:01 +09:00
Damien Elmes
4477e21369 make sure we load css on model init 2011-04-28 09:23:57 +09:00
Damien Elmes
8705085200 update latex support 2011-04-28 09:23:56 +09:00
Damien Elmes
be045d451c remove the media table
The media table was originally introduced when Anki hashed media filenames,
and needed a way to remember the original filename. It also helped with:
1) getting a quick list of all media used in the deck, or the media added
   since the last sync, for mobile clients
2) merging identical files with different names

But had some drawbacks:
- every operation that modifies templates, models or facts meant generating
  the q/a and checking if any new media had appeared
- each entry is about 70 bytes, and some decks have 100k+ media files

So we remove the media table. We address 1) by being more intelligent about
media downloads on the mobile platform. We ask the user after a full sync if
they want to look for missing media, and they can choose not to if they know
they haven't added any. And on a partial sync, we can scan the contents of the
incoming facts for media references, and download any references we find. This
also avoids all the issues people had with media not downloading because it
was in their media folder but not in the media database.

For 2), when copying media to the media folder, if we have a duplicate
filename, we check if that file has the same md5, and avoid copying if so.
This won't merge identical content that has separate names, but instances
where users need that are rare.
2011-04-28 09:23:56 +09:00
Damien Elmes
9c247f45bd remove q/a cache, tags in fields, rewrite remaining ids, more
Anki used random 64bit IDs for cards, facts and fields. This had some nice
properties:
- merging data in syncs and imports was simply a matter of copying each way,
  as conflicts were astronomically unlikely
- it made it easy to identify identical cards and prevent them from being
  reimported
But there were some negatives too:
- they're more expensive to store
- javascript can't handle numbers > 2**53, which means AnkiMobile, iAnki and
  so on have to treat the ids as strings, which is slow
- simply copying data in a sync or import can lead to corruption, as while a
  duplicate id indicates the data was originally the same, it may have
  diverged. A more intelligent approach is necessary.
- sqlite was sorting the fields table based on the id, which meant the fields
  were spread across the table, and costly to fetch

So instead, we'll move to incremental ids. In the case of model changes we'll
declare that a schema change and force a full sync to avoid having to deal
with conflicts, and in the case of cards and facts, we'll need to update the
ids on one end to merge. Identical cards can be detected by checking to see if
their id is the same and their creation time is the same.

Creation time has been added back to cards and facts because it's necessary
for sync conflict merging. That means facts.pos is not required.

The graves table has been removed. It's not necessary for schema related
changes, and dead cards/facts can be represented as a card with queue=-4 and
created=0. Because we will record schema modification time and can ensure a
full sync propagates to all endpoints, it means we can remove the dead
cards/facts on schema change.

Tags have been removed from the facts table and are represented as a field
with ord=-1 and fmid=0. Combined with the locality improvement for fields, it
means that fetching fields is not much more expensive than using the q/a
cache.

Because of the above, removing the q/a cache is a possibility now. The q and a
columns on cards has been dropped. It will still be necessary to render the
q/a on fact add/edit, since we need to record media references. It would be
nice to avoid this in the future. Perhaps one way would be the ability to
assign a type to fields, like "image", "audio", or "latex". LaTeX needs
special consider anyway, as it was being rendered into the q/a cache.
2011-04-28 09:23:53 +09:00
Damien Elmes
9421a037f6 remove self explanatory module docstrings; strip trailing whitespace 2011-04-28 09:21:07 +09:00
Damien Elmes
04babfb102 if latex didn't run, prompt user to install 2011-01-31 13:00:11 +09:00
Damien Elmes
be8eec52bc make sure latex.py works indepent of gui 2011-01-26 15:06:51 +09:00
Damien Elmes
6071f8e209 include latex in alt tags of generated image 2011-01-26 13:01:12 +09:00
Damien Elmes
3fe6167d7f Revert "temp hack to prevent latex generation on ankiweb"
This reverts commit a334f839b8.

fixed on the server side now
2011-01-13 05:25:20 +09:00
Damien Elmes
a334f839b8 temp hack to prevent latex generation on ankiweb 2011-01-12 20:36:12 +09:00
Damien Elmes
50622a3127 encode latex after everything else 2010-12-22 08:06:44 +09:00
Damien Elmes
58b20b0626 make sure subprocess is available so we can set startupinfo 2010-12-11 18:36:01 +09:00
Damien Elmes
70eb44bce2 latex improvements
- move latex preamble into a deck var and include amsmath by default
- include the pre/postamble in the hash, so changes to the preamble result in
  newly generated images
2010-12-11 02:05:00 +09:00
Damien Elmes
b0f300bb74 fix latex generation bug caused my mediaDir() always chdiring now 2010-12-11 01:46:29 +09:00
Damien Elmes
4d2d9eab81 generate latex at fact modification, not review
- latex now slots in to the formatQA hook to render images in the q/a
- moved call() to utils
- cache/uncache latex have been obsoleted. User can delete manually, and
  images will be regenerated with a DB check
2010-12-11 01:40:49 +09:00
Damien Elmes
4a35dbe6b2 python2.7/win32 fix for latex 2010-11-12 13:05:43 +09:00
Damien Elmes
5fe42791c3 use relative path in latex generation 2010-07-26 17:14:49 +09:00
Damien Elmes
095ac330b5 fix first-time latex generation in a deck with no media dir 2010-02-01 03:33:13 +09:00
Damien Elmes
bf35112bd0 improve latex error message 2010-01-12 04:38:44 +09:00
Damien Elmes
11c1e7799b use relative paths in latex as the path may contain foreign chars 2009-09-26 05:47:52 +09:00
Damien Elmes
13a14e498c increase mod in delete 2009-07-08 12:29:09 +09:00
Damien Elmes
50103693d1 add progress to cache/uncache 2009-07-08 12:28:48 +09:00
Damien Elmes
95d6ba64ab fix uncache latex 2009-07-08 12:24:25 +09:00
Damien Elmes
6f27ae52cc revert to old style file-only latex handling 2009-07-08 12:20:56 +09:00
Damien Elmes
6af560da9a make sure to set ret if wait=False 2009-03-19 11:06:53 +09:00
Damien Elmes
66cda18a69 fix call() 2009-03-15 06:41:53 +09:00
Damien Elmes
df3185ab0f add wait kwarg to call() 2009-03-15 06:36:19 +09:00
Damien Elmes
75d6123dc3 identify temp files as anki, quiet lame 2009-01-17 16:29:45 +09:00
Damien Elmes
b161d6e485 add option to avoid building latex 2008-12-24 15:48:54 +09:00
Damien Elmes
3b3fef4ebc refactor latex into media support 2008-12-23 18:00:12 +09:00
Damien Elmes
6a21be9d19 refactor latex handling 2008-12-23 16:24:06 +09:00