docnado icon indicating copy to clipboard operation
docnado copied to clipboard

WIP: Pull multiple articles into a single document via a special URL route

Open JohnHardy opened this issue 5 years ago • 1 comments

We have needed a couple of times to pull multiple articles into a single document. We did this previously by exporting all the relevant PDFs, and then concatenating them together. This sucked because it was slow and unweidly.

This PR adds a special URL http://localhost:5000/book/?page=setup/installation.md&page=setup/meta-data.md#setup_meta_data_md&authors=true&versions=1 that lets users specify ordered pages (via URL args or request body). This can be used to automatically generate reports / books.

Limitations:

Only applies the default "document" style via "book.html" template.

Todo before merge:

  • [ ] Code quality
  • [ ] Example script / documentation for how to create a book
  • [ ] Table of contents / page numbering?
  • [ ] Page Breaks

JohnHardy avatar Mar 08 '19 10:03 JohnHardy

The main problem is that the URLs are relative in the markdown and they will need to be transformed relative to the local page in the /book/ route, otherwise things links like images will not be found.

Doing this is pretty messy and will affect other features in a way that we can't easily test against at the moment. Before continuing the implementation, I think a refactor is needed to consolidate the codebase and improve the automated testing and markdown parser context.

def absoluteify_urls(self, url):
        """ Take a URL and make it absolute to the document being rendered.
        """
        path = os.path.join(self.markdown.page_root, urllib.request.url2pathname(url))
        path = path.replace(os.getcwd(), '')
        # TODO: swap the prefix `\docs\` with \w\ or whatever the URL route is.
        # TODO: convert into URL path `pathname2url`
        # Return the result

JohnHardy avatar Mar 08 '19 11:03 JohnHardy