Skip to content

Commit

Permalink
fix: new line is just div tag (no br) in IE10
Browse files Browse the repository at this point in the history
  • Loading branch information
Sohee Lee committed Jan 21, 2019
1 parent 52f0fcd commit 6629d01
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/js/wwCodeBlockManager.js
Expand Up @@ -7,6 +7,9 @@ import util from 'tui-code-snippet';

import domUtils from './domUtils';

const isIE10 = util.browser.msie && util.browser.version === 10;
const brString = isIE10 ? '' : '<br>';

const tagEntities = {
'&': '&amp;',
'<': '&lt;',
Expand Down Expand Up @@ -179,7 +182,7 @@ class WwCodeBlockManager {

const resultText = $pre.text().replace(/\s+$/, '');
$pre.empty();
$pre.html(resultText ? resultText : '<br>');
$pre.html(resultText ? resultText : brString);

if (lang) {
$pre.attr('data-language', lang);
Expand Down Expand Up @@ -242,8 +245,9 @@ class WwCodeBlockManager {
*/
_isEmptyLine(node) {
const {nodeName, childNodes} = node;
const isEmpty = isIE10 ? node.textContent === '' : childNodes.length === 1 && childNodes[0].nodeName === 'BR';

return nodeName === 'DIV' && childNodes.length === 1 && childNodes[0].nodeName === 'BR';
return nodeName === 'DIV' && isEmpty;
}

/**
Expand Down Expand Up @@ -310,7 +314,7 @@ class WwCodeBlockManager {

const firstDiv = document.createElement('div');
const firstLine = strArray.shift();
firstDiv.innerHTML = `${firstLine}<br>`;
firstDiv.innerHTML = `${firstLine}${brString}`;
newFrag.appendChild(firstDiv);

if (strArray.length) {
Expand Down

0 comments on commit 6629d01

Please sign in to comment.