There is 1 comment.
 
 
XWiki Platform / cid:jira-generated-image-avatar-1899f3ca-6159-4c77-8067-eceeddc35fdb XWIKI-24539 Open

Paged.js named strings are serialized with unmatched quotes in PDF Export (string-set content(text))

 
View issue   ยท   Add comment
 

1 comment

 
cid:jira-generated-image-avatar-878f3951-8067-4ad7-987d-015dfbc31835 James Wartell on 13/Aug/26 17:40
 

Adding this as a javascript extension on a template works as a workaround:

require(['xwiki-page-ready'], function(pageReady) {
  if (window.XWiki?.contextaction === 'export') {    // ===== BEGIN PagedJS string-set quote patch =====
    // Workaround for Paged.js 0.4.3 bug where string-set variables are emitted like:
    //   --pagedjs-string-first-section-name: "Definitions;
    // instead of:
    //   --pagedjs-string-first-section-name: "Definitions";
    //
    // Do not directly require(['paged-polyfill']) here. XWiki.PDFExport.Sheet controls when
    // PagedJS is loaded. This wrapper only intercepts that later load.
    try {
      require.config({
        map: {
          '*': {
            'paged-polyfill': 'garney-paged-polyfill-patched'
          },
          'garney-paged-polyfill-patched': {
            'paged-polyfill': 'paged-polyfill-patched'
          }
        }
      });      define('garney-paged-polyfill-patched', ['paged-polyfill'], function(PagedPolyfill) {
        if (!window.__garneyPagedStringSetPatchRegistered) {
          window.__garneyPagedStringSetPatchRegistered = true;          class FixStringSetQuotes extends Paged.Handler {
            afterPageLayout(pageFragment) {
              console.log(
                'afterPageLayout',
                pageFragment.id
              );
              const style = pageFragment.style;              // Copy property names first because CSSStyleDeclaration is live.
              const properties = [];
              for (let i = 0; i < style.length; i++) {
                properties.push(style[i]);
              }              properties.forEach(function(property) {
                if (!property.startsWith('--pagedjs-string-')) {
                  return;
                }                const value = style.getPropertyValue(property).trim();                const quoteCount = (value.match(/"/g) || []).length;                if (value.startsWith('"') && quoteCount % 2 === 1) {
                  const fixed = value + '"';
                  style.setProperty(property, fixed);
                  console.log('Fixed PagedJS string-set variable:', property, value, '=>', fixed);
                }              });              
            } 
          }          
          Paged.registerHandlers(FixStringSetQuotes);
          console.log('PagedJS string-set quote patch registered.');
        }