Header wrapping - markdown

At the time, the following markup:

# OPERA
BELLISSIMA

Renders into <h1>OPERA</h1> followed by <p>BELLISSIMA</p>. It does not look to be possible to wrap headers in any way.

I am using markdown as a book transcription format, hence I would like to make line wrap match the original book being transcribed (in order to simplify proofreading), yet I would like to render all the text without any additional wrapping — just as with the normal paragraphs.

Is it possible to achieve these using python-markdown?

Asked Sep 26 '21 18:09
avatar georgthegreat
georgthegreat

6 Answer:

I did a brief research on the subject — it looks like there is no implementation which supports word wrapping in headers.

As original John Gruber's description does not say anything, this seems like a bug: as there is no blank line before the next line, it should not be considered as a new paragraph.

1
Answered Nov 04 '20 at 13:35
avatar  of georgthegreat
georgthegreat

You are correct that the original rules do not specifically state that headers cannot wrap. However, that is how the reference implementation behaves. And when the rules aren't clear, the behavior of the reference implementation controls.

Additionally, as this has been consistent behavior for many years now, there are many thousands of documents which do not have blank lines between headers and the content that follows them. Makes such a change would break all of those documents.

For the above reasons we will not be making any such change. Of course, you are welcome to alter the behavior in an extension if you want.

1
Answered Nov 04 '20 at 14:03
avatar  of waylan
waylan

Can this be done via configuration option of the Markdown class (at the time Markdown parser itself does not seem to be configurable — only extension do).

Of course I could copy-paste HashHeaderParser and alter it, but this does not seem the right thing to do.

1
Answered Nov 04 '20 at 14:18
avatar  of georgthegreat
georgthegreat

This would need to be done via an extension which provides a new BlockProcessor which replaces the HashHeaderProcessor.

1
Answered Nov 04 '20 at 14:26
avatar  of waylan
waylan

You can also always insert raw <br> into your header:

>>> markdown.markdown('## OPERA<br>BELLISSIMA')
'<h2>OPERA<br>BELLISSIMA</h2>'
1
Answered Nov 04 '20 at 17:13
avatar  of mitya57
mitya57

You can also always insert raw <br> into your header:

>>> markdown.markdown('## OPERA<br>BELLISSIMA')
'<h2>OPERA<br>BELLISSIMA</h2>'

This solves the reversed problem: I want the source to have the same layout at the original book.

I. e. compare the layout of this transcription: https://raw.githubusercontent.com/hda-technical/dancebooks/master/transcriptions/%5B1589%2C%20it%5D%20Prospero%20Lutij%20-%20Opera%20bellissima.md

with the layout of the original book: https://gallica.bnf.fr/ark:/12148/bpt6k3215756/f9.item

1
Answered Nov 04 '20 at 20:04
avatar  of georgthegreat
georgthegreat