-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11841 from quarto-dev/bugfix/issue-11835
Detect `#` headings with AST
- Loading branch information
Showing
8 changed files
with
89 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* level-one-headings.ts | ||
* | ||
* Copyright (C) 2025 Posit Software, PBC | ||
*/ | ||
|
||
import { join } from "../../../deno_ral/path.ts"; | ||
import { execProcess } from "../../process.ts"; | ||
import { pandocBinaryPath, resourcePath } from "../../resources.ts"; | ||
|
||
export async function hasLevelOneHeadings(markdown: string): Promise<boolean> { | ||
// this is O(n * m) where n is the number of blocks and m is the number of matches | ||
// we could do better but won't until we profile and show it's a problem | ||
|
||
const path = pandocBinaryPath(); | ||
const filterPath = resourcePath( | ||
join("filters", "quarto-internals", "leveloneanalysis.lua"), | ||
); | ||
const result = await execProcess({ | ||
cmd: [path, "-f", "markdown", "-t", "markdown", "-L", filterPath], | ||
stdout: "piped", | ||
}, markdown); | ||
return result.stdout?.trim() === "true"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/resources/filters/quarto-internals/leveloneanalysis.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
local found = false | ||
function Header(el) | ||
found = found or el.level == 1 | ||
return nil | ||
end | ||
|
||
function Pandoc(doc) | ||
if found then | ||
doc.blocks = pandoc.Blocks({ | ||
pandoc.Str("true") | ||
}) | ||
else | ||
doc.blocks = pandoc.Blocks({ | ||
pandoc.Str("false") | ||
}) | ||
end | ||
return doc | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
format: latex | ||
number-sections: true | ||
_quarto: | ||
tests: | ||
latex: | ||
ensureFileRegexMatches: | ||
- [] | ||
- ["subsection{Section}"] | ||
--- | ||
|
||
## Section | ||
|
||
```r | ||
# this is a comment that shouldn't break quarto | ||
print("Hello, world") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
format: typst | ||
number-sections: true | ||
_quarto: | ||
tests: | ||
typst: | ||
ensurePdfRegexMatches: | ||
- ["1 Section"] | ||
- ["0.1 Section"] | ||
--- | ||
|
||
## Section | ||
|
||
```r | ||
# this is a comment that shouldn't break quarto | ||
print("Hello, world") | ||
``` |