INNER CODE UNIT · Python

render_markdown

CybercentreCanada/assemblyline · gen_docs.py:21

    def render_markdown(file) -> None:
        if not file.endswith(".py"):
            return
        lib = SourceFileLoader(file, file).load_module()
        markdown_list = [(c.markdown(), c.__name__) for c in lib.__dict__.values() if isclass(
            c) and issubclass(c, Model) and not (c.__module__.startswith("assemblyline.odm.models"))]

        if markdown_list:
            # Bring last item to the front
            name = markdown_list[-1][1]
            compiled_md = "\n\n".join(m[0] for m in markdown_list)
            if len(markdown_list) > 1:
                compiled_md = markdown_list.pop(-1)[0]
                # Check if other models were part of the first render
                for md, md_name in markdown_list:
                    # Add if missing
                    if not re.search(f"# {md_name}\n", compiled_md):
                        compiled_md += f"\n\n{md}"

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…