Skip to content
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

Fix cr-sections inside sections (eg. when h2 is used) #123

Merged
merged 5 commits into from
Nov 3, 2024
Merged
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
2 changes: 1 addition & 1 deletion _extensions/closeread/_extension.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
title: closeread
author: Andrew Bray and James Goldie
version: 1.0.0
version: 1.0.1
quarto-required: ">=1.3.0"
contributes:
formats:
Expand Down
2 changes: 1 addition & 1 deletion _extensions/closeread/closeread.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 17 additions & 4 deletions _extensions/closeread/closeread.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,22 @@ document.addEventListener("DOMContentLoaded", () => {
document.body.classList.add("cr-removeheaderspace")
}

// attach layout classes to direct parents of `.cr-section`s
// attach layout classes to parents of `.cr-section`s up to main.content
/* this replicates quarto <= 1.6 functionality:
https://github.com/quarto-dev/quarto-cli/blob/
d85467627aae71c96e3d1e9718a3b47289329cde/src/format/html/
format-html-bootstrap.ts#L1163C1-L1186C7 */
format-html-bootstrap.ts#L1163C1-L1186C7 */
const ensureInGrid = el => {
const parent = el.parentElement
parent.classList.add("page-columns", "page-full")
if (isDocumentMain(parent)) {
return
} else {
ensureInGrid(parent)
}
}
const crSections = Array.from(document.querySelectorAll(".cr-section"))
crSections.map(
el => el.parentElement.classList.add("page-columns", "page-full"))
crSections.map(ensureInGrid)

const ojsModule = window._ojs?.ojsConnector?.mainModule
const ojsStickyName = ojsModule?.variable()
Expand Down Expand Up @@ -409,3 +417,8 @@ function getBooleanConfig(metaFlag) {
.querySelector("meta[" + metaFlag + "]")?.getAttribute(metaFlag)
return option === "true"
}

function isDocumentMain(el) {
return el === null ||
(el.tagName == "MAIN" && el.classList.contains("content"))
}
2 changes: 1 addition & 1 deletion _extensions/closeread/closeread.scss
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
}
}
.sidebar-right {
grid-template-columns: 2fr var(cr-narrative-sidebar-width);
grid-template-columns: 2fr var(--cr-narrative-sidebar-width);

.narrative-col {
grid-column: 2;
Expand Down
Loading