@@ -102,7 +102,7 @@ function render_typst_brand_yaml()
102102            local  declImage  =  {}
103103            for  name , image  in  pairs (logo .images ) do 
104104              declImage [name ] =  {
105-                 path  =  quote_string (image .path ): gsub ( ' \\ ' ,  ' \\\\ ' ) ,
105+                 path  =  quote_string (image .path ),
106106                alt  =  quote_string (image .alt ),
107107              }
108108            end 
@@ -114,7 +114,7 @@ function render_typst_brand_yaml()
114114          for  _ , size  in  pairs ({' small'  , ' medium'  , ' large'  }) do 
115115            if  logo [size ] then 
116116              declLogo [size ] =  {
117-                 path  =  quote_string (logo [size ].path ): gsub ( ' \\ ' ,  ' \\\\ ' ) ,
117+                 path  =  quote_string (logo [size ].path ),
118118                alt  =  quote_string (logo [size ].alt ),
119119              }
120120            end 
@@ -239,102 +239,103 @@ function render_typst_brand_yaml()
239239            ' , content)' 
240240          }))
241241        end 
242-   
243-         --  logo
244-         local  logo  =  param (' logo'  )
245-         local  logoOptions  =  {}
246-         local  foundLogo  =  null 
247-          if  logo  then 
248-           if  type (logo ) ==  ' string'  then 
249-             foundLogo  =  _quarto .modules .brand .get_logo (brandMode , logo ) or  {path = logo }
250-           elseif  type (logo ) ==  ' table'  then 
251-             for  k , v  in  pairs (logo ) do 
252-               logoOptions [k ] =  v 
253-             end 
254-             if  logo .path  then 
255-               foundLogo  =   _quarto .modules .brand .get_logo (brandMode , logo .path ) or  {path = logo }
256-             end 
242+       end 
243+     end ,
244+     Meta  =  function (meta )
245+       local  brand  =  param (' brand'  )
246+       local  brandMode  =  param (' brand-mode'  ) or  ' light' 
247+       brand  =  brand  and  brand [brandMode ]
248+       --  it can contain the path but we want to store an object here
249+       if  not  meta .brand  or  pandoc .utils .type (meta .brand ) ==  ' Inlines'  then 
250+         meta .brand  =  {}
251+       end 
252+       --  logo
253+       local  logo  =  param (' logo'  )
254+       local  logoOptions  =  {}
255+       local  foundLogo  =  null 
256+       if  logo  then 
257+         if  type (logo ) ==  ' string'  then 
258+           foundLogo  =  _quarto .modules .brand .get_logo (brandMode , logo ) or  {path = logo }
259+         elseif  type (logo ) ==  ' table'  then 
260+           for  k , v  in  pairs (logo ) do 
261+             logoOptions [k ] =  v 
262+           end 
263+           if  logo .path  then 
264+             foundLogo  =  _quarto .modules .brand .get_logo (brandMode , logo .path ) or  {path = logo }
257265          end 
258266        end 
259-          if   not   foundLogo   and   brand . processedData . logo   then 
260-            local   tries   =  { ' large ' ,  ' small ' ,  ' medium ' }  --  low to high priority 
261-            foundLogo  =  _quarto .modules .brand .get_logo (brandMode , ' medium'  )
262-              or  _quarto .modules .brand .get_logo (brandMode , ' small'  )
263-              or  _quarto .modules .brand .get_logo (brandMode , ' large'  )
264-          end 
265-          if  foundLogo  then 
266-            logoOptions .path  =  foundLogo .path 
267-            logoOptions .alt  =  foundLogo .alt 
267+       end 
268+       if   not   foundLogo   and   brand   and   brand . processedData   and   brand . processedData . logo   then 
269+         foundLogo  =  _quarto .modules .brand .get_logo (brandMode , ' medium'  )
270+           or  _quarto .modules .brand .get_logo (brandMode , ' small'  )
271+           or  _quarto .modules .brand .get_logo (brandMode , ' large'  )
272+       end 
273+       if  foundLogo  then 
274+         logoOptions .path  =  foundLogo .path 
275+         logoOptions .alt  =  foundLogo .alt 
268276
269-           local  pads  =  {}
270-           for  k , v  in  _quarto .utils .table .sortedPairs (logoOptions ) do 
271-             if  k  ==  ' padding'  then 
272-               local  widths  =  {}
273-               _quarto .modules .typst .css .parse_multiple (v , 5 , function (s , start )
274-                 local  width , newstart  =  _quarto .modules .typst .css .consume_width (s , start )
275-                 table.insert (widths , width )
276-                 return  newstart 
277-               end )
278-               local  sides  =  _quarto .modules .typst .css .expand_side_shorthand (
279-                 widths ,
280-                 ' widths in padding list: '  ..  v )
281-               pads .top  =  sides .top 
282-               pads .right  =  sides .right 
283-               pads .bottom  =  sides .bottom 
284-               pads .left  =  sides .left 
285-             elseif  k :find  ' ^padding-'  then 
286-               local  _ , ndash  =  k :gsub (' -'  , ' '  )
287-               if  ndash  ==  1  then 
288-                 local  side  =  k :match (' ^padding--(%a+)'  )
289-                 local  padding_sides  =  {' left'  , ' top'  , ' right'  , ' bottom'  }
290-                 if  tcontains (padding_sides , side ) then 
291-                   pads [side ] =  _quarto .modules .typst .css .translate_length (v )
292-                 else 
293-                   quarto .log .warning (' invalid padding key '  ..  k )
294-                 end 
277+         local  pads  =  {}
278+         for  k , v  in  _quarto .utils .table .sortedPairs (logoOptions ) do 
279+           if  k  ==  ' padding'  then 
280+             local  widths  =  {}
281+             _quarto .modules .typst .css .parse_multiple (v , 5 , function (s , start )
282+               local  width , newstart  =  _quarto .modules .typst .css .consume_width (s , start )
283+               table.insert (widths , width )
284+               return  newstart 
285+             end )
286+             local  sides  =  _quarto .modules .typst .css .expand_side_shorthand (
287+               widths ,
288+               ' widths in padding list: '  ..  v )
289+             pads .top  =  sides .top 
290+             pads .right  =  sides .right 
291+             pads .bottom  =  sides .bottom 
292+             pads .left  =  sides .left 
293+           elseif  k :find  ' ^padding-'  then 
294+             local  _ , ndash  =  k :gsub (' -'  , ' '  )
295+             if  ndash  ==  1  then 
296+               local  side  =  k :match (' ^padding--(%a+)'  )
297+               local  padding_sides  =  {' left'  , ' top'  , ' right'  , ' bottom'  }
298+               if  tcontains (padding_sides , side ) then 
299+                 pads [side ] =  _quarto .modules .typst .css .translate_length (v )
295300              else 
296301                quarto .log .warning (' invalid padding key '  ..  k )
297302              end 
298-             end 
299-           end 
300-           local  inset  =  nil 
301-           if  next (pads ) then 
302-             if  pads .top  ==  pads .right  and 
303-               pads .right  ==  pads .bottom  and 
304-               pads .bottom  ==  pads .left 
305-             then 
306-               inset  =  pads .top 
307-             elseif  pads .top  ==  pads .bottom  and  pads .left  ==  pads .right  then 
308-               inset  =  _quarto .modules .typst .as_typst_dictionary ({x  =  pads .left , y  =  pads .top })
309303            else 
310-               inset   =   _quarto . modules . typst . as_typst_dictionary ( pads )
304+               quarto . log . warning ( ' invalid padding key  '  ..   k )
311305            end 
312-           else 
313-             inset  =  ' 0.75in' 
314306          end 
315-           logoOptions .width  =  _quarto .modules .typst .css .translate_length (logoOptions .width  or  ' 1.5in'  )
316-           logoOptions .location  =  logoOptions .location  and 
317-             location_to_typst_align (logoOptions .location ) or  ' left+top' 
318-           quarto .log .debug (' logo options'  , logoOptions )
319-           local  altProp  =  logoOptions .alt  and  (' , alt: "'  ..  logoOptions .alt  ..  ' "'  ) or  ' ' 
320-           local  imageFilename  =  logoOptions .path 
321-           if  _quarto .modules .mediabag .should_mediabag (imageFilename ) then 
322-             imageFilename  =  _quarto .modules .mediabag .resolved_url_cache [logoOptions .path ] or  _quarto .modules .mediabag .fetch_and_store_image (logoOptions .path )
323-             imageFilename  =  _quarto .modules .mediabag .write_mediabag_entry (imageFilename ) or  imageFilename 
307+         end 
308+         local  inset  =  nil 
309+         if  next (pads ) then 
310+           if  pads .top  ==  pads .right  and 
311+             pads .right  ==  pads .bottom  and 
312+             pads .bottom  ==  pads .left 
313+           then 
314+             inset  =  pads .top 
315+           elseif  pads .top  ==  pads .bottom  and  pads .left  ==  pads .right  then 
316+             inset  =  _quarto .modules .typst .as_typst_dictionary ({x  =  pads .left , y  =  pads .top })
324317          else 
325-             --  backslashes need to be doubled for Windows
326-             imageFilename  =  string.gsub (imageFilename , ' \\ '  , ' \\\\ '  )
318+             inset  =  _quarto .modules .typst .as_typst_dictionary (pads )
327319          end 
328-           quarto .doc .include_text (' in-header'  ,
329-             ' #set page(background: align('  ..  logoOptions .location  ..  ' , box(inset: '  ..  inset  ..  ' , image("'  ..  imageFilename  ..  ' ", width: '  ..  logoOptions .width  ..  altProp  ..  ' ))))'  )
330-         end   
331-       end 
332-     end ,
333-     Meta  =  function (meta )
334-       local  brandMode  =  param (' brand-mode'  ) or  ' light' 
335-       --  it can contain the path but we want to store an object here
336-       if  not  meta .brand  or  pandoc .utils .type (meta .brand ) ==  ' Inlines'  then 
337-         meta .brand  =  {}
320+         else 
321+           inset  =  ' 0.75in' 
322+         end 
323+         logoOptions .width  =  _quarto .modules .typst .css .translate_length (logoOptions .width  or  ' 1.5in'  )
324+         logoOptions .inset  =  inset 
325+         logoOptions .location  =  logoOptions .location  and 
326+           location_to_typst_align (logoOptions .location ) or  ' left+top' 
327+         quarto .log .debug (' logo options'  , logoOptions )
328+         local  imageFilename  =  logoOptions .path 
329+         if  _quarto .modules .mediabag .should_mediabag (imageFilename ) then 
330+           imageFilename  =  _quarto .modules .mediabag .resolved_url_cache [logoOptions .path ] or  _quarto .modules .mediabag .fetch_and_store_image (logoOptions .path )
331+           imageFilename  =  _quarto .modules .mediabag .write_mediabag_entry (imageFilename ) or  imageFilename 
332+           imageFilename  =  imageFilename  and  imageFilename :gsub (' \\ _'  , ' _'  )
333+         else 
334+           --  backslashes need to be doubled for Windows
335+           imageFilename  =  string.gsub (imageFilename , ' \\ '  , ' \\\\ '  )
336+         end 
337+         logoOptions .path  =  pandoc .RawInline (' typst'  , imageFilename )
338+         meta .logo  =  logoOptions 
338339      end 
339340      meta .brand .typography  =  meta .brand .typography  or  {}
340341      local  base  =  _quarto .modules .brand .get_typography (brandMode , ' base'  )
0 commit comments