Skip to content

Commit 7a1ca68

Browse files
committed
Exclude headers in divs from outline
1 parent 012d457 commit 7a1ca68

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

apps/lsp/src/service/toc.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
getLine,
3737
Document,
3838
Parser,
39+
isDiv,
3940

4041
} from 'quarto-core';
4142

@@ -140,7 +141,7 @@ export class TableOfContents {
140141
}
141142

142143
// compute restricted ranges (ignore headings in these ranges)
143-
const isWithinIgnoredRange = isWithinRange(tokens, token => isCallout(token) || isTheorem(token) || isProof(token));
144+
const isWithinIgnoredRange = isWithinRange(tokens, isDiv);
144145
const isWithinTabset = isWithinRange(tokens, isTabset);
145146

146147
const existingSlugEntries = new Map<string, { count: number }>();

packages/quarto-core/src/markdown/token.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,29 @@ export type TokenType =
3333
export const kAttrIdentifier = 0;
3434
export const kAttrClasses = 1;
3535
export const kAttrAttributes = 2;
36-
export type TokenAttr = [string, Array<string>, Array<[string,string]>];
36+
export type TokenAttr = [string, Array<string>, Array<[string, string]>];
3737

3838

3939
export interface Token<T = unknown> {
4040
type: TokenType;
4141
range: Range;
42-
attr?: TokenAttr;
42+
attr?: TokenAttr;
4343
data: T;
44-
// FrontMatter: yaml
45-
// Header: { level: number, text: string }
46-
// Math: { type: string, text: string }
47-
// CodeBlock: text
48-
// RawBlock: { format: string, text: string }
49-
// (Other): null
44+
// FrontMatter: yaml
45+
// Header: { level: number, text: string }
46+
// Math: { type: string, text: string }
47+
// CodeBlock: text
48+
// RawBlock: { format: string, text: string }
49+
// (Other): null
5050
}
5151

5252
export type TokenFrontMatter = Token<string>;
53-
export function isFrontMatter(token: Token) : token is TokenFrontMatter {
53+
export function isFrontMatter(token: Token): token is TokenFrontMatter {
5454
return token.type === "FrontMatter";
5555
}
5656

5757
export type TokenHeader = Token<{ level: number, text: string }>;
58-
export function isHeader(token: Token) : token is TokenHeader {
58+
export function isHeader(token: Token): token is TokenHeader {
5959
return token.type === "Header";
6060
}
6161

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

77+
export function isDiv(token: Token) {
78+
return token.type === "Div"
79+
}
80+
7781
export function isCallout(token: Token) {
7882
if (token.type === "Div" && token.attr) {
7983
const classes = token.attr[kAttrClasses];

0 commit comments

Comments
 (0)