python-markdown-generator icon indicating copy to clipboard operation
python-markdown-generator copied to clipboard

Could be used to generate markdown files for Pelican?

Open datatalking opened this issue 1 year ago • 4 comments

@Nicceboy I've been playing with your code and was curious if this could be adapted to extended to start generating the keyboard-review.md on step 3 of this Pelican Tutorial

Does this work with Mermaid for charts?

Now if, and that might be a big if, I'm wanting to know how I could extend what you wrote to write more keyboard-review.md type blog posts. I do lots of Natural Language Processing and Machine Learning so being able to generate .md files is a very helpful tool... and If I can adapt it to Pelican now I've mostly automated a blog and website.

datatalking avatar May 08 '23 20:05 datatalking

Hey, about the Pelican.

Do you mean metadata which is often called as front matter? For example, https://docs.zettlr.com/en/core/yaml-frontmatter/ Pelican seems to use simplified yaml in Markdowns and .rst file otherwise.

You should be able to generate this with the existing code by creating own function, e.g.

from markdowngenerator import MarkdownGenerator
import datetime


def addFrontMatter(doc: MarkdownGenerator,  meta: dict):
    for k, v in meta.items():
        doc.writeTextLine(f'{k}: {v}')
    doc.writeTextLine(f'')

def main():
    with MarkdownGenerator(
        filename="example.md", enable_write=False, enable_TOC=False
    ) as doc:

        metadata = {
        "Title": "My First Review",
        "Date": str(datetime.datetime.now()),
        "Category": "Review"
        }

        addFrontMatter(doc, metadata)
        doc.addHeader(1, "Hello there!")
        doc.writeTextLine(f'{doc.addBoldedText("This is just a test.")}')
        doc.addHeader(2, "Second level header.")
        table = [
            {"Column1": "col1row1 data", "Column2": "col2row1 data"},
            {"Column1": "col1row2 data", "Column2": "col2row2 data"},
        ]

        doc.addTable(dictionary_list=table)
        doc.writeTextLine("Ending the document....")

if __name__ == "__main__":
    main()

If you want to parse .rst files and add then dynamically, it should not be too big work.

About the Mermaids, it might be possible. But it depends what kind of automation you need. Is there some data which is used as starting point and that should be mapped to Mermaid syntax?

Nicceboy avatar May 08 '23 20:05 Nicceboy

Hey, about the Pelican.

Do you mean metadata which is often called as front matter? For example, https://docs.zettlr.com/en/core/yaml-frontmatter/ Pelican seems to use simplified yaml in Markdowns and .rst file otherwise.

As an analyst that probably know way more python than I should, I wasn't exactly sure what you meant by meta-data or front matter are but I'm re-reading your reply and if meta-data is the content of the README.md then yes. I basically was curious if I could have Pelican to generate my README.md files or README.rst using your script so I don't have to make them by hand each time I do a Pelican.

As an alternative I was thinking have your script get called when my Data_Butler tool finds a folder or repo of mine doesn't have a README.md or README.rst and create it.

datatalking avatar May 08 '23 22:05 datatalking

When I used that code I get this error in python 3.7.

Screen Shot 2023-05-08 at 4 14 23 PM

Is this a related Table Of Contents issue as this?

datatalking avatar May 08 '23 23:05 datatalking

The front matter or metadata are those key-value pairs you can see in the beginning of the Pelican example README file. The code made an example implementation for doing that.

When I used that code I get this error in python 3.7. Screen Shot 2023-05-08 at 4 14 23 PM Is this a related https://github.com/executablebooks/jupyter-book/issues/786 issue as this?

This is just related to my own code. If the output file is written directly to disk, it is hard to add table of contents without rewriting the whole file.

Nicceboy avatar May 12 '23 07:05 Nicceboy