Skip to content

Commit 79383df

Browse files
committed
tracer html output of links to other formats
1 parent 8233b5b commit 79383df

File tree

4 files changed

+40
-7
lines changed

4 files changed

+40
-7
lines changed

src/command/render/render-files.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ import {
8989
} from "../../core/timing.ts";
9090
import { satisfies } from "semver/mod.ts";
9191
import { quartoConfig } from "../../core/quarto.ts";
92-
import { registerProjectType } from "../../project/types/project-types.ts";
9392

9493
export async function renderExecute(
9594
context: RenderContext,

src/command/render/render.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ export async function renderPandoc(
208208
pandocOptions,
209209
htmlPostProcessors,
210210
htmlFinalizers,
211+
renderedFormats,
211212
);
212213

213214
// Compute the path to the output file
@@ -415,6 +416,7 @@ async function runHtmlPostprocessors(
415416
options: PandocOptions,
416417
htmlPostprocessors: Array<HtmlPostProcessor>,
417418
htmlFinalizers: Array<(doc: Document) => Promise<void>>,
419+
renderedFormats: RenderedFormat[],
418420
): Promise<HtmlPostProcessResult> {
419421
const postProcessResult: HtmlPostProcessResult = {
420422
resources: [],
@@ -430,7 +432,14 @@ async function runHtmlPostprocessors(
430432
const doc = await parseHtml(htmlInput);
431433
for (let i = 0; i < htmlPostprocessors.length; i++) {
432434
const postprocessor = htmlPostprocessors[i];
433-
const result = await postprocessor(doc, inputMetadata, inputTraits);
435+
const result = await postprocessor(
436+
doc,
437+
{
438+
inputMetadata,
439+
inputTraits,
440+
renderedFormats
441+
}
442+
);
434443

435444
postProcessResult.resources.push(...result.resources);
436445
postProcessResult.supporting.push(...result.supporting);

src/command/render/types.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ export interface PandocInputTraits {
6464

6565
export type HtmlPostProcessor = (
6666
doc: Document,
67-
inputMedata: Metadata,
68-
inputTraits: PandocInputTraits,
67+
options: {
68+
inputMetadata: Metadata;
69+
inputTraits: PandocInputTraits;
70+
renderedFormats: RenderedFormat[];
71+
},
6972
) => Promise<HtmlPostProcessResult>;
7073

7174
export interface HtmlPostProcessResult {

src/format/html/format-html-bootstrap.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
kLinkCitations,
1919
kQuartoTemplateParams,
2020
kSectionDivs,
21+
kTitle,
2122
kTocDepth,
2223
kTocLocation,
2324
} from "../../config/constants.ts";
@@ -52,6 +53,7 @@ import {
5253
HtmlPostProcessor,
5354
HtmlPostProcessResult,
5455
PandocInputTraits,
56+
RenderedFormat,
5557
} from "../../command/render/types.ts";
5658
import { processDocumentAppendix } from "./format-html-appendix.ts";
5759
import {
@@ -63,6 +65,7 @@ import {
6365
} from "./format-html-title.ts";
6466
import { kTemplatePartials } from "../../command/render/template.ts";
6567
import { TempContext } from "../../core/temp-types.ts";
68+
import { isHtmlOutput } from "../../config/format.ts";
6669

6770
export function formatPageLayout(format: Format) {
6871
return format.metadata[kPageLayout] as string || kPageLayoutArticle;
@@ -214,8 +217,11 @@ function bootstrapHtmlPostprocessor(
214217
): HtmlPostProcessor {
215218
return async (
216219
doc: Document,
217-
_inputMedata: Metadata,
218-
inputTraits: PandocInputTraits,
220+
options: {
221+
inputMetadata: Metadata;
222+
inputTraits: PandocInputTraits;
223+
renderedFormats: RenderedFormat[];
224+
},
219225
): Promise<HtmlPostProcessResult> => {
220226
// use display-7 style for title
221227
const title = doc.querySelector("header > .title");
@@ -372,14 +378,30 @@ function bootstrapHtmlPostprocessor(
372378
) {
373379
await processDocumentAppendix(
374380
input,
375-
inputTraits,
381+
options.inputTraits,
376382
format,
377383
flags,
378384
doc,
379385
offset,
380386
);
381387
}
382388

389+
// Inject links to other formats if there is another
390+
// format that of this file that has been rendered
391+
if (options.renderedFormats.length > 1) {
392+
const el = doc.createElement("div");
393+
for (const renderedFormat of options.renderedFormats) {
394+
if (!isHtmlOutput(renderedFormat.format.pandoc, true)) {
395+
const link = doc.createElement("a");
396+
link.setAttribute("href", renderedFormat.path);
397+
link.innerHTML = `${renderedFormat.format.pandoc.to}`;
398+
el.appendChild(link);
399+
el.appendChild(doc.createElement("br"));
400+
}
401+
}
402+
doc.body.appendChild(el);
403+
}
404+
383405
// no resource refs
384406
return Promise.resolve({ resources, supporting: [] });
385407
};

0 commit comments

Comments
 (0)