Commit graph

40 commits

Author SHA1 Message Date
Damien Elmes
41a47fcf01 fix some clippy lints 2020-08-26 19:02:56 +10:00
Damien Elmes
54bb782809 handle <%foo%> inside {{#conditional}}
https://forums.ankiweb.net/t/the-latest-version-of-ios-cannot-display-the-template-normally/2142
2020-08-12 19:28:26 +10:00
Damien Elmes
99140fb189 fix conditional negation being lost on field rename
https://forums.ankiweb.net/t/anki-force-changes-all-to/1694
2020-08-02 10:09:24 +10:00
Damien Elmes
8dcb7fd2ba check for empty cloze cards when rendering as well 2020-05-14 21:56:45 +10:00
Damien Elmes
6dd31341f8 add "fill empty" checkbox 2020-05-14 20:58:45 +10:00
Damien Elmes
4815010da0 don't hide static template text when card is empty 2020-05-13 11:17:44 +10:00
Damien Elmes
14c0a5891b fetch template and note fields in backend during normal card render
Saves having to serialize the note fields and q/a templates, which
is particularly a win when rendering question/answer in the browse
screen.

Also some work towards being able to preview notes without having to
commit them to the database.
2020-05-13 10:38:49 +10:00
Damien Elmes
2e971da79e properly handle negated conditionals outside of req generation 2020-05-12 21:13:34 +10:00
Damien Elmes
7106af61ff update template on field removals as well 2020-05-12 21:13:33 +10:00
Damien Elmes
549f98340a update template when fields renamed 2020-05-12 21:13:33 +10:00
Damien Elmes
8dad5cc3ab switch to owned strings in ParsedTemplate
will make it easier to cache the parsed results in the future,
and handle field renames & other transformations
2020-05-12 21:13:33 +10:00
Damien Elmes
3af6905ad0 fix infinite loop on unclosed {{/<% 2020-05-12 21:13:33 +10:00
Damien Elmes
da09c7781e handle legacy syntax in parser instead of modifying original template
Simplifies things for the caller, and ensures legacy handling doesn't
get accidentally forgotten
2020-05-12 21:13:33 +10:00
Damien Elmes
39070abb89 drop type answer requirement special case
While it makes no sense to have the typing box on the front without
another non-empty field, "the front of this card is empty" when
a typing box is on the template seems to be confusing some users, so
it is clearer to show them the box.
2020-04-29 21:29:16 +10:00
Damien Elmes
8f427dbbd7 FString -> TR 2020-04-01 18:16:43 +10:00
Damien Elmes
42781a696f remove some unused imports 2020-02-29 15:21:11 +10:00
Damien Elmes
0d1a30c6d8 rework Fluent handling
- all .ftl files for a language are concatenated into a single file
at build time
- all languages are included in the binary
- external ftl files placed in the ftl folder can override the
built-in definitions
- constants are automatically generated for each string key
- dropped the separate StringsGroup enum
2020-02-23 13:22:50 +10:00
Damien Elmes
78ffde32e1 expose StringsGroup enum in protobuf 2020-02-17 08:40:17 +10:00
Damien Elmes
ba0bc3086c move empty card check into template code 2020-02-17 08:40:17 +10:00
Damien Elmes
0738ff46b6 make template errors translatable 2020-02-17 08:40:17 +10:00
Damien Elmes
8f34c720b8 remove redundant test_ prefix 2020-02-17 08:40:17 +10:00
Damien Elmes
391a58077a show which side the template error occurred on 2020-02-08 11:54:08 +10:00
Damien Elmes
fc3570c949 clearer error when closing tags transposed 2020-02-08 10:32:34 +10:00
Damien Elmes
46c6a7f7e4 extract and flag AV tags as part of the render process
We can now show replay buttons for the audio contained in {{FrontSide}}
without having to play it again when the answer is shown.

The template code now always defers FrontSide rendering, as it wasn't
a big saving, and meant the logic had to be implemented twice.
2020-01-24 11:06:11 +10:00
Damien Elmes
faaecdb2c7 look through negated conditionals instead of just ignoring them
https://anki.tenderapp.com/discussions/ankidesktop/38220-bug-in-2119-regarding-computation-of-req
2020-01-23 17:27:07 +10:00
Damien Elmes
548ed31ef7 add a simple TTS field filter
This simply wraps the field in extra text that the frontend will
deal with. Also added some helpers for extracting and stripping
audio and TTS tags from the rendered text.
2020-01-20 19:16:24 +10:00
Damien Elmes
21098c43b5 save filters and field name separately 2020-01-16 18:47:21 +10:00
Damien Elmes
2e8bdb580a show missing field errors in the same way as the other errors 2020-01-16 18:47:21 +10:00
Damien Elmes
52bd10063e more useful template error message 2020-01-16 18:47:21 +10:00
Damien Elmes
ce77759177 allow an empty field name if filters are provided
This is to make it easier for add-ons to provide extra content that
degrades nicely on platforms that don't have the add-on.
2020-01-15 18:48:23 +10:00
Damien Elmes
8eceedd2e5 more template rendering tweaks
- The front and back are rendered in one call now. If the front
side contains no custom filters, we can bake {{FrontSide}} into the
rear side. If it did contain custom filters, we return the partially
complete rear template instead, and the calling code can inject
the FrontSide in after it has been fully rendered.

- Instead of modifying "cloze" into something like "cq-2", the card
ordinal and whether we're rendering the question or answer are now
passed in to the rendering filters as context.

- The Rust code doesn't need to support filter names split on '-'
anymore.

- Drop the "Show" part of hint descriptions so i18n support can be
deferred.

- Ignore blank filter names caused by user using two colons instead
of one.

- Fixed hint field and text transposition.
2020-01-12 21:34:07 +10:00
Damien Elmes
524a27dd08 ignore extra { chars in replacement
This will still show a trailing } with {{{field}}}, but will at
least show the field content instead of 'unknown field'.
2020-01-11 18:02:24 +10:00
Damien Elmes
d671f091ff type: and hint: support
We may need to keep handling hints in the Python code for now until
i18n is sorted out.
2020-01-11 09:35:41 +10:00
Damien Elmes
3510eb1861 add ruby filters 2020-01-10 21:04:52 +10:00
Damien Elmes
ca6793c940 add copyright headers to some files 2020-01-10 21:00:48 +10:00
Damien Elmes
3a14c247c8 replace fields and apply standard filters in rslib
The filters still need to be implemented.
2020-01-10 18:02:26 +10:00
Damien Elmes
8f3df55da2 flatten->render; pass field content in
This is paving the way to move the standard filters into Rust.

Non-empty fields are now determined in Rust, using a single regex
instead of the overkill stripHTMLMedia(). The old implementation
has been moved into the Pystache code for now.
2020-01-10 14:59:29 +10:00
Damien Elmes
c0604c596b ignore template closing characters outside of a tag 2020-01-08 20:29:04 +10:00
Damien Elmes
520275bea3 handle conditional replacement in Rust
This extends the existing Rust code to handle conditional
replacement. The replacement of field names and filters to text
remains in Python, so that add-ons can still define their own
field modifiers.

The code is currently running the old Pystache rendering and the
new implementation in parallel, and will print a message to the
console if they don't match. If you notice any problems, please
let me know.
2020-01-08 20:28:04 +10:00
Damien Elmes
2a00e0a6b0 tweaking the folder names again
hopefully that's the last of it
2020-01-03 07:48:38 +10:00
Renamed from lib-rust/src/template.rs (Browse further)