Use alternate pattern match during field changes

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}}
This commit is contained in:
Dave Shifflett 2014-12-29 18:57:38 -06:00
parent 11ea5d5686
commit 643ec35449

View file

@ -304,7 +304,7 @@ and notes.mid = ? and cards.ord = ?""", m['id'], ord)
def renameField(self, m, field, newName): def renameField(self, m, field, newName):
self.col.modSchema(check=True) self.col.modSchema(check=True)
pat = r'{{(.*)([:#^/]|[^:#/^}][^:}]*?:|)%s}}' pat = r'{{([^{}]*)([:#^/]|[^:#/^}][^:}]*?:|)%s}}'
def wrap(txt): def wrap(txt):
def repl(match): def repl(match):
return '{{' + match.group(1) + match.group(2) + txt + '}}' return '{{' + match.group(1) + match.group(2) + txt + '}}'