javascript - Clipboard API: Leading spaces lost on first HTML paragraph when pasting into PowerPoint - Stack Overflow

I'm using the Clipboard API to copy styled HTML content with leading spaces into Microsoft PowerPo

I'm using the Clipboard API to copy styled HTML content with leading spaces into Microsoft PowerPoint, and I found that using a combination of   and mso-spacerun:yes works well — except for the first line (based on this question). For some reason, the indentation of the first paragraph gets collapsed down into at most one space when pasted into PowerPoint.

Here’s the full source code of what I’m doing:

const htmlText =
  // Indented with non-breaking spaces and mso-spacerun
  '<p><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;Three</span></p>' +
  '<p><span style="mso-spacerun:yes">&nbsp;&nbsp;Two</span></p>' +
  '<p><span style="mso-spacerun:yes">&nbsp;One</span></p>' +
  '<p><span style="mso-spacerun:yes">&nbsp;&nbsp;Two</span></p>'+
  '<p><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;Three</span></p>';

async function copyToClipboard() {
  try {
    const data = [
      new ClipboardItem({
        'text/html': new Blob([htmlText], { type: 'text/html' })
      })
    ];
    await navigator.clipboard.write(data);
    console.log('HTML copied to clipboard');
  } catch (err) {
    console.error('Failed to copy HTML:', err);
  }
}

When I paste this into PowerPoint:

  • The second, third, and fourth lines all keep their leading spaces as expected.
  • But the first line loses its indentation and appears left-aligned.

The following shows the result in powerpoint:

Has anyone else run into this?
Is there a workaround or specific formatting tweak that forces PowerPoint to respect the leading spaces on the first paragraph as well?

Thanks in advance!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744329616a4568824.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信