-
Notifications
You must be signed in to change notification settings - Fork 339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
shift-heading-level-by
not adjusting numbering correctly in quarto 1.6
#12048
Comments
shift-heading-level-by
not adjust numbering correctly in quarto 1.6shift-heading-level-by
not adjusting numbering correctly in quarto 1.6
@t-kalinowski what do you expect I understand the first results from Quarto 1.3 is what you expect with 1. then 2. directly ? In book, a .qmd doc is a chapter, and level 1 header ( I know we had some discussion about Disallow support for Thank you ! Related Discussion |
My primary motivation is to get rid of the These are all level three |
|
What is the reason to use level three headers instead of the expected level two? |
Looking at this more closely, outside of book context, I think this highlight a different in behavior with how Pandoc works. I am taking this document as example with no level 2 in the document and asking to shift any level by 2 to consider them as level 1. to ---
title: "Test"
format: html
number-sections: true
shift-heading-level-by: -1
---
```{=html}
<style>
h1 { color: red; }
h2 { color: green; }
h3 { color: blue; }
h4 { color: purple; }
h5 { color: orange; }
</style>
```
### h3
foo
#### h4
foo
##### h5
foo Rendering with Quarto gives this results where heades have correct style corresponding to their new levels but the numbering is not right as 0. means an existant level one has been considered. Running same document with Pandoc
have correct numbering. I think this is all related to Simpler example ---
title: "Test"
format: html
number-sections: true
---
## First
foo
## Second
foo
## Third
foo Documents looks good with the correct numbering Now this should be equivalent IMO ---
title: "Test"
format: html
number-sections: true
shift-heading-level-by: -1
---
### First
foo
### Second
foo
### Third
foo But see the numbering: So either
The latter implies that quarto expectation are that Markdown levels used are correct. Or that users shift document levels using a Lua filter Header = function(h)
h.level = h.level -1
return h
end @t-kalinowski using a Lua filter instead of the Pandoc option maybe working solution for your current situation. Could even be shifting only some level (skiping This |
Thank you @cderv, that MRE looks like it isolated the issue! That lua filter looks like it'll do the job, I'll try using that approach for now. In case it's helpful for others in the future, I drafted a short R snippet for manually converting all headings in a project. It's a little crude run once script and doesn't handle nested code blocks. Only run this if you're using version control! library(magrittr)
library(stringi)
for (file in Sys.glob(c("*.qmd", "*.md"))) {
lines <- readLines(file)
is_code <- as.logical(cumsum(startsWith(lines, "```")) %% 2)
for(lvl in 1:7) {
prefix <- paste0(strrep("#", lvl), " ")
is_heading <- startsWith(lines, prefix) & !is_code
lines[is_heading] %<>% stri_sub(2)
if(any(is_h0 <- !startsWith(lines[is_heading], "#")))
warning("file: ", file, " lvl 0 headings introduced: ", lines[is_heading][is_h0])
}
writeLines(lines, file)
}
This is a quarto project that previously used level 3 headers, and now is unable to after a recent quarto update. I vaguely recall there was some friction I encountered w/ manually exporting to asciidoc (quarto ascidoc export wasn't a feature yet), and some specific requirements about headings from the publisher. |
The lua filter works great! For others coming across this: In format:
html:
filters:
# work around bug with `shift-level-headings-by`
# https://github.com/quarto-dev/quarto-cli/issues/12048
- scripts/shift-heading-levels.lua
theme:
light: cosmo
dark: darkly and Header = function(h)
if h.level > 1 then
h.level = h.level - 1
end
return h
end |
Awesome ! That is the best solution for now IMO. It let me time to look at the problem deeper |
Bug description
Given this quarto file in a book project:
if
shift-heading-level-by: -1
is provided, quarto 1.3 produces this:However, quarto 1.6 (the current release) produces this:
Note that with quarto 1.6, the h3 heading is still numbered as an h3 heading, and not as a level 2 heading as expected.
In an actual book project, this manifests as all subsections numbers having a
.0.
phantom level 2 heading.Steps to reproduce
No response
Expected behavior
No response
Actual behavior
No response
Your environment
Quarto check output
The text was updated successfully, but these errors were encountered: