Shorten Welcome Message fix
We want to ignore certain tags when they show up in the HTML. This now ignores script tags and link tags (for stylesheets)
This commit is contained in:
@@ -12,6 +12,10 @@
|
||||
function clampHtmlByWords(root, wordsLeft) {
|
||||
'use strict';
|
||||
|
||||
if (root.nodeName === 'SCRIPT' || root.nodeName === 'LINK') {
|
||||
return wordsLeft; // early exit and ignore
|
||||
}
|
||||
|
||||
var remaining = wordsLeft;
|
||||
var nodes = Array.from(root.childNodes ? root.childNodes : []);
|
||||
var words, chopped;
|
||||
|
||||
@@ -3,6 +3,8 @@ import ReactDOM from 'react-dom';
|
||||
import { clampHtmlByWords } from './clamp-html';
|
||||
|
||||
let container;
|
||||
const scriptTag = '<script src="/asset-v1:edX+testX+1T2021+type@asset+block/script.js"></script>';
|
||||
const stylesheet = '<link rel="stylesheet" type="text/css" href="/asset-v1:edX+testX+1T2021+type@asset+block/introjs.css">';
|
||||
|
||||
beforeEach(() => {
|
||||
container = document.createElement("div");
|
||||
@@ -25,6 +27,9 @@ describe('ClampHtml', () => {
|
||||
['a <i>aa <em>aaa</em></i>', 2, 'a <i>aa…</i>'],
|
||||
['a <i>aa <em>aaa</em> ab</i>', 3, 'a <i>aa <em>aaa…</em></i>'],
|
||||
['a <i>aa ab</i> b c', 4, 'a <i>aa ab</i> b…'],
|
||||
[scriptTag + 'a b c', 2, scriptTag + 'a b…'],
|
||||
[stylesheet + 'a b c', 2, stylesheet + 'a b…'],
|
||||
[scriptTag + stylesheet + 'a b c', 2, scriptTag + stylesheet + 'a b…'],
|
||||
])('clamps by words: %s, %i', (input, wordsLeft, expected) => {
|
||||
const div = ReactDOM.render(<div dangerouslySetInnerHTML={{ __html: input }} />, container);
|
||||
clampHtmlByWords(div, wordsLeft);
|
||||
|
||||
Reference in New Issue
Block a user