amyreese / markdown-pp

Preprocessor for Markdown files to generate a table of contents and other documentation needs
MIT License
309 stars 68 forks source link

How to disable features (in particular auto-numbering of sections in TOC) ? #73

Open sylvaticus opened 4 years ago

sylvaticus commented 4 years ago

Hello, I just learned how to disable the latex plugin, but I would like now to also disable automatic numbering of paragraphs in the TOC, as they are already manually numbered.

More in general it would be nice to have a way to disable each feature individually and to document it.

sylvaticus commented 4 years ago

I can see there in an option -h (I was looking for the manpage) that list the modules that can be disabled, including tableofcontent.

It would be nice to have an option to disable individual features for each module, e.g. -e tableofcontent numbers,links -e latexplugin equations

sylvaticus commented 4 years ago

Solved my own user case with a bit of hacking of /usr/local/lib/python3.6/dist-packages/MarkdownPP/MarkdownPP.py

Now I have the sections with identation rather than numbering:

            if depth == 1:
                section = "%d\\. " % headernum
                sectionintoc = "- "
                sectioninbody = ""

            else:
                section = (".".join([str(x) for x in stack]) +
                           ".%d\\. " % headernum)
                sectionintoc = "".join("   " for x in stack)+"- "
                sectioninbody = ""

            #tocdata += ("%s [%s](#%s)  \n" %
            #            (section, TableOfContents.clean_title(title), short))
            tocdata += ("%s [%s](#%s)  \n" %
                        (sectionintoc, TableOfContents.clean_title(title), short))

            #transforms.append(Transform(linenum, "swap",
            #                  data[linenum].replace(title, section + title)))
            transforms.append(Transform(linenum, "swap",
                              data[linenum].replace(title, sectioninbody + title)))
            transforms.append(Transform(linenum, "prepend",
                              "<a name=\"%s\"></a>\n\n" % short))

Of course, the general idea to have feature disabled in the command line is still interesting..