Feature: Plain Markdown generator.#88
Conversation
…kdownGenerator.hpp and .cpp. Added new subcommand 'gitdoc' to use the PlainMarkdownGenerator. Added Driver::git_build() to utilize PlainMarkdownGenerator functions instead of MarkdownGenerator.
…rks with `gitdoc` command to have the output directory contain only plain Markdown
Corrected the spelling of 'unsupported' in the documentation.
BroDudeGuyMan
left a comment
There was a problem hiding this comment.
The cmbuild.sh script is not a dependency and can be removed from the repo. It's simply a helpful script to clean the build dir, configure CMake, and build the project.
lawmurray
left a comment
There was a problem hiding this comment.
Thanks for working on this @BroDudeGuyMan. I've reviewed the code.
The major issue is that you have copied all of MarkdownGenerator.cpp to PlainMarkdownGenerator.cpp before making your changes in there, which means there is now a lot of duplicated code. That creates a maintenance headache for future: any fixes to that code will need to happen in both files in future. So we can't do that.
Can you instead integrate your changes into MarkdownGenerator.cpp? Similar to what you have done in Driver.cpp, were you just use a few if (plain_md) conditionals to act differently. There are only 10-20 lines that you have had to change in the Markdown generator, so this is the best way.
If you can do that, I can review again.
Let's remove this file too. Everyone has their own workflows, and they can make such a script themselves if that's how they prefer to work. |
|
You got it @lawmurray. I can get that done today. |
|
@lawmurray I've made the changes. Now, when using init, a |
Typo fix
| ### For small projects | ||
| If you don't want the Mkdocs noise, you can run: | ||
| ``` | ||
| doxide gitdoc |
There was a problem hiding this comment.
I don't see any gitdoc command implemented. Besides, a separate command is not the preferred approach, so this can be removed.
|
|
||
| Add at least `doxide.yaml` to version control, and the other files if you intend to use Material for MkDocs (highly recommended for a quick start---you can always try something else later). | ||
|
|
||
| ### For small projects |
There was a problem hiding this comment.
No need to document this here, as it's mean to be a "quick start" section.
| callback([&]() { driver.init(); }); | ||
| auto init_cmd = app.add_subcommand("init", | ||
| "Initialize configuration files."); | ||
| init_cmd->add_flag("--plain", |
There was a problem hiding this comment.
I'll elaborate on the discussion page, but I think we should just add a --style command-line option that takes values plain and mkdocs-material. Then doxide init --style plain can do what you want, and doxide build --style plain or putting style: plain in doxide.yaml can do what you want.
| #include "YAMLParser.hpp" | ||
| #include "CppParser.hpp" | ||
| #include "MarkdownGenerator.hpp" | ||
| #include "PlainMarkdownGenerator.hpp" |
| */ | ||
| static const char* init_doxide_yaml = | ||
| R""""(title: | ||
| R""""(style: |
There was a problem hiding this comment.
Use the order title, description, style, files. This is a user-editable file, and having style first may confuse.
| } | ||
|
|
||
| void Driver::init() { | ||
| void Driver::init(bool plain_md) { |
There was a problem hiding this comment.
I don't see the need to have the bool plain_md parameter. Why not just check the style member variable?
| "style: plain"); | ||
| } else { | ||
| doxide_yaml = std::regex_replace(doxide_yaml, std::regex("style:"), | ||
| "style: mkdocs"); |
There was a problem hiding this comment.
Let's use mkdocs-material, it's more precise.
| * Create a new configuration file. | ||
| */ | ||
| void init(); | ||
| void init(bool plain); |
There was a problem hiding this comment.
Again, not seeing the need for this parameter, I think there are better ways.
| /** | ||
| * Build GetHub webview ready documentation. | ||
| */ | ||
| void git_build(); |
There was a problem hiding this comment.
This shouldn't be a command, let's just use a --style plain command-line option.
| /** | ||
| * Whether to remove Mkdocs noise. | ||
| */ | ||
| bool plain; |
There was a problem hiding this comment.
This seems redundant with having the style member set to plain? If so, let's remove it, and just use the style member.
| /** | ||
| * Entity style. This is used to generate certain types of Markdown. | ||
| */ | ||
| std::string style; |
There was a problem hiding this comment.
This means that every entity has its own style attribute, which will slow things down considerably and is unnecessary. Only Driver and MarkdownGenerator should need to know the style.
| std::string filename; // file name for this entity | ||
| std::string childdir; // directory name for children, relative to filename | ||
| if (entity.type == EntityType::ROOT) { | ||
| style = entity.style; |
There was a problem hiding this comment.
As above, add style to Driver and MarkdownGenerator, but not each Entity.
| out << "(" << childdir << sanitize(child->name) << "/index.md)" << std::endl; | ||
| out << ": " << line(brief(*child)) << std::endl; | ||
| out << std::endl; | ||
| if (style == "plain") { |
There was a problem hiding this comment.
Don't do a string comparison each time, as these are tight inner loops, and doing so will harm performance considerably. Instead, do the comparison once, and store the result in a bool.
| out << std::endl; | ||
| out << "!!! macro \"" << htmlize(line(child->decl)) << '"' << std::endl; | ||
| if (style == "plain") { | ||
| out << "> #**Macro**" << std::endl << "> " << htmlize(line(child->decl)) << std::endl; |
There was a problem hiding this comment.
This unicode character is broken for me. Perhaps it's not in all fonts. Is there an alternative?
There was a problem hiding this comment.
I think this shouldn't exist any longer.
| /docs/demo | ||
| /.cache | ||
| /src/config.h | ||
| cmbuild.sh |
| cmake_policy(SET CMP0074 NEW) # use <PackageName>_ROOT to look for packages | ||
|
|
||
| set(CMAKE_CXX_STANDARD 20) | ||
| set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
There was a problem hiding this comment.
Can you explain what this does?
| src/JSONCounter.cpp | ||
| src/JSONGenerator.cpp | ||
| src/MarkdownGenerator.cpp | ||
| src/PlainMarkdownGenerator.cpp |
|
Thanks for the update here @BroDudeGuyMan. I've reviewed and left some comments throughout. What I'd suggest is that we just add a
|
Problem
Doxide currently only outputs Markdown that is not compatible with GitHub webview, and other Markdown viewers. This is okay for larger projects, but small personal repositories often rely on GitHub webview for source documentation.
Fix
New Generator
I have added a new class called
PlainMarkdownGeneratorthat replaces all Mkdoc-specific Markdown with standard, fully supported syntax. Icons have also been replaced with near-identical Unicode characters.Use the new generator with:
doxide gitdocInit options
There is a new option for the
initsub-command:This will create
doxide.yamlas normal, as well as the output directory, but will skip creatingmkdocs.yamland the web content directories. This leaves only Markdown, with no other dependencies.How this helps
Now Doxide can be used as both a documentation hosting tool, and a local documentation manager. All without the hassle of manually editing files and removing directories.
Changes:
src/PlainMarkdownGenerator.hppsrc/PlainMakrdownGenerator.cppbool Driver::plainDriver::init()toDriver::init(bool plain_md)CMakeLists.txtto addset(CMAKE_EXPORT_COMPILE_COMMANDS ON)docs/getting-started.mdanddocs/running.md