Skip to content

Commit

Permalink
Merge pull request #123 from qmd-lab/jimjam-slam/issue121
Browse files Browse the repository at this point in the history
Fix cr-sections inside sections (eg. when h2 is used)
  • Loading branch information
jimjam-slam authored Nov 3, 2024
2 parents 5a4567d + 8649ae0 commit e615011
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
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

0 comments on commit e615011

Please # to comment.