Markdown {{TOC}} has a weird bug over here

DEVONthink Pro 4.2.2

I’ve got a strange problem with {{TOC}} in Markdown documents. That may sound like it’s not necessarily a DEVONthink issue, but I’ve reason to belive it is.

I do most of my work with Markdown documents and I index rather than import. (With my workflows that’s the best choice) Everything has been working great for years.

Some time in the past few months the TOC has been blowing up. Crazy amounts of extraneous material at the top of the “table”, looks like stuff from the source code for the module:

Table of Contents Extension for Python-Markdown

===============================================

See https://Python-Markdown.github.io/extensions/toc

for documentation.

Original code Copyright 2008 Jack Miller

All changes Copyright 2008-2024 The Python Markdown Project

License: BSD

"""
Add table of contents support to Python-Markdown.

See the documentation
for details.
"""

from future import annotations
from . import Extension
from ..treeprocessors import Treeprocessor
from ..util import parseBoolValue, AMP_SUBSTITUTE, deprecated, HTML_PLACEHOLDER_RE, AtomicString
...

LOTS of that. But here’s where it gets interesting..

Sometimes it works okay, sometimes it doesn’t. While I was trying to debug this I found something weird. A document where the TOC generates correctly is in one database and I copy it into another database where I have the problem. Now the “good” file is “bad”! But if I copy it back into it’s original database it’s “good” again!

Both of these databases are indexed, so I’m really moving files around the file system and updating the index.

Further information: yesterday I completely trashed and rebuilt the “bad” database but the problem continues. Please help!

What does your example text have to do with anything?

1 Like

Is there a file named TOC in the „bad“ database? {{…}} is also the syntax for transclusions.

1 Like

File transclusion would also be my guess.

@arasmus you can disambiguate transclusion from table of contents if you specify header levels with the extended syntax, i.e. {{TOC:1-6}}. (I did a quick test to confirm.) But it seems easier to rename whatever file you have named TOC.

1 Like

Wow, first of all THANKS to all you guys for responding so quickly on a Sunday and a holiday.

@BLUEFROG sorry if I wasn’t clear. The text is just the first part of all this extraneous junk that is appearing in what should be the TOC

@cgrunenberg & @troejgaard Ding ding ding! We have a solution!

If you had suggested that I had a file named “TOC” I would have thought it unlikely. But there, buried in my python 3.13 dist (probably explaining why “it just happened recently”) there is a “toc.py” file in the site-packages/markdown/extensions directory. I renamed it and the problem went away!

You guys are awesome and I appreciate it a whole lot. I never would have figured that out. (I never did figure that out.)

Um, a final question if I may: would this be changed in any way if I was using imported databases (I’m guessing not.)

2 Likes

Good to know, and thanks for that. But yeah, easier to rename the file since this is my largest database and there are MANY table of contents in there. Better to rename or even exclude the problem file. (No real reason for the python distribution to be in my database anyway, it was kind of a side effect.)

Why do you index your Python distribution into a DT database?

The location (imported vs. indexed) doesn’t matter.

1 Like

As indicated in the previous post, it was kind of a side effect of other stuff. I agree that should be excluded

If this is your Python distro and you need it, you should not rename files in it. That may break something in Python.

1 Like

Clearly. Thank you.