Adding ability to parse restructured text in the same way as markdown.

This commit is contained in:
Robert Tice
2017-11-22 16:06:49 -05:00
parent 3d482364e1
commit 874b417886
5 changed files with 118 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
{% extends 'book_base.html' %}
{% load markdown_filter %}
{% load rst_filter %}
{% block sidebar %}
<nav id="sidebar">
@@ -61,6 +62,11 @@
</div>
</nav>
{{ content|markdownify|safe }}
{% if mdcontent %}
{{ mdcontent|markdownify|safe }}
{% elif rstcontent %}
{{ rstcontent|rstify|safe }}
{% endif %}
</div>
{% endblock%}

View File

@@ -0,0 +1,8 @@
from django import template
import docutils
register = template.Library()
@register.filter
def rstify(text):
return docutils.core.publish_parts(text, writer_name='html')['html_body']

View File

@@ -170,20 +170,27 @@ def book_router(request, book, part, chapter):
# load page, if part or chapter is out of range go to unknown page link
if inrange:
content_page = os.path.join(book_path,
mdcontent_page = os.path.join(book_path,
"pages",
"part%s-chapter%s.md" % (part, chapter))
rstcontent_page = os.path.join(book_path,
"pages",
"part%s-chapter%s.rst" % (part, chapter))
if os.path.isfile(content_page):
with open(content_page, 'r') as f:
htmldata['content'] = f.read()
# check for markdown version
if os.path.isfile(mdcontent_page):
with open(mdcontent_page, 'r') as f:
htmldata['mdcontent'] = f.read()
elif os.path.isfile(rstcontent_page):
with open(rstcontent_page, 'r') as f:
htmldata['rstcontent'] = f.read()
else:
with open(os.path.join(resources_base_path,
"under-construction.md")) as f:
htmldata['content'] = f.read()
htmldata['mdcontent'] = f.read()
else:
with open(os.path.join(resources_base_path,
"invalid-page.md")) as f:
htmldata['content'] = f.read()
htmldata['mdcontent'] = f.read()
return render(request, 'readerpage.html', htmldata)

View File

@@ -1,5 +1,7 @@
# So, what is this Ada thingy anyway?
(This page is md)
Since you are reading this, we will assume you are familiar with the ubiquitous programming language called C. Well, Ada is like C... except it has a fundamentally different approach to its design paradigms. To explain this further, let's look at the C99 Rationale document [1]. Specifically paragraph 15 labeled: **Keep the spirit of C**:
* Trust the programmer.

View File

@@ -0,0 +1,88 @@
So, what is this Ada thingy anyway?
===================================
(This page is rst)
Since you are reading this, we will assume you are familiar with the
ubiquitous programming language called C. Well, Ada is like C… except it
has a fundamentally different approach to its design paradigms. To
explain this further, lets look at the C99 Rationale document [1].
Specifically paragraph 15 labeled: **Keep the spirit of C**:
::
* Trust the programmer.
* Don't prevent the programmer from doing what needs to be done.
* Keep the language small and simple.
* Provide only one way to do an operation.
* Make it faast, even if it is not guaranteed to be portable.
These are the design guidelines that the designers of C use when
thinking about the language. Lets now compare this to the Ada design
principals:
::
* Stuff
* More Stuff
* This is a place holder
Lets look at some Ada.
--------------
Test
~~~~
This is a test of inserting code blocks in the markdown
.. raw:: html
<div example_editor="Hello World">
.. raw:: html
</div>
--------------
Lorem Ipsum Dolor
-----------------
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum.
--------------
.. lorem-ipsum-dolor-1:
Lorem Ipsum Dolor
-----------------
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum.
--------------
.. lorem-ipsum-dolor-2:
Lorem Ipsum Dolor
~~~~~~~~~~~~~~~~~
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum.