2

I would like to convert an ipython notebook to mediawiki markup. I had two ideas how to do that:

  1. Customize an export for the nbconvert tool.
  2. Export to LaTeX first and then use pandoc to convert it to mediawiki markup.

I couldn't find anything on the first option. The problem for the second option is that LaTeX output puts in a lot of custom commands which are not converted into <source lang='python'> ... </source> tags correctly. Does anybody have a good idea?

fabee
  • 515
  • 1
  • 5
  • 14

1 Answers1

3

you can probably pitch-in in issue 4058 nbconvert: Wikipedia (mediawiki) output. We'll be happy to guide you if you want to learn how to write an exporter for nbconvert.

You will basically need to write template. For example, heading in markdow are generated with :

{% block headingcell scoped %}
{{ '#' * cell.level }} {{ cell.source | replace('\n', ' ') }}
{% endblock headingcell %}

So mediawiki will probably be

{% block headingcell scoped %}
{{ '=' * cell.level }}{{ cell.source | replace('\n', ' ') }}{{ '=' * cell.level }}
{% endblock headingcell %}

One just need to write the all template.

We of course need to write more docs on how to extend nbconvert if you want to help with that, we'll happy to help too.

Matt
  • 27,170
  • 6
  • 80
  • 74
  • Thanks for your answer. To me it seems that writing an exporter or a template is not straightforward without any further documentation. Since I am a bit short in time I used a quick hack (basically use the basic latex output of nbconvert, use pandoc to transform it into mediawiki, and then use sed for a few replacements to make it nice). I'd like to help but I don't think I will find the time to dig into the topic at the moment. As soon as there is more docs on the exporter and the templates, I will probably try to write an exporter for mediawiki and then I am more than happy to share. – fabee Sep 30 '13 at 16:36
  • Exporter are not **hard** to write, but it's mainly a do-ocracy, things are mostly done by people that need it. Sadly this generally also apply to docs. Docs are not written until API is stable, and API does not stabilize until we get enough feedback, but we have feedback only when people can use the feature, that is to say when there is docs... Any way, we'll be happy to see you make a PR even if it is for a draft of implementation of mediawiki converter that does half the job. – Matt Oct 01 '13 at 14:21
  • Hmm, if I'd like to write the exporter now, where would be the best place to read up on a few things? Or do I just need to look into existing exporters? – fabee Oct 02 '13 at 07:58
  • Have a look at ipython/ipython-in-depth and maybe [this](http://nbviewer.ipython.org/urls/raw.github.com/Carreau/posts/master/06-NBconvert-Doc-Draft.ipynb) but both will be out of date on IPython dev version. I would suggest looking at markdown converter. Even if you just try to do something and make an unfinished PR we can give you pointer on how to do thing directly on the ongoing pull-request. – Matt Oct 02 '13 at 11:38