Skip to content

Commit

Permalink
adding matheatical expressions support in markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
l-dfa committed Oct 26, 2018
1 parent b6bbb65 commit aa62693
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
7 changes: 7 additions & 0 deletions rstsite/rstblog/templates/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,10 @@
</div>
</div>
{% endblock %}

{% block javascript %}
{% if markup == "markdown" %}
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-MML-AM_CHTML' async></script>
{% endif %}
{% endblock %}

23 changes: 17 additions & 6 deletions rstsite/rstblog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ def show(request, slug=''):
# preaparing translations as [(language, slug), (language, slug), ...]
trans = article.get_translations()
translations = [(LANGUAGES.get(t.language), t.slug, t.language) for t in trans]
markup = ''

# preparing article content as html
try:
Expand All @@ -371,17 +372,26 @@ def show(request, slug=''):
content = file_content[:]
if ( article.markup == 'restructuredtext'
or p.suffix == SUFFIX.reST ):
markup = 'restructuredtext'
content = rstcontent2html(content)
elif ( article.markup == 'html'
or p.suffix == SUFFIX.html ):
pass
markup = 'html'
elif ( article.markup == 'markdown'
or p.suffix == SUFFIX.markdown ):
content = markdown(content, extensions=[
'markdown.extensions.tables',
'markdown.extensions.footnotes',])
markup = 'markdown'
content = markdown(
content,
extensions=[
'markdown.extensions.tables',
'markdown.extensions.footnotes',
'mdx_math', ],
extension_configs = {
'mdx_math': {
'enable_dollar_delimiter': True, }, }
) # to manage math expressions using https://www.mathjax.org/ (pip install python-markdown-math); 2018-10-26 ldfa
else:
raise ValueError(f'{article.markup} is a markup language not supported yet')
raise ValueError(f'{article.markup} is a markup language not supported (yet)')
except:
raise Http404()

Expand All @@ -395,7 +405,8 @@ def show(request, slug=''):
data = { 'content': content,
'infos': infos,
'article': article,
'translations': translations, }
'translations': translations,
'markup': markup, }

return render( request, 'show.html', data, )

Expand Down
2 changes: 2 additions & 0 deletions rstsite/rstsite/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def siteconf(request):
'ABSTRACT': settings.RSTSITE.get('ABSTRACT', ''),
'WTITLE': settings.RSTSITE.get('WTITLE', ''),
'WSUBTITLE': settings.RSTSITE.get('WSUBTITLE', ''),
'WLICENSE': settings.RSTSITE.get('WLICENSE', ''),
'WLICENSEREF': settings.RSTSITE.get('WLICENSEREF', ''),
}
return cont

Expand Down

0 comments on commit aa62693

Please sign in to comment.