admin管理员组文章数量:1402803
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"> Three</span></p>' +
'<p><span style="mso-spacerun:yes"> Two</span></p>' +
'<p><span style="mso-spacerun:yes"> One</span></p>' +
'<p><span style="mso-spacerun:yes"> Two</span></p>'+
'<p><span style="mso-spacerun:yes"> 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!
本文标签:
版权声明:本文标题:javascript - Clipboard API: Leading spaces lost on first HTML paragraph when pasting into PowerPoint - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744329615a2600899.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论