Display tables at full length while keeping the rest at readable line length

There’s a request (almost 2.5 years old) for a hotkey which toggles “readable line length” on and off, which would be a useful stop-gap.

In another thread requesting a hotkey or button to do the same thing, users write that the plug-ins Smarter Markdown Hotkeys and hotkeysplus make “readable line length” addressable by a hotkey. @Archie in the first thread uses MySnippets to toggle a CSS snippet controlling line length on and off.

My current work-around is similar to Archie’s. I use a macro manager (Keyboard Maestro, but Alfred and AutoHotkey would work just as well) to invoke, by hotkey, a shell script which ‘toggles’ a single-purpose CSS snippet on and off:

#!/bin/zsh

snippet="path/to/obsidian-vault/.obsidian/snippets/measure.css"
template="path/to/templates-directory/measure.css"

if [[ -s "$snippet" ]]; then
	: > "$snippet"
else
	cat "$template" > "$snippet"
fi

If the snippet contains text, the script empties it; otherwise, it writes the contents of the template file to the snippet file. Because Obsidian immediately refreshes on changes to CSS snippets, the effect is to toggle line length.

The CSS I’m using is:

.inline-title {
	width: var(--file-line-width);
	margin-left: auto !important;
	margin-right: auto !important;
}

.markdown-source-view.mod-cm6.is-readable-line-width .cm-sizer,
.markdown-source-view.mod-cm6.is-readable-line-width .cm-content {
	max-width: 100% !important;
}

.markdown-source-view.mod-cm6.is-readable-line-width .cm-line {
	margin-left: auto !important;
	margin-right: auto !important;
}

This keeps text and the inline title centred with a comfortable measure, but allows Dataview output and images to expand to the full width of the window (in source view). The result is unsatisfactory where Dataview output or images are substantially narrower than the window (they’re aligned against the left edge of the window, out of flow with the text), but in the case of notes interspersed with wide tables, it produces exactly the result pictured in @EleanorKonik’s mock-up above.