Skip to content

Instantly share code, notes, and snippets.

@tonyfast
Forked from anonymous/Disqus Magic.ipynb
Last active August 29, 2015 14:22
Show Gist options
  • Save tonyfast/eeed58903980e863559c to your computer and use it in GitHub Desktop.
Save tonyfast/eeed58903980e863559c to your computer and use it in GitHub Desktop.
Disqus Magic for IPython notebooks
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from jinja2 import Template
from IPython.display import (
display,
HTML,
)
from IPython.core import magic
tmpl = Template("""
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = "{{ shortname }}";
{% if title %}
var disqus_title = "{{ title }}";
{% endif %}
</script>
<script src="https://{{ shortname }}.disqus.com/embed.js" async="true">
</script>
<noscript>
Please enable JavaScript to view the
<a href="https://disqus.com/?ref_noscript" rel="nofollow">
comments powered by Disqus.
</a>
</noscript>
""")
@magic.magics_class
class DisqusMagics(magic.Magics):
@magic.line_magic
def disqus(self, line):
line = line.strip().split(" ", 1)
title = line[1] if len(line) > 1 else None
display(HTML(tmpl.render(shortname=line[0],
title=title)))
def load_ipython_extension(ip):
ip.register_magics(DisqusMagics)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment