diff --git a/compile_server/app/templates/readerpage.html b/compile_server/app/templates/readerpage.html index b86c43b..4fbac0d 100644 --- a/compile_server/app/templates/readerpage.html +++ b/compile_server/app/templates/readerpage.html @@ -1,6 +1,7 @@ {% extends 'book_base.html' %} {% load markdown_filter %} +{% load rst_filter %} {% block sidebar %} - {{ content|markdownify|safe }} + {% if mdcontent %} + {{ mdcontent|markdownify|safe }} + {% elif rstcontent %} + {{ rstcontent|rstify|safe }} + {% endif %} + {% endblock%} \ No newline at end of file diff --git a/compile_server/app/templatetags/rst_filter.py b/compile_server/app/templatetags/rst_filter.py new file mode 100644 index 0000000..d174de3 --- /dev/null +++ b/compile_server/app/templatetags/rst_filter.py @@ -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'] diff --git a/compile_server/app/views.py b/compile_server/app/views.py index d8a8403..aec55f3 100644 --- a/compile_server/app/views.py +++ b/compile_server/app/views.py @@ -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) diff --git a/resources/books/Ada_For_The_C_Developer/pages/part1-chapter1.md b/resources/books/Ada_For_The_C_Developer/pages/part1-chapter1.md index 03420af..4056170 100644 --- a/resources/books/Ada_For_The_C_Developer/pages/part1-chapter1.md +++ b/resources/books/Ada_For_The_C_Developer/pages/part1-chapter1.md @@ -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. diff --git a/resources/books/Ada_For_The_C_Developer/pages/part1-chapter2.rst b/resources/books/Ada_For_The_C_Developer/pages/part1-chapter2.rst new file mode 100644 index 0000000..cf6254f --- /dev/null +++ b/resources/books/Ada_For_The_C_Developer/pages/part1-chapter2.rst @@ -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, let’s 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. Let’s now compare this to the Ada design +principals: + +:: + + * Stuff + * More Stuff + * This is a place holder + +Let’s look at some Ada. + +-------------- + +Test +~~~~ + +This is a test of inserting code blocks in the markdown + +.. raw:: html + +
+ +.. raw:: html + +
+ +-------------- + +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. \ No newline at end of file