Love TOCs for RTF (+ idea)

I just realized something else.

DT lets me write a note, which may need to have sidebar notation referring to other documents.

I can transclude other documents, giving my note extra depth.

But I can also open any document’s attachment, where the TOC, transclusion, and all that other wonderful stuff continues to work. Just keep the inspector open in the edit window for the attachment.

I’ve often thought attachments can serve as little maps of content for a single note. Pretty neat the way attachments can have their own internal organization just like any other document.

I’m still unable to visualize an actual use case for what you’re up to :slight_smile:

I may also have problems visualizing a use case. This could be an answer without a question, but I still think it’s cool and I’ve started using it for brainstorming.

Imagine storyboarding a novel in Devonthink. Here’s the notes for the opening scene:

You have a TOC in the inspector. Now, check out the annotations:

Not very useful, except for a place to park links. Open the attachment and it’s a lot nicer, with the main character’s and neighborhood bar’s notes transcluded in:

The links for Main character and The neighborhood bar go to the source notes that were transcluded.

I have a Keyboard Maestro macro that makes this kind of thing easy. It expects an item link on the clipboard and inserts a link followed by a transclusion.

Anyway, those were my thoughts. The Annotation can be like a little auto-generated dossier clipped to a Markdown document.

1 Like

Is the length of the line taken into account as well for detecting headings?

It looks like if the line is longer than 99 characters, it’s not detected as a heading even if the line is entirely bold.

Note the missing sections below:

Is there anyway to make it so the longer lines are detected as well?

Yes, both the styling and the length matter as there’s no real RTF support for headings.

Thanks for the info. So there’s no way it can just detect up to the line break? Or is more for performance?

No, that’s not possible currently.

1 Like

Ok, Thanks again for the info.

I think normally it won’t be a problem for me.

In the current document I’m working on, the headings are research questions, and so they’re some times quite a bit longer than one would expect for normal heading.

I was just still hoping for the TOC navigation. :slight_smile:

I have a solution that might work for you. It’s a script I used before TOCs were built-in. It looks at every line in the document, and adds any that start with a bold character to a list. It then shows that list in a dialog, so you can select a line to jump to. It’s basic, but it might help.

-- BOLD TOC
-- find lines that start with bolded text
-- let user select one of these lines to jump to

tell application id "DNtp"
	try
		set itemURL to get the reference URL of (item 1 of (selection as list))
		tell rich text of think window 1
			set theList to {}
			set thePos to {}
			set paraCount to 0
			
			repeat with thisParagraph in every paragraph
				--set len to the number of characters of thisParagraph
				if (font of thisParagraph contains "Bold") then --only finds paragraphs that start bold
					set len to the number of characters of thisParagraph
					--only works with paragraphs that have more than one character (ignores empty lines)
					if len > 1 then
						--if paragraph is too long, trim
						if len > 55 then
							set thisHeading to characters 0 thru 55 of thisParagraph
						else
							set thisHeading to thisParagraph
						end if
						set end of theList to thisHeading as rich text
						set end of thePos to paraCount
					end if
				end if
				set paraCount to paraCount + 1
			end repeat
		end tell
		
		set theChoice to (choose from list theList with prompt {"Choose which heading to jump to: "} default items "" OK button name "Go To") as string
		set choiceNum to my list_position(theChoice, theList)
		set choicePos to item choiceNum of thePos as rich text
		set itemURL to itemURL & "?reveal=1&line=" & choicePos as string
		open location itemURL
		
	end try
end tell

on list_position(this_item, this_list)
	repeat with i from 1 to the count of this_list
		if item i of this_list is this_item then return i
	end repeat
	return 0
end list_position
2 Likes