fix <br> remaining when image attached to empty field
This commit is contained in:
parent
5260e10f8f
commit
02145c7078
@ -655,7 +655,7 @@ to a cloze type first, via Edit>Change Note Type."""
|
||||
|
||||
def addMedia(self, path, canDelete=False):
|
||||
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):
|
||||
"Add to media folder and return local img or sound tag."
|
||||
|
@ -376,10 +376,10 @@ function hideDupes() {
|
||||
$("#dupes").hide();
|
||||
}
|
||||
|
||||
let pasteHTML = function(html, internal, extendedMode) {
|
||||
html = filterHTML(html, internal, extendedMode);
|
||||
/// If the field has only an empty br, remove it first.
|
||||
let insertHtmlRemovingInitialBR = function(html: string) {
|
||||
if (html !== "") {
|
||||
// remove trailing <br> in empty field
|
||||
// remove <br> in empty field
|
||||
if (currentField && currentField.innerHTML === "<br>") {
|
||||
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) {
|
||||
// wrap it in <top> as we aren't allowed to change top level elements
|
||||
const top = $.parseHTML("<ankitop>" + html + "</ankitop>")[0] as Element;
|
||||
|
Loading…
Reference in New Issue
Block a user