Anki Forums

New line break handling

I recently updated to 2.1.42 from a version installed just a few months earlier (I think it may have been 2.1.38). I am disappointed to find that line break handling has been changed in an unfortunately unhelpful way.

To be precise, I am talking about using the return key whilst typing in a field on a note, whether when adding a new note or when editing a note in the browse window. Formerly, typing a return closed the current <div> and opened a new <div>, but now it simply inserts a <br>. This is a problem, because a <br> does not start a new element, but rather it is akin to a forced line break rather than a carriage break in the publishing world.

The consequence of this change is that each next paragraph is not really a new paragraph, and so block-level CSS properties no longer work as intended, such as text-indent, margin, and padding. For example, if I type three paragraphs, separating each with the return key (as we are used to doing), only the first is indented, because under this new handling the three paragraphs are a single block element.

I beg you to reconsider this change. For the moment I must be more heavy-handed with customizing the HTML for each note, and that is a big time drain for basic note entry. I recognize there are times when a forced line break rather than carriage return would be desired, but the standard implementation is to use shift-return when a forced line break is desired. Please consider implementing a more standard approach. In this regard, the previous implementation was quite superior.

In the current Anki, I am not sure how to actually type distinct paragraphs without directly editing the HTML. Is there something I am missing?

Divs cause their own problems, so I’m not sure about switching back to the old behaviour, but perhaps we could make it optional.

@hengiesel is changes to onKey() and onKeyUp() based on a flag all that would be required here?

@dae Yes. However I would like to look into a nicer / fuller solution. Give me some time to prepare a PR :slight_smile:

@garretm3
Could you show us, how you apply text-indent / margin / etc. to the block elements? Do you do it through the template CSS?

1 Like

Thank you, both of you, for considering.

@hengiesel No problem. Below is a screenshot example of a card where I make use of text-indent. In poetic sections, each poetic line is a paragraph of its own (the <div> that was automatically created with the return key in previous versions). When a single poetic line is too long to display in the column, the continuation is displayed inset (I’m sure you’ve seen these before in various types of poetic or verse settings).

In the previous versions of Anki, I could type or paste the text and type returns after each line. Then I would edit the HTML for that note and simply wrap all the parts of a card that were poetry inside a single <div class='poetry'> that I would add myself. Adding that additional div was the only HTML editing I would need to do on a per card basis. The rest is handled by the card template, notably:

.poetry {
	text-indent: -20px;
	padding-left: 20px;
}

You can separate your text into new divs in the template. Just split them by <br>:

<div id="content" class="hidden">{{Front}}</div>

<div id="output" class="poetry"></div>

<script>
   let output = document.getElementById("output")

   for (item of document.getElementById("content").innerHTML.split("<br>")) {
      let paragraph = document.createElement("div")
      paragraph.innerHTML = item
      output.appendChild(paragraph)
   }
</script>

Input

"Behold, I have created the blacksmith<br>
Who blows the coals in the fire,<br>
Who brings forth an instrument for his work;<br>
And I have created the spoiler to destroy.<br>
No weapon formed against you shall prosper<br>
And every tongue which rises against you in judgement<br>
You shall condemn.<br>
This is the heritage of the servants of the Lord,<br>
And their righteousness is from Me,"<br>
Says the Lord.

Output

image

2 Likes

Everyone has their own preferences, but I was very happy when Anki desktop started using <br> instead of <div> as <br> works much better for my decks. So my vote is to keep <br> !

Cheers, and no disrepect to the OP, just stating my preference!

1 Like