@@ -66,6 +66,7 @@ import {
6666import { kTemplatePartials } from "../../command/render/template.ts" ;
6767import { TempContext } from "../../core/temp-types.ts" ;
6868import { isHtmlOutput } from "../../config/format.ts" ;
69+ import { basename } from "https://deno.land/[email protected] /path/win32.ts" ; 6970
7071export function formatPageLayout ( format : Format ) {
7172 return format . metadata [ kPageLayout ] as string || kPageLayoutArticle ;
@@ -302,6 +303,36 @@ function bootstrapHtmlPostprocessor(
302303 tocTarget ?. remove ( ) ;
303304 }
304305
306+ // Inject links to other formats if there is another
307+ // format that of this file that has been rendered
308+ if ( options . renderedFormats . length > 1 ) {
309+ let dlLinkTarget = doc . querySelector ( `nav[role="doc-toc"]` ) ;
310+ if ( dlLinkTarget === null ) {
311+ dlLinkTarget = doc . querySelector ( "#quarto-margin-sidebar" ) ;
312+ }
313+
314+ if ( dlLinkTarget ) {
315+ const heading = doc . createElement ( "h2" ) ;
316+ heading . innerText = "Related" ;
317+ dlLinkTarget . appendChild ( heading ) ;
318+
319+ const formatList = doc . createElement ( "ul" ) ;
320+
321+ for ( const renderedFormat of options . renderedFormats ) {
322+ if ( ! isHtmlOutput ( renderedFormat . format . pandoc , true ) ) {
323+ const li = doc . createElement ( "li" ) ;
324+ const link = doc . createElement ( "a" ) ;
325+ link . setAttribute ( "href" , renderedFormat . path ) ;
326+ link . setAttribute ( "download" , basename ( renderedFormat . path ) ) ;
327+ link . innerHTML = `${ renderedFormat . format . pandoc . to } ` ;
328+ li . appendChild ( link ) ;
329+ formatList . appendChild ( li ) ;
330+ }
331+ }
332+ dlLinkTarget . appendChild ( formatList ) ;
333+ }
334+ }
335+
305336 // default treatment for computational tables
306337 const addTableClasses = ( table : Element , computational = false ) => {
307338 table . classList . add ( "table" ) ;
@@ -386,22 +417,6 @@ function bootstrapHtmlPostprocessor(
386417 ) ;
387418 }
388419
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-
405420 // no resource refs
406421 return Promise . resolve ( { resources, supporting : [ ] } ) ;
407422 } ;
0 commit comments