Skip to content

Commit

Permalink
🐛 fix #320
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Apr 17, 2020
1 parent 08e5530 commit ad63020
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@

### v3.1.12 / 2020-04-17

* [320](https://github.com/Vanessa219/vditor/issues/320) 代码区点击复制代码时自动去掉行号 `修复缺陷`
* [314](https://github.com/Vanessa219/vditor/issues/314) 添加图片懒加载设置 `引入特性`
* [319](https://github.com/Vanessa219/vditor/issues/319) add ctrl+shift+e button to toolbar for smartphone `改进功能`
* [312](https://github.com/Vanessa219/vditor/issues/312) 支持块级元素上下移动 `引入特性`
Expand Down
12 changes: 11 additions & 1 deletion src/ts/markdown/codeRender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ export const codeRender = (element: HTMLElement, lang: (keyof II18nLang) = "zh_C
return;
}

let codeText = e.innerText;
if (e.classList.contains("highlight-chroma")) {
const codeElement = document.createElement("code");
codeElement.innerHTML = e.innerHTML;
codeElement.querySelectorAll(".highlight-ln").forEach((item: HTMLElement) => {
item.remove();
});
codeText = codeElement.innerText;
}

const divElement = document.createElement("div");
divElement.className = "vditor-copy";
divElement.innerHTML = `<span aria-label="${i18n[lang].copy}"
Expand All @@ -26,7 +36,7 @@ class="vditor-tooltipped vditor-tooltipped__w"
onclick="this.previousElementSibling.select();document.execCommand('copy');` +
`this.setAttribute('aria-label', '${i18n[lang].copied}')">${copySVG}</span>`;
const textarea = document.createElement("textarea");
textarea.value = code160to32(e.innerText);
textarea.value = code160to32(codeText);
divElement.insertAdjacentElement("afterbegin", textarea);

e.before(divElement);
Expand Down

0 comments on commit ad63020

Please sign in to comment.