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

@ -87,12 +87,12 @@ paragraphs
<p>
</p>
<p>
whitespace is honored and not removed (but is not displayed because that&#39;s how html works by default)
it can be made visible using css (e.g. <code class="verbatim">white-space: pre</code>).
</p>
</li>
</ul>
<p>
also whitespace is not significant
and superfluous whitespace (at the beginning of the line) is removed
</p>
</blockquote>
<script>
console.log("Hello World!")
@ -134,11 +134,58 @@ list item 2
<p>
#+END_EXAMPLE
</p>
<p>
#+BEGIN_QUOTE
</p>
<blockquote>
<pre class="example">
#+END_QUOTE
</pre>
</blockquote>
</li>
<li>
<p>
verse blocks
</p>
<ul>
<li>
<p>
emacs / ox-hugo rendering
</p>
<p class="verse">
Great clouds overhead<br />
Tiny black birds rise and fall<br />
Snow covers Emacs<br />
<br />
&nbsp;&nbsp;&nbsp;---AlexSchroeder<br />
</p>
</li>
<li>
<p>
go-org rendering
</p>
<div class="src src-html">
<div class="highlight">
<pre>
&lt;style&gt;
.verse-block p { white-space: pre; }
.verse-block p + p { margin: 0; }
&lt;/style&gt;
</pre>
</div>
</div>
<style>
.verse-block p { white-space: pre; }
.verse-block p + p { margin: 0; }
</style>
<div class="verse-block">
<p>
Great clouds overhead
Tiny black birds rise and fall
Snow covers Emacs
</p>
<p>
—AlexSchroeder
</p>
</div>
</li>
</ul>
</li>
</ul>

View file

@ -45,9 +45,8 @@ blocks like the quote block parse their content and can contain
- paragraphs
- ...
also whitespace is not significant
and superfluous whitespace (at the beginning of the line) is removed
whitespace is honored and not removed (but is not displayed because that's how html works by default)
it can be made visible using css (e.g. =white-space: pre=).
#+END_QUOTE
#+BEGIN_EXPORT html
@ -76,3 +75,38 @@ this unindented line is outside of the list item
#+BEGIN_EXAMPLE
#+END_QUOTE
#+END_EXAMPLE
#+END_QUOTE
- verse blocks
- emacs / ox-hugo rendering
#+BEGIN_EXPORT html
<p class="verse">
Great clouds overhead<br />
Tiny black birds rise and fall<br />
Snow covers Emacs<br />
<br />
&nbsp;&nbsp;&nbsp;---AlexSchroeder<br />
</p>
#+END_EXPORT
- go-org rendering
#+BEGIN_SRC html
<style>
.verse-block p { white-space: pre; }
.verse-block p + p { margin: 0; }
</style>
#+END_SRC
#+BEGIN_EXPORT html
<style>
.verse-block p { white-space: pre; }
.verse-block p + p { margin: 0; }
</style>
#+END_EXPORT
#+BEGIN_VERSE
Great clouds overhead
Tiny black birds rise and fall
Snow covers Emacs
---AlexSchroeder
#+END_VERSE

View file

@ -45,9 +45,8 @@ blocks like the quote block parse their content and can contain
- paragraphs
- ...
also whitespace is not significant
and superfluous whitespace (at the beginning of the line) is removed
whitespace is honored and not removed (but is not displayed because that's how html works by default)
it can be made visible using css (e.g. =white-space: pre=).
#+END_QUOTE
#+BEGIN_EXPORT html
@ -76,3 +75,38 @@ this unindented line is outside of the list item
#+BEGIN_EXAMPLE
#+END_QUOTE
#+END_EXAMPLE
#+END_QUOTE
- verse blocks
- emacs / ox-hugo rendering
#+BEGIN_EXPORT html
<p class="verse">
Great clouds overhead<br />
Tiny black birds rise and fall<br />
Snow covers Emacs<br />
<br />
&nbsp;&nbsp;&nbsp;---AlexSchroeder<br />
</p>
#+END_EXPORT
- go-org rendering
#+BEGIN_SRC html
<style>
.verse-block p { white-space: pre; }
.verse-block p + p { margin: 0; }
</style>
#+END_SRC
#+BEGIN_EXPORT html
<style>
.verse-block p { white-space: pre; }
.verse-block p + p { margin: 0; }
</style>
#+END_EXPORT
#+BEGIN_VERSE
Great clouds overhead
Tiny black birds rise and fall
Snow covers Emacs
---AlexSchroeder
#+END_VERSE

View file

@ -32,10 +32,10 @@
descriptive lists
- [ ] term :: details
continued details
continued details
- [ ] details without a term
- [X] term ::
details on a new line
details on a new line
- term ::
details on a new line (with an empty line in between)