fralau / mkdocs-mermaid2-plugin

A Mermaid graphs plugin for mkdocs
https://mkdocs-mermaid2.readthedocs.io
MIT License
214 stars 26 forks source link

Skip parsing of HTML pages when possible #42

Closed ribetm closed 3 years ago

ribetm commented 3 years ago

Currently every page passed through the post_page event is parsed, while there could be ways to quickly skip it if there are no charts to process.

The optimization proposed in #41 should greatly benefit large documentations with limited use of this plugin. It does not run BeautifulSoup on every pages produced by mkdocs and instead checks first for the word mermaid textually. This change allowed a 600 pages documentation (only 1 page with charts) to build in 60s instead of 240s, as about 70% of the total computing time was spent in mermaid's post_page event.

This PR should not have any meaningful consequences on the generated files, except for the fact that pages not processed by mermaid will not be reformatted by bs4 (white lines, indentation and attributes re-ordering). This is probably not an issue since it was mostly a side-effect and actually means keeping the output format of base mkdocs.

Three possibilities:

github-actions[bot] commented 3 years ago

Thank you for your contribution! This is very appreciated.