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

tabsets - support .active #11821

Merged
merged 7 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions news/changelog-1.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ All changes included in 1.7:

## Other Fixes and Improvements

- ([#7260](https://github.com/quarto-dev/quarto-cli/issues/7260)): Add support for `active` class in tabsets so the `.active` tab shows up by default.
- ([#8613](https://github.com/quarto-dev/quarto-cli/issues/8613)): Fix `giscus` color on load to support dark mode (by @kv9898).
- ([#11441](https://github.com/quarto-dev/quarto-cli/issues/11441)): Don't add newlines around shortcodes during processing.
- ([#11643](https://github.com/quarto-dev/quarto-cli/issues/11643)): Improve highlighting of nested code block inside markdown code block, i.e. using ` ```{{python}} ` or ` ```python ` inside ` ````markdown` fenced code block.
29 changes: 26 additions & 3 deletions src/command/build-js/cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@

import { Command } from "cliffy/command/mod.ts";

import { esbuildCompile } from "../../core/esbuild.ts";
import {
ESBuildAnalysis,
esbuildAnalyze,
esbuildCompile,
} from "../../core/esbuild.ts";
import { buildIntelligenceResources } from "../../core/schema/build-schema-file.ts";
import { resourcePath } from "../../core/resources.ts";
import { formatResourcePath, resourcePath } from "../../core/resources.ts";
import { simple } from "acorn/walk";
import { Parser } from "acorn/acorn";
import classFields from "acorn-class-fields";
import { initYamlIntelligenceResourcesFromFilesystem } from "../../core/schema/utils.ts";

// initialize language handlers
import "../../core/handlers/handlers.ts";
import { join } from "../../deno_ral/path.ts";

function ensureAllowableIDESyntax(src: string, filename: string) {
const ast = Parser.extend(classFields).parse(src, {
Expand Down Expand Up @@ -126,11 +131,29 @@ async function buildYAMLJS() {
);
}

async function buildEsbuildAnalysisCache() {
// build the necessary esbuild analysis cache
const inputFiles = [
"quarto.js",
];
const analysisCache: Record<string, ESBuildAnalysis> = {};
for (const file of inputFiles) {
analysisCache[file] = await esbuildAnalyze(
formatResourcePath("html", file),
resourcePath(join("formats", "html")),
);
}
Deno.writeTextFileSync(
formatResourcePath("html", "esbuild-analysis-cache.json"),
JSON.stringify(analysisCache, null, 2),
);
}

export async function buildAssets() {
// this has to come first because buildYAMLJS depends on it.
await buildIntelligenceResources();

await buildYAMLJS();
await buildEsbuildAnalysisCache();
}

export const buildJsCommand = new Command()
Expand Down
54 changes: 54 additions & 0 deletions src/core/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,61 @@
* Copyright (C) 2021-2022 Posit Software, PBC
*/

import { assert } from "testing/asserts";
import { execProcess } from "./process.ts";
import { architectureToolsPath } from "./resources.ts";
import { TempContext } from "./temp-types.ts";
import { createTempContext } from "./temp.ts";
import { kQuartoVersion } from "../config/constants.ts";

type ESBuildAnalysisImport = {
path: string;
kind: string;
external: boolean;
};

type ESBuildOutputValue = {
imports: ESBuildAnalysisImport[];
entryPoint: string;
inputs: Record<string, { bytesInOutput: number }>;
bytes: number;
};

export type ESBuildAnalysis = {
inputs: Record<string, { bytes: number; format: string }>;
outputs: Record<string, ESBuildOutputValue>;
};

export async function esbuildAnalyze(
input: string,
workingDir: string,
tempContext?: TempContext,
): Promise<ESBuildAnalysis> {
let mustCleanup = false;
if (!tempContext) {
tempContext = createTempContext();
mustCleanup = true;
}

try {
const tempName = tempContext.createFile({ suffix: ".json" });
await esbuildCommand(
[
"--analyze=verbose",
`--metafile=${tempName}`,
"--outfile=/dev/null",
cscheid marked this conversation as resolved.
Show resolved Hide resolved
input,
],
"",
workingDir,
);
return JSON.parse(Deno.readTextFileSync(tempName)) as ESBuildAnalysis;
} finally {
if (mustCleanup) {
tempContext.cleanup();
}
}
}

export async function esbuildCompile(
input: string,
Expand Down Expand Up @@ -38,6 +91,7 @@ export async function esbuildCommand(
cmd,
cwd: workingDir,
stdout: "piped",
stderr: "piped",
},
input,
);
Expand Down
59 changes: 53 additions & 6 deletions src/format/html/format-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* Copyright (C) 2020-2022 Posit Software, PBC
*/
import { join } from "../../deno_ral/path.ts";
import { dirname, join, relative } from "../../deno_ral/path.ts";
import { warning } from "../../deno_ral/log.ts";

import * as ld from "../../core/lodash.ts";
Expand All @@ -14,7 +14,7 @@ import { Document, Element } from "../../core/deno-dom.ts";

import { renderEjs } from "../../core/ejs.ts";
import { mergeConfigs } from "../../core/config.ts";
import { formatResourcePath } from "../../core/resources.ts";
import { formatResourcePath, resourcePath } from "../../core/resources.ts";
import { TempContext } from "../../core/temp.ts";
import { asCssSize } from "../../core/css.ts";

Expand Down Expand Up @@ -114,6 +114,53 @@ import {
import { kQuartoHtmlDependency } from "./format-html-constants.ts";
import { registerWriterFormatHandler } from "../format-handlers.ts";
import { brandSassFormatExtras } from "../../core/sass/brand.ts";
import { ESBuildAnalysis, esbuildAnalyze } from "../../core/esbuild.ts";
import { assert } from "testing/asserts";

let esbuildAnalysisCache: Record<string, ESBuildAnalysis> | undefined;
export function esbuildCachedAnalysis(
input: string,
): ESBuildAnalysis {
if (!esbuildAnalysisCache) {
esbuildAnalysisCache = JSON.parse(
Deno.readTextFileSync(
formatResourcePath("html", "esbuild-analysis-cache.json"),
),
) as Record<string, ESBuildAnalysis>;
}
const result = esbuildAnalysisCache[input];
assert(result, `Cached analysis not found for ${input}`);
return result;
}

function recursiveModuleDependencies(
path: string,
): DependencyHtmlFile[] {
const result: DependencyHtmlFile[] = [];
const inpRelPath = relative(join(resourcePath("formats"), "html"), path);

result.push({
name: inpRelPath,
path: formatResourcePath("html", inpRelPath),
attribs: { type: "module" },
});

const analysis = esbuildCachedAnalysis(inpRelPath);
// console.log(JSON.stringify(analysis, null, 2));
for (const [_key, value] of Object.entries(analysis.outputs)) {
for (const imp of value.imports) {
if (imp.external) {
const relPath = relative(path, join(path, imp.path));
result.push({
name: relPath,
path: formatResourcePath("html", relPath),
attribs: { type: "module" },
});
}
}
}
return result;
}

export function htmlFormat(
figwidth: number,
Expand Down Expand Up @@ -313,10 +360,10 @@ export async function htmlFormatExtras(

// quarto.js helpers
if (bootstrap) {
scripts.push({
name: "quarto.js",
path: formatResourcePath("html", "quarto.js"),
});
const deps = recursiveModuleDependencies(
formatResourcePath("html", "quarto.js"),
);
scripts.push(...deps);
}

// tabby if required
Expand Down
79 changes: 51 additions & 28 deletions src/resources/editor/tools/vs-code.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21651,7 +21651,7 @@ var require_yaml_intelligence_resources = __commonJS({
"Short/abbreviated form of container-title;",
"A minor contributor to the item; typically cited using \u201Cwith\u201D before\nthe name when listed in a bibliography.",
"Curator of an exhibit or collection (e.g.&nbsp;in a museum).",
"Physical (e.g.&nbsp;size) or temporal (e.g.&nbsp;running time) dimensions of\nthe item.",
"Physical (e.g.&nbsp;size) or temporal (e.g.\uFFFD\uFFFDrunning time) dimensions of\nthe item.",
"Director (e.g.&nbsp;of a film).",
"Minor subdivision of a court with a <code>jurisdiction</code> for a\nlegal item",
"(Container) edition holding the item (e.g.&nbsp;\u201C3\u201D when citing a chapter\nin the third edition of a book).",
Expand Down Expand Up @@ -23616,6 +23616,14 @@ var require_yaml_intelligence_resources = __commonJS({
"Disambiguating year suffix in author-date styles (e.g.&nbsp;\u201Ca\u201D in \u201CDoe,\n1999a\u201D).",
"Manuscript configuration",
"internal-schema-hack",
{
short: "Include an automatically generated table of contents",
long: ""
},
{
short: "Use smart quotes in document output. Defaults to true.",
long: ""
},
"Project configuration.",
"Project type (<code>default</code>, <code>website</code>,\n<code>book</code>, or <code>manuscript</code>)",
"Files to render (defaults to all files)",
Expand Down Expand Up @@ -24188,12 +24196,12 @@ var require_yaml_intelligence_resources = __commonJS({
mermaid: "%%"
},
"handlers/mermaid/schema.yml": {
_internalId: 193535,
_internalId: 194269,
type: "object",
description: "be an object",
properties: {
"mermaid-format": {
_internalId: 193527,
_internalId: 194261,
type: "enum",
enum: [
"png",
Expand All @@ -24209,7 +24217,7 @@ var require_yaml_intelligence_resources = __commonJS({
exhaustiveCompletions: true
},
theme: {
_internalId: 193534,
_internalId: 194268,
type: "anyOf",
anyOf: [
{
Expand Down Expand Up @@ -24249,7 +24257,42 @@ var require_yaml_intelligence_resources = __commonJS({
"case-detection": true
},
$id: "handlers/mermaid"
}
},
"schema/document-typst.yml": [
{
name: "page-numbering",
tags: {
formats: [
"typst"
]
},
schema: {
anyOf: [
"string",
{
enum: [
false
]
}
]
},
description: {
short: "Include an automatically generated table of contents"
}
},
{
name: "smart",
tags: {
formats: [
"typst"
]
},
schema: "boolean",
description: {
short: "Use smart quotes in document output. Defaults to true."
}
}
]
};
}
});
Expand Down Expand Up @@ -24774,8 +24817,8 @@ function mappedIndexToLineCol(eitherText) {
};
}
function mappedLines(str2, keepNewLines = false) {
const lines2 = rangedLines(str2.value, keepNewLines);
return lines2.map((v) => mappedString(str2, [v.range]));
const lines3 = rangedLines(str2.value, keepNewLines);
return lines3.map((v) => mappedString(str2, [v.range]));
}

// parsing.ts
Expand Down Expand Up @@ -33575,9 +33618,7 @@ async function breakQuartoMd(src, validate2 = false, lenient = false) {
} else if (cell_type === "directive") {
cell.source = mappedString(src, mappedChunks.slice(1, -1), fileName);
}
if (mdTrimEmptyLines(lines(cell.sourceVerbatim.value)).length > 0 || cell.options !== void 0) {
nb.cells.push(cell);
}
nb.cells.push(cell);
lineBuffer.splice(0, lineBuffer.length);
}
};
Expand Down Expand Up @@ -33639,24 +33680,6 @@ async function breakQuartoMd(src, validate2 = false, lenient = false) {
await flushLineBuffer("markdown", srcLines.length);
return nb;
}
function mdTrimEmptyLines(lines2) {
const firstNonEmpty = lines2.findIndex((line) => line.trim().length > 0);
if (firstNonEmpty === -1) {
return [];
}
lines2 = lines2.slice(firstNonEmpty);
let lastNonEmpty = -1;
for (let i = lines2.length - 1; i >= 0; i--) {
if (lines2[i].trim().length > 0) {
lastNonEmpty = i;
break;
}
}
if (lastNonEmpty > -1) {
lines2 = lines2.slice(0, lastNonEmpty + 1);
}
return lines2;
}

// ../yaml-schema/format-aliases.ts
var formatAliases = void 0;
Expand Down
Loading
Loading