Skip to content

countRenderedButtons

Counts the buttons a note’s source will actually render.

Three kinds of ```code-button fence render no clickable button, and a vault that DOCUMENTS code buttons is full of the first two:

  • A fence nested inside a longer or different fence (a markdown ```` or ~~~ block) is a markdown SAMPLE shown to the reader; the renderer never sees it as a block. - An isRaw: true fence renders its output directly and no button element at all. - A fence whose info string carries anything after code-button uses the legacy argument syntax, which renders an error banner asking to update the config rather than the button.

Counting any of them makes the suite’s shortfall assertion unsatisfiable — it demands more buttons than the note can ever render — and an assertion that cannot pass gates nothing.

The scan follows CommonMark’s fence rules: a fence closes only on a run of the SAME character at least as long as the opener, with no info string, and one left open runs to the end of the document, where it still renders.

Import:

import { countRenderedButtons } from 'obsidian-dev-utils/script-utils/demo-vault-buttons';

Signature:

function countRenderedButtons(source: string): number

Parameters:

Parameter Type Description
source string The note’s markdown.

Returns: number — How many buttons it renders.


Links to this page: