Issue raised by @bollwyvl. The question is "how to customize how cells are split during Markdown => ipynb conversion"?
There are several ways of doing it; here's one.
By default, the current behavior is kept: the smallest cells are created (i.e. one for every new line \n\n, basically), using the observation that it's easier to merge than to split cells.
Then, there is a dedicated class, for example CellMerger, that is responsible for merging consecutive cells. It implements a method to_merge(cell0, cell_1) that takes as input two consecutive ipymd cells, and returns True or False. When converting from Markdown to ipynb, this class is called at the end of the conversion. It starts from the first cell, decides whether it should be merged with the next one, does the merge if necessary, and move to the next pair of cells, until the end. (probably this should only concern Markdown cells; a code cell will never be merged with a Markdown cell!)
Returning always True means that we'll end up with as few Markdown cells as possible (a single big cell if there's no code cell).
Returning always False means that the current behavior is kept.
In the middle, we can customize how cells should be created out of Markdown text. For example, decide that two Markdown cells should be merged if none starts with a header.
The default CellMerger should implement reasonable heuristics between the two extremes.
Another thing: it may be possible to force a split with something like a *** in Markdown, but I don't think it should be mandatory (i.e. not writing any *** should not result in a single big cell for the whole document!)
Issue raised by @bollwyvl. The question is "how to customize how cells are split during Markdown => ipynb conversion"?
There are several ways of doing it; here's one.
By default, the current behavior is kept: the smallest cells are created (i.e. one for every new line
\n\n, basically), using the observation that it's easier to merge than to split cells.Then, there is a dedicated class, for example
CellMerger, that is responsible for merging consecutive cells. It implements a methodto_merge(cell0, cell_1)that takes as input two consecutive ipymd cells, and returnsTrueorFalse. When converting from Markdown to ipynb, this class is called at the end of the conversion. It starts from the first cell, decides whether it should be merged with the next one, does the merge if necessary, and move to the next pair of cells, until the end. (probably this should only concern Markdown cells; a code cell will never be merged with a Markdown cell!)Returning always
Truemeans that we'll end up with as few Markdown cells as possible (a single big cell if there's no code cell).Returning always
Falsemeans that the current behavior is kept.In the middle, we can customize how cells should be created out of Markdown text. For example, decide that two Markdown cells should be merged if none starts with a header.
The default
CellMergershould implement reasonable heuristics between the two extremes.Another thing: it may be possible to force a split with something like a
***in Markdown, but I don't think it should be mandatory (i.e. not writing any***should not result in a single big cell for the whole document!)