There is 1 comment.
 
 
XWiki Platform / cid:jira-generated-image-avatar-a388e162-e49b-42c2-ad71-da8b867b56fc 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-f817c36c-306f-480d-9d40-520b941eb063 James Wartell on 13/Aug/26 18:06
 
Adding this as a javascript extension on a template works as a workaround:


{code:java}
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': '
stringset -paged-polyfill-patched'
          },
          '
stringset -paged-polyfill-patched': {
            'paged-polyfill': 'paged-polyfill-patched'
          }
        }
      });

      define('
stringset -paged-polyfill-patched', ['paged-polyfill'], function(PagedPolyfill) {
        if (!window.
__PagedStringSetPatchRegistered __stringSetPagedStringSetPatchRegistered ) {
          window.
__PagedStringSetPatchRegistered __stringSetPagedStringSetPatchRegistered = 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.');
        }

        return PagedPolyfill;
      });
    } catch (e) {
      console.log(e);
    }
    // ===== END PagedJS string-set quote patch =====
  }
});
{code}