Skip to content

Commit

Permalink
Use alternate pattern match during field changes
Browse files Browse the repository at this point in the history
When a user renames or deletes a field, Anki tries to go through the
user's templates to substitute occurrences of that field name with its
new name or remove the field.

However, if the user has multiple Mustache placeholders on a single
line, this does not work as intended because the leading (.*) capture
group grabs the text in-between the two (or more) Mustache placeholders.

Examples:

    {{#Flag}}
        ...
    {{/Flag}}{{^Flag}}
        ...
    {{/Flag}}

or

    {{Front}} {{#Flag}}...{{/Flag}}

or

    {{Front}} Hello. {{Victim}}
  • Loading branch information
corpulentcoffee committed Dec 30, 2014
1 parent 11ea5d5 commit 643ec35
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion anki/models.py
Expand Up @@ -304,7 +304,7 @@ def move(fields, oldidx=oldidx):

def renameField(self, m, field, newName):
self.col.modSchema(check=True)
pat = r'{{(.*)([:#^/]|[^:#/^}][^:}]*?:|)%s}}'
pat = r'{{([^{}]*)([:#^/]|[^:#/^}][^:}]*?:|)%s}}'
def wrap(txt):
def repl(match):
return '{{' + match.group(1) + match.group(2) + txt + '}}'
Expand Down

0 comments on commit 643ec35

Please sign in to comment.