Skip to content

Loading all Markdown in memory - #627

Closed
d0ugal wants to merge 2 commits into
mkdocs:masterfrom
d0ugal:refactor-markdown-loading
Closed

d0ugal wants to merge 2 commits into
mkdocs:masterfrom
d0ugal:refactor-markdown-loading

Conversation

@d0ugal

@d0ugal d0ugal commented Jun 12, 2015

Copy link
Copy Markdown
Contributor

This change updates the Markdown loading to load all the documents at startup. This gives us much more flexibility when we want to reference other Markdown files or use the metadata from a Markdown file earlier in the build.

Remaining tasks:

  • Fix a few test failures on older Python versions
  • Fix the code in a few places that is wonky. Commented on inline.
  • Add to release notes

Original text below the line.


This needs a bunch of works and it breaks loads of the tests, but it works quite well. It gets the page title from the Markdown if it isn't provided in the mkdocs.yml.

Feedback very welcome, it is a bit rough at the moment tho'

See #316

@d0ugal d0ugal added this to the 0.15.0 milestone Jun 12, 2015
@waylan

waylan commented Jun 12, 2015

Copy link
Copy Markdown
Contributor

Looks like a good start.

One thing that concerns me is that the Markdown is rendered to HTML too soon. If/when a plugin API is added, I anticipate a hook being provided prior to each page being built which means the HTML should not be rendered until build time. I realize that it is rendered early because that is how you are getting the meta-data for each page. And yes, that info should already be available before the pre-build hook.

Of course, those two things are in direct opposition to each other. However, I recommend that the Python-Markdown's Meta-Data Extension not be used. Instead extract the meta-data early (perhaps using docdata), and save the meta-data and the markdown source (with the meta-date removed) as two separate attributes in the Page instance. The way, the Markdown source can be used later to render the HTML just before building the page, but after the pre-build hook.

If you don't want to add another dependency, I give permission to include the relevant parts of docdata directly in MkdDocs. Or you are welcome to use some other implementation of your choice or creation.

An interesting side-affect will be that the code which calls Markdown will still be in build.py so you won't need to move the Markdown wrapper (leave it in build.py) and you won't need to update those tests (which are many of the currently failing tests).

@facelessuser

Copy link
Copy Markdown
Contributor

However, I recommend that the Python-Markdown's Meta-Data Extension not be used.

+1 to this. Personally, I have never found the meta extension to be all that useful as I want the meta data before I parse. Usually, by time I've parsed is too late for me to use the meta for what I want.

@d0ugal

d0ugal commented Jun 13, 2015

Copy link
Copy Markdown
Contributor Author

Great, I'm glad you both said this because I was struggling with it too. It did indeed feel a bit strange to render the Markdown so early.

If you don't want to add another dependency, I give permission to include the relevant parts of docdata directly in MkdDocs. Or you are welcome to use some other implementation of your choice or creation.

@waylan Great - thanks! I am a bit hesitant to include another dependency, just because of the effort recently we had to do to remove two (six and ghp-import). So I might take this approach, initially I'll try a prototype with the dependency and see how that goes.

@d0ugal
d0ugal force-pushed the refactor-markdown-loading branch 6 times, most recently from 1fb2bfe to a303fd1 Compare June 13, 2015 09:49
@d0ugal

d0ugal commented Jun 13, 2015

Copy link
Copy Markdown
Contributor Author

Updated. I think this generally does make much more sense. Unfortunately, most of the tests still break as they are broken due to how I changed the internal pages structure. This PR changes it so that we convert from string paths to page objects as soon as possible. The previous was was quite delayed and the tests took advantage of this to easily define a set of pages as a list of strings.

@d0ugal

d0ugal commented Jun 13, 2015

Copy link
Copy Markdown
Contributor Author

... and because we load the pages when we do now, it verifies they all exist. A bunch of tests have fake paths to markdown files because they never tested the build process. /me sighs

Comment thread mkdocs/build.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Within the template I would expect the html_content, toc, and meta to all be attributes of the page object. I realize that may involve so template refactoring and this is prototyping right now, but I think that is we're this needs to go.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree. In my previous version I had added it to the template, but left it available via the old names too to avoid updating all the templates at the same time.

@d0ugal d0ugal changed the title Initial experimentation with loading all Mardown in memory Initial experimentation with loading all Markdown in memory Jun 18, 2015
@d0ugal
d0ugal force-pushed the refactor-markdown-loading branch from 56b1fb6 to 1bd9aa7 Compare June 28, 2015 21:15
@d0ugal d0ugal changed the title Initial experimentation with loading all Markdown in memory Loading all Markdown in memory Jun 28, 2015
Comment thread mkdocs/nav.py

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs fixed.

@d0ugal
d0ugal force-pushed the refactor-markdown-loading branch from 1bd9aa7 to d9c5a7f Compare June 28, 2015 21:25
Comment thread mkdocs/utils/mdutils.py

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be implemented 😄 Given Markdown as a string, it should return the first Header (h1/#). Thoughts about a reasonable approach?

@d0ugal
d0ugal force-pushed the refactor-markdown-loading branch from d9c5a7f to 544d736 Compare June 28, 2015 21:52
@tkirill

tkirill commented Jul 4, 2015

Copy link
Copy Markdown

@d0ugal This is that required refactoring for #316? If so then what is the status of this PR? Is it waiting for review or there are some tasks to be done? If there are any free tasks to be done to merge this PR I would be happy to do them.

@waylan

waylan commented Jul 4, 2015

Copy link
Copy Markdown
Contributor

@tkirill, yes this is the refactoring for #316 among other things. I believe this is waiting on the issues mentioned in the comments above.

@d0ugal

d0ugal commented Jul 7, 2015

Copy link
Copy Markdown
Contributor Author

@tkirill Yup, this re-factoring would enable #316 (it actually almost includes the implementation) and a number of other things we want to do. @waylan is correct that the above comments and check list in the description here are the outstanding tasks.

If you want to try any of them, I'd suggest making pull requests against my fork and then they can be merged in and included here. Stick to one per commit to make things easier to review if you can.

@d0ugal d0ugal mentioned this pull request Jul 7, 2015
@d0ugal d0ugal closed this Jul 10, 2015
@d0ugal

d0ugal commented Jul 10, 2015

Copy link
Copy Markdown
Contributor Author

@d0ugal d0ugal mentioned this pull request Aug 15, 2015
1 of 2 tasks
@waylan waylan mentioned this pull request May 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants