html2canvas icon indicating copy to clipboard operation
html2canvas copied to clipboard

underline missing bug

Open dongguoqiang1994 opened this issue 7 years ago • 5 comments

https://jsfiddle.net/w90erdL6/1/

<div id="capture" style="padding: 10px;">
    hehe:<span style="text-decoration-line: underline">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
    hehe:<span style="text-decoration-line: underline">1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
</div>
<script src="https://unpkg.com/[email protected]/dist/html2canvas.min.js"></script>
<script>
    html2canvas(document.querySelector("#capture")).then(canvas => {
        document.body.appendChild(canvas)
    });
</script>

If the span tag only includes &nbsp;, the style of text-decoration-line: underline is misplaced. But if it contains any content, such as &#8203;, the style will be okay.

html2canvas version tested with: 1.0.0-alpha.12 Browser & version: latest Chrome and latest Firefox Operating system: Window 10

dongguoqiang1994 avatar Aug 14 '18 06:08 dongguoqiang1994

Did anyone solve this problem in the end, find a way, and ask the great god to answer! ! !

sugusgeekery avatar May 07 '20 02:05 sugusgeekery

最新版本问题还是存在,但是在空格中间打一个字比如 <span style="text-decoration-line: underline">&nbsp;&nbsp;&nbsp; 1 &nbsp;&nbsp;&nbsp;</span> 空白的下划线就可以出现。

otizis avatar Mar 06 '23 08:03 otizis

最新版本问题还是存在,但是在空格中间打一个字比如 <span style="text-decoration-line: underline">&nbsp;&nbsp;&nbsp; 1 &nbsp;&nbsp;&nbsp;</span> 空白的下划线就可以出现。

谢谢你给了我解决这个问题的灵感 在&nbsp;&nbsp;&nbsp;中 插入一个 &ZeroWidthSpace; 就可以了!

threetail avatar May 26 '23 09:05 threetail

最新版本问题还是存在,但是在空格中间打一个字比如 <span style="text-decoration-line: underline">&nbsp;&nbsp;&nbsp; 1 &nbsp;&nbsp;&nbsp;</span> 空白的下划线就可以出现。

谢谢你给了我解决这个问题的灵感 在&nbsp;&nbsp;&nbsp;中 插入一个 &ZeroWidthSpace; 就可以了!

You're a genius.

xweiba avatar Jul 02 '24 02:07 xweiba

Changing the source code from if (isTextNode(childNode) && childNode.data.trim().length > 0) to if (isTextNode(childNode) && childNode.data.length > 0) will fix the issue.

Please note that I have not done further scenario testing.

xweiba avatar Jul 02 '24 04:07 xweiba