Preserve whitespace (indentation) inside paragraphs

We want original whitespace to be rendered in some cases (e.g. verse
blocks). This requires information about the original whitespace to be
preserved during paragraph parsing. As html ignores (collapses) whitespace by
default we don't have to adapt the html writer and can just selectively enable
rendering of the preseverved whitespace wherever we want it using
css (white-space: pre).

To differentiate meaningful whitespace from document structure based
indentation (i.e. list item base indentation) we need to introduce
document.baseLvl. A paragraph by itself does not have enough information to
differentiate both kinds of whitespace and needs this information as context
[0].

As we're already touching list indentation i went along and improved (fixed?)
descriptive list item indentation rendering in the org writer (it should match
emacs tab behavior - i.e. indent subsequent lines up to the `:: `).

[0] e.g. list items can contain blank lines - a paragraph starting with a blank
line would not know that it is part of a list item / has a base indentation -
the blank line would suggest a baseLvl of 0.
This commit is contained in:
Niklas Fasching 2019-12-09 19:37:39 +01:00
parent 466903d3ac
commit b61e49eb85
8 changed files with 141 additions and 19 deletions

View file

@ -196,11 +196,12 @@ func (w *OrgWriter) WriteListItem(li ListItem) {
}
func (w *OrgWriter) WriteDescriptiveListItem(di DescriptiveListItem) {
indent := w.indent + strings.Repeat(" ", len(di.Bullet)+1)
w.WriteString(w.indent + di.Bullet)
if di.Status != "" {
w.WriteString(fmt.Sprintf(" [%s]", di.Status))
indent = indent + strings.Repeat(" ", len(di.Status)+3)
}
indent := w.indent + strings.Repeat(" ", len(di.Bullet)+1)
if len(di.Term) != 0 {
term := w.WriteNodesAsString(di.Term...)
w.WriteString(" " + term + " ::")