Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/lsp/src/service/toc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
getLine,
Document,
Parser,
isDiv,

} from 'quarto-core';

Expand Down Expand Up @@ -140,7 +141,7 @@ export class TableOfContents {
}

// compute restricted ranges (ignore headings in these ranges)
const isWithinIgnoredRange = isWithinRange(tokens, token => isCallout(token) || isTheorem(token) || isProof(token));
const isWithinIgnoredRange = isWithinRange(tokens, isDiv);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me make things fun (of the type 3 variety).

What should we do about conditional content divs? (to say nothing of arbitrary Lua filters...)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behavior of conditional content divs is that the div itself will never actually appear in the resulting document. But if the conditions are met, then the contents will be included in the document, and headers inside will "move one level up".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You always find and share the most interesting case! 😅

Level 3 indeed... How can we handle those indeed...

Copy link
Collaborator Author

@vezwork vezwork Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well gosh. I could probably hack together some checks for that in this code... but should I?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vezwork No, I don't think that's the best move. Let's merge this as is and talk about a redesign for later.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've realized that this PR doesn't actually address the regression. There is a deeper issue that probably is best resolved by deferring outline stuff to the CLI.

const isWithinTabset = isWithinRange(tokens, isTabset);

const existingSlugEntries = new Map<string, { count: number }>();
Expand Down
24 changes: 14 additions & 10 deletions packages/quarto-core/src/markdown/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,29 @@ export type TokenType =
export const kAttrIdentifier = 0;
export const kAttrClasses = 1;
export const kAttrAttributes = 2;
export type TokenAttr = [string, Array<string>, Array<[string,string]>];
export type TokenAttr = [string, Array<string>, Array<[string, string]>];


export interface Token<T = unknown> {
type: TokenType;
range: Range;
attr?: TokenAttr;
attr?: TokenAttr;
data: T;
// FrontMatter: yaml
// Header: { level: number, text: string }
// Math: { type: string, text: string }
// CodeBlock: text
// RawBlock: { format: string, text: string }
// (Other): null
// FrontMatter: yaml
// Header: { level: number, text: string }
// Math: { type: string, text: string }
// CodeBlock: text
// RawBlock: { format: string, text: string }
// (Other): null
}

export type TokenFrontMatter = Token<string>;
export function isFrontMatter(token: Token) : token is TokenFrontMatter {
export function isFrontMatter(token: Token): token is TokenFrontMatter {
return token.type === "FrontMatter";
}

export type TokenHeader = Token<{ level: number, text: string }>;
export function isHeader(token: Token) : token is TokenHeader {
export function isHeader(token: Token): token is TokenHeader {
return token.type === "Header";
}

Expand All @@ -74,6 +74,10 @@ export function isRawBlock(token: Token): token is TokenRawBlock {
return token.type === "RawBlock";
}

export function isDiv(token: Token) {
return token.type === "Div"
}

export function isCallout(token: Token) {
if (token.type === "Div" && token.attr) {
const classes = token.attr[kAttrClasses];
Expand Down