Skip to content

Commit

Permalink
Merge branch 'quarto-dev:main' into Typst-callout-without-body
Browse files Browse the repository at this point in the history
  • Loading branch information
debdagybra authored May 31, 2024
2 parents cc2d14c + 14c65d4 commit 4601634
Show file tree
Hide file tree
Showing 18 changed files with 169 additions and 46 deletions.
4 changes: 3 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
],
"env": {
"QUARTO_BIN_PATH": "${workspaceFolder}/package/dist/bin",
"QUARTO_SHARE_PATH": "${workspaceFolder}/src/resources"
"QUARTO_SHARE_PATH": "${workspaceFolder}/src/resources",
"QUARTO_ROOT": "${workspaceFolder}",
"QUARTO_DEBUG": "true"
},
"attachSimplePort": 9229,
"windows": {
Expand Down
3 changes: 3 additions & 0 deletions news/changelog-1.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ All changes included in 1.5:
- ([#8851](https://github.com/quarto-dev/quarto-cli/issues/8851)): Don't strip `index.html` from external paths.
- ([#8977](https://github.com/quarto-dev/quarto-cli/issues/8977)): Don't decorate about links within external link icons.
- ([#9356](https://github.com/quarto-dev/quarto-cli/issues/9356)): Don't process column classes for figures inside the About divs.
- ([#9781](https://github.com/quarto-dev/quarto-cli/issues/9781)): Correctly hide elements from click event in collapsed margin sidebar.

## Book

Expand Down Expand Up @@ -122,6 +123,7 @@ All changes included in 1.5:
- ([#9635](https://github.com/quarto-dev/quarto-cli/issues/9635)): Respect `{shortcodes=false}` when resolving `include` shortcodes.
- ([#9664](https://github.com/quarto-dev/quarto-cli/pull/9664)): Add `placeholder` shortcode to produce placeholder images.
- ([#9665](https://github.com/quarto-dev/quarto-cli/issues/9665)): Fix issue with key-value arguments of shortcode handlers in code contexts.
- ([#9793](https://github.com/quarto-dev/quarto-cli/issues/9793)): `embed` shortcode now correctly retrieve svg image from embdedded cell.

## Lightbox Images

Expand All @@ -144,6 +146,7 @@ All changes included in 1.5:
## Publishing

- ([#9308](https://github.com/quarto-dev/quarto-cli/issues/9308)): Improved error message when trying to publish to Github pages with `quarto publish gh-pages`.
- ([#9585](https://github.com/quarto-dev/quarto-cli/issues/9585)): Improved `quarto publish gh-pages` workflow when existing gh-pages branch is present or problem with the remote repository.

## `quarto inspect`

Expand Down
49 changes: 27 additions & 22 deletions src/command/check/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,52 +131,57 @@ async function checkVersions(_services: RenderServices) {
let typstVersion = lines(
(await execProcess({
cmd: [typstBinaryPath(), "--version"],
stdout: "piped"
stdout: "piped",
})).stdout!,
)[0].split(' ')[1];
)[0].split(" ")[1];
checkVersion(typstVersion, ">=0.10.0", "Typst");

completeMessage("Checking versions of quarto dependencies......OK");
}

async function checkInstall(services: RenderServices) {
completeMessage("Checking Quarto installation......OK");
info(` Version: ${quartoConfig.version()}`);
info(`${kIndent}Version: ${quartoConfig.version()}`);
if (quartoConfig.version() === "99.9.9") {
// if they're running a dev version, we assume git is installed
// and QUARTO_ROOT is set to the root of the quarto-cli repo
// print the output of git rev-parse HEAD
const gitHead = await execProcess({
cmd: ["git", "rev-parse", "HEAD"],
stdout: "piped",
});
if (gitHead.stdout) {
info(` commit: ${gitHead.stdout.trim()}`);
const quartoRoot = Deno.env.get("QUARTO_ROOT");
if (quartoRoot) {
const gitHead = await execProcess({
cmd: ["git", "-C", quartoRoot, "rev-parse", "HEAD"],
stdout: "piped",
stderr: "piped", // to not show error if not in a git repo
});
if (gitHead.success && gitHead.stdout) {
info(`${kIndent}commit: ${gitHead.stdout.trim()}`);
}
}
}
info(` Path: ${quartoConfig.binPath()}`);
info(`${kIndent}Path: ${quartoConfig.binPath()}`);
if (Deno.build.os === "windows") {
try {
const codePage = readCodePage();
clearCodePageCache();
await cacheCodePage();
const codePage2 = readCodePage();

info(` CodePage: ${codePage2 || "unknown"}`);
info(`${kIndent}CodePage: ${codePage2 || "unknown"}`);
if (codePage && codePage !== codePage2) {
info(
` NOTE: Code page updated from ${codePage} to ${codePage2}. Previous rendering may have been affected.`,
`${kIndent}NOTE: Code page updated from ${codePage} to ${codePage2}. Previous rendering may have been affected.`,
);
}
// if non-standard code page, check for non-ascii characters in path
// deno-lint-ignore no-control-regex
const nonAscii = /[^\x00-\x7F]+/;
if (nonAscii.test(quartoConfig.binPath())) {
info(
` ERROR: Non-ASCII characters in Quarto path causes rendering problems.`,
`${kIndent}ERROR: Non-ASCII characters in Quarto path causes rendering problems.`,
);
}
} catch {
info(` CodePage: Unable to read code page`);
info(`${kIndent}CodePage: Unable to read code page`);
}
}

Expand All @@ -191,10 +196,10 @@ async function checkInstall(services: RenderServices) {

for (const tool of tools.installed) {
const version = await tool.installedVersion() || "(external install)";
toolsOutput.push(` ${tool.name}: ${version}`);
toolsOutput.push(`${kIndent}${tool.name}: ${version}`);
}
for (const tool of tools.notInstalled) {
toolsOutput.push(` ${tool.name}: (not installed)`);
toolsOutput.push(`${kIndent}${tool.name}: (not installed)`);
}
});
toolsOutput.forEach((out) => info(out));
Expand All @@ -213,19 +218,19 @@ async function checkInstall(services: RenderServices) {
if (tlContext.usingGlobal) {
const tlMgrPath = await which("tlmgr");

latexOutput.push(` Using: Installation From Path`);
latexOutput.push(`${kIndent}Using: Installation From Path`);
if (tlMgrPath) {
latexOutput.push(` Path: ${dirname(tlMgrPath)}`);
latexOutput.push(`${kIndent}Path: ${dirname(tlMgrPath)}`);
}
} else {
latexOutput.push(` Using: TinyTex`);
latexOutput.push(`${kIndent}Using: TinyTex`);
if (tlContext.binDir) {
latexOutput.push(` Path: ${tlContext.binDir}`);
latexOutput.push(`${kIndent}Path: ${tlContext.binDir}`);
}
}
latexOutput.push(` Version: ${version}`);
latexOutput.push(`${kIndent}Version: ${version}`);
} else {
latexOutput.push(` Tex: (not detected)`);
latexOutput.push(`${kIndent}Tex: (not detected)`);
}
});
latexOutput.forEach((out) => info(out));
Expand Down
2 changes: 1 addition & 1 deletion src/core/devconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function readInstalledDevConfig(): DevConfig | null {

export function readSourceDevConfig(): DevConfig {
const rootDir = Deno.env.get("QUARTO_ROOT") ||
join(quartoConfig.sharePath(), "../../src");
join(quartoConfig.sharePath(), "../..");
const configurationScript = join(
rootDir,
"configuration",
Expand Down
18 changes: 18 additions & 0 deletions src/core/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,21 @@ export async function lsFiles(

return Promise.resolve(undefined);
}

export async function gitBranchExists(
branch: string,
cwd?: string,
): Promise<boolean | undefined> {
if (await which("git")) {
const result = await execProcess({
cmd: ["git", "show-ref", "--verify", "--quiet", `refs/heads/${branch}`],
cwd,
stdout: "piped",
stderr: "piped",
});

return result.code === 0;
}

return Promise.resolve(undefined);
}
3 changes: 2 additions & 1 deletion src/core/github-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export type GitHubContext = {
repo: boolean;
originUrl?: string;
repoUrl?: string;
ghPages?: boolean;
ghPagesRemote?: boolean;
ghPagesLocal?: boolean;
siteUrl?: string;
browse?: boolean;
organization?: string;
Expand Down
20 changes: 18 additions & 2 deletions src/core/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { join } from "../deno_ral/path.ts";
import { existsSync } from "fs/mod.ts";
import { isHttpUrl } from "./url.ts";
import { GitHubContext } from "./github-types.ts";
import { gitBranchExists } from "./git.ts";

export async function gitHubContext(dir: string) {
// establish dir
Expand Down Expand Up @@ -43,7 +44,7 @@ export async function gitHubContext(dir: string) {
context.originUrl = result.stdout?.trim();

// check for a gh-pages branch
context.ghPages = (await execProcess({
const ghPagesRemote = await execProcess({
cmd: [
"git",
"ls-remote",
Expand All @@ -54,7 +55,22 @@ export async function gitHubContext(dir: string) {
],
stdout: "piped",
stderr: "piped",
})).success;
});

context.ghPagesRemote = ghPagesRemote.success;
if (!ghPagesRemote.success) {
// when no gh-pages branch on remote, check local to avoid creation error
// as if local branch exists, we don't want to create a new one
// https://git-scm.com/docs/git-ls-remote#Documentation/git-ls-remote.txt---exit-code
if (ghPagesRemote.code === 2) {
context.ghPagesLocal = await gitBranchExists("gh-pages");
} else {
// if we go there, this means something is not right with the remote origin
throw new Error(
`There is an error while retrieving information from remote 'origin'.\n Git error: ${ghPagesRemote.stderr}. \n Git status code: ${ghPagesRemote.code}.`,
);
}
}

// determine siteUrl
context.siteUrl = siteUrl(
Expand Down
10 changes: 8 additions & 2 deletions src/core/jupyter/jupyter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1930,9 +1930,15 @@ function mdImageOutput(
? (data as string[]).join("")
: data as string;

// base64 decode if it's not svg
const outputFile = join(options.assets.base_dir, imageFile);
if (mimeType !== kImageSvg) {
if (
// base64 decode if it's not svg
mimeType !== kImageSvg ||
// or if it is encoded svg; this could happen when used in embed context,
// as Pandoc will generate ipynb with base64 encoded svg data
// https://github.com/quarto-dev/quarto-cli/issues/9793
!/<svg/.test(imageText)
) {
const imageData = base64decode(imageText);

// if we are in retina mode, then derive width and height from the image
Expand Down
61 changes: 49 additions & 12 deletions src/publish/gh-pages/gh-pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { joinUrl } from "../../core/url.ts";
import { completeMessage, withSpinner } from "../../core/console.ts";
import { renderForPublish } from "../common/publish.ts";
import { RenderFlags } from "../../command/render/types.ts";
import { gitCmds, gitVersion } from "../../core/git.ts";
import { gitBranchExists, gitCmds, gitVersion } from "../../core/git.ts";
import {
anonymousAccount,
gitHubContextForPublish,
Expand Down Expand Up @@ -71,7 +71,7 @@ async function publishRecord(
input: string | ProjectContext,
): Promise<PublishRecord | undefined> {
const ghContext = await gitHubContextForPublish(input);
if (ghContext.ghPages) {
if (ghContext.ghPagesRemote) {
return {
id: "gh-pages",
url: ghContext.siteUrl || ghContext.originUrl,
Expand Down Expand Up @@ -114,17 +114,27 @@ async function publish(
const ghContext = await gitHubContextForPublish(options.input);
verifyContext(ghContext, "GitHub Pages");

// create gh pages branch if there is none yet
const createGhPagesBranch = !ghContext.ghPages;
if (createGhPagesBranch) {
// create gh pages branch on remote and local if there is none yet
const createGhPagesBranchRemote = !ghContext.ghPagesRemote;
const createGhPagesBranchLocal = !ghContext.ghPagesLocal;
if (createGhPagesBranchRemote) {
// confirm
const confirmed = await Confirm.prompt({
let confirmed = await Confirm.prompt({
indent: "",
message: `Publish site to ${
ghContext.siteUrl || ghContext.originUrl
} using gh-pages?`,
default: true,
});
if (confirmed && !createGhPagesBranchLocal) {
confirmed = await Confirm.prompt({
indent: "",
message:
`A local gh-pages branch already exists. Should it be pushed to remote 'origin'?`,
default: true,
});
}

if (!confirmed) {
throw new Error();
}
Expand All @@ -135,9 +145,29 @@ async function publish(
}
const oldBranch = await gitCurrentBranch(input);
try {
await gitCreateGhPages(input);
// Create and push if necessary, or just push local branch
if (createGhPagesBranchLocal) {
await gitCreateGhPages(input);
} else {
await gitPushGhPages(input);
}
} catch {
// Something failed so clean up, i.e
// if we created the branch then delete it.
// Example of failure: Auth error on push (https://github.com/quarto-dev/quarto-cli/issues/9585)
if (createGhPagesBranchLocal && await gitBranchExists("gh-pages")) {
await gitCmds(input, [
["checkout", oldBranch],
["branch", "-D", "gh-pages"],
]);
}
throw new Error(
"Publishing to gh-pages with `quarto publish gh-pages` failed.",
);
} finally {
await gitCmds(input, [["checkout", oldBranch]]);
if (await gitCurrentBranch(input) !== oldBranch) {
await gitCmds(input, [["checkout", oldBranch]]);
}
if (stash) {
await gitStashApply(input);
}
Expand Down Expand Up @@ -191,7 +221,7 @@ async function publish(
/^https:\/\/(.+?)\.github\.io\/$/,
);
if (defaultSiteMatch) {
if (createGhPagesBranch) {
if (createGhPagesBranchRemote) {
notifyGhPagesBranch = true;
} else {
try {
Expand All @@ -207,7 +237,7 @@ async function publish(
}

// if this is an update then warn that updates may require a browser refresh
if (!createGhPagesBranch && !notifyGhPagesBranch) {
if (!createGhPagesBranchRemote && !notifyGhPagesBranch) {
info(colors.yellow(
"NOTE: GitHub Pages sites use caching so you might need to click the refresh\n" +
"button within your web browser to see changes after deployment.\n",
Expand Down Expand Up @@ -360,7 +390,14 @@ async function gitCreateGhPages(dir: string) {
await gitCmds(dir, [
["checkout", "--orphan", "gh-pages"],
["rm", "-rf", "--quiet", "."],
["commit", "--allow-empty", "-m", `Initializing gh-pages branch`],
["push", "origin", `HEAD:gh-pages`],
["commit", "--allow-empty", "-m", "Initializing gh-pages branch"],
]);
await gitPushGhPages(dir);
}

async function gitPushGhPages(dir: string) {
if (await gitCurrentBranch(dir) !== "gh-pages") {
await gitCmds(dir, [["checkout", "gh-pages"]]);
}
await gitCmds(dir, [["push", "origin", "HEAD:gh-pages"]]);
}
2 changes: 1 addition & 1 deletion src/publish/huggingface/huggingface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async function publishRecord(
input: string | ProjectContext,
): Promise<PublishRecord | undefined> {
const ghContext = await gitHubContextForPublish(input);
if (ghContext.ghPages) {
if (ghContext.ghPagesRemote) {
return {
id: kHuggingFace,
url: ghContext.siteUrl || ghContext.originUrl,
Expand Down
3 changes: 3 additions & 0 deletions src/resources/formats/html/quarto.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ window.document.addEventListener("DOMContentLoaded", function (_event) {
for (const child of el.children) {
child.style.opacity = 0;
child.style.overflow = "hidden";
child.style.pointerEvents = "none";
}

nexttick(() => {
Expand Down Expand Up @@ -360,6 +361,7 @@ window.document.addEventListener("DOMContentLoaded", function (_event) {

const clone = child.cloneNode(true);
clone.style.opacity = 1;
clone.style.pointerEvents = null;
clone.style.display = null;
toggleContents.append(clone);
}
Expand Down Expand Up @@ -434,6 +436,7 @@ window.document.addEventListener("DOMContentLoaded", function (_event) {
for (const child of el.children) {
child.style.opacity = 1;
child.style.overflow = null;
child.style.pointerEvents = null;
}

const placeholderEl = window.document.getElementById(
Expand Down
Loading

0 comments on commit 4601634

Please sign in to comment.