mirror of
https://github.com/ankitects/anki.git
synced 2025-09-22 16:02:23 -04:00
fix <br> remaining when image attached to empty field
This commit is contained in:
parent
5260e10f8f
commit
02145c7078
2 changed files with 9 additions and 4 deletions
|
@ -655,7 +655,7 @@ to a cloze type first, via Edit>Change Note Type."""
|
||||||
|
|
||||||
def addMedia(self, path, canDelete=False):
|
def addMedia(self, path, canDelete=False):
|
||||||
html = self._addMedia(path, canDelete)
|
html = self._addMedia(path, canDelete)
|
||||||
self.web.eval("setFormat('inserthtml', %s);" % json.dumps(html))
|
self.web.eval("insertHtmlRemovingInitialBR(%s);" % json.dumps(html))
|
||||||
|
|
||||||
def _addMedia(self, path, canDelete=False):
|
def _addMedia(self, path, canDelete=False):
|
||||||
"Add to media folder and return local img or sound tag."
|
"Add to media folder and return local img or sound tag."
|
||||||
|
|
|
@ -376,10 +376,10 @@ function hideDupes() {
|
||||||
$("#dupes").hide();
|
$("#dupes").hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
let pasteHTML = function(html, internal, extendedMode) {
|
/// If the field has only an empty br, remove it first.
|
||||||
html = filterHTML(html, internal, extendedMode);
|
let insertHtmlRemovingInitialBR = function(html: string) {
|
||||||
if (html !== "") {
|
if (html !== "") {
|
||||||
// remove trailing <br> in empty field
|
// remove <br> in empty field
|
||||||
if (currentField && currentField.innerHTML === "<br>") {
|
if (currentField && currentField.innerHTML === "<br>") {
|
||||||
currentField.innerHTML = "";
|
currentField.innerHTML = "";
|
||||||
}
|
}
|
||||||
|
@ -387,6 +387,11 @@ let pasteHTML = function(html, internal, extendedMode) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let pasteHTML = function(html, internal, extendedMode) {
|
||||||
|
html = filterHTML(html, internal, extendedMode);
|
||||||
|
insertHtmlRemovingInitialBR(html);
|
||||||
|
};
|
||||||
|
|
||||||
let filterHTML = function(html, internal, extendedMode) {
|
let filterHTML = function(html, internal, extendedMode) {
|
||||||
// wrap it in <top> as we aren't allowed to change top level elements
|
// wrap it in <top> as we aren't allowed to change top level elements
|
||||||
const top = $.parseHTML("<ankitop>" + html + "</ankitop>")[0] as Element;
|
const top = $.parseHTML("<ankitop>" + html + "</ankitop>")[0] as Element;
|
||||||
|
|
Loading…
Reference in a new issue