Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for markdown in heading cells when they are nbconverted. #3576

Merged
merged 5 commits into from Jul 9, 2013
Merged

Added support for markdown in heading cells when they are nbconverted. #3576

merged 5 commits into from Jul 9, 2013

Conversation

damianavila
Copy link
Member

@minrk as posted a PR where provides the possibility to write markdown in heading cells: #3531

@Carreau has pointed out the need of a counterpart in the nbconvert machinery.

@jakobgager and @jdfreder have pointed out that the latex exporter already supported markdown in heading.

So, I have made some little changes for the remaining basic templates: basichtml, rst, markdown (python tpl don't need changes) to cover this issue from the nbconvert machinery point of view.

Damián.

@@ -61,7 +61,7 @@ $$

{% block headingcell scoped %}

{{ '#' * cell.level }} {{ cell.source}}
{{ '#' * cell.level }} {{ cell.source | wrap(80)}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does the wrap 80 behave on more than 80 char title ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same way than with other text... it is probably redundant because it is no sense to have a title with more than 80 char at least you are working in the academia... hehe... joke aside, I think we need to wrap the tile for deal with longer ones...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my problem is :

#  if this is a really long long title in markdown

this will probably not be...

#  if this is a really long
long title in markdown

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you are right about that... maybe is better not to call wrap in this case...
I prefer to have consistency in the title... I will delete this call of the wrap function.
Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jinja2 has a built-in wordwrap filter which support the definition of wrapstrings. If I understand the docs correctly you might be able to apply this filter here, like {{ cell.source | wordwrap(80, False, '\n'+'#' * cell.level)}}
Ok, it is some rude workaround, but should be possible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, let me try it...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could even replace our wrap filter totally I guess !

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, it works great... but I added a whitespace to the function to be rendered correctly, if not present we have the text immediately next to # and it will be not rendered OK by a lot of markdown parsers:
{{ cell.source | wordwrap(80, False, '\n'+'#' * cell.level+' ')}}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great that it worked!

@Carreau
Copy link
Member

Carreau commented Jul 8, 2013

+2 (+1, +1 because I like nbconverted )

nbconverting (verb): IPython conversion process. Example "He was a matlab guy, but he as recently been nbconverted to IPython."

@damianavila
Copy link
Member Author

HeHe... From your definition, "nbconverted to IPython" is redundant...

Example "He was a matlab guy, but he as recently been nbconverted." That's all... HeHe

As you with iPtyhon vs. IPython campaign... I have to start my own campaign with the nbconvert verb... JaJa

@@ -61,7 +61,7 @@ $$

{% block headingcell scoped %}

{{ '#' * cell.level }} {{ cell.source}}
{{ '#' * cell.level }} {{ cell.source | wordwrap(80, False, '\n'+'#' * cell.level+' ')}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would kill the wordwrap here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and... why? if we have a very long title it would be nice to have it wraped.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tools that auto hard-wrap without user input bug me, but you can leave this if you want.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand you, but if we are already wrapping inside markdown cells, I think we have to be consistent and wrap also inside the headers cells... or not wrap anything... If I have to choose, I prefer to wrap it all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consistency argument wins, original comment withdrawn.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Real question is markdown interpretation is the following one or more title

## Am I a nice
## multiline title or
## 4 titles without
## any text ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(definitively 4 titles if I past that in a MD cell in notebook.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay then, original comment reinstated, do not wrap this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, you convinced me... I will not wrap the headers.
Updating the PR...

@Carreau
Copy link
Member

Carreau commented Jul 9, 2013

+1 then :-)

Carreau added a commit that referenced this pull request Jul 9, 2013
Added support for markdown in heading cells when they are nbconverted.
@Carreau Carreau merged commit 0fe886f into ipython:master Jul 9, 2013
@damianavila damianavila deleted the header_markdown branch July 9, 2013 16:30
@damianavila
Copy link
Member Author

Thanks!

@jakobgager jakobgager mentioned this pull request Jul 10, 2013
7 tasks
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
Added support for markdown in heading cells when they are nbconverted.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants