Skip to content

Commit

Permalink
Merge d94d337 into 30afd5f
Browse files Browse the repository at this point in the history
  • Loading branch information
no-chris committed Dec 24, 2023
2 parents 30afd5f + d94d337 commit 1fd8a32
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import chordLyricLineTpl from './tpl/chordLyricLine';
import _intersection from 'lodash/intersection';
import _last from 'lodash/last';
import stripTags from '../../core/dom/stripTags';
import htmlToElement from '../../core/dom/htmlToElement';

const breakPointsClasses = [
'cmChordSymbol',
Expand Down Expand Up @@ -42,7 +43,7 @@ export default function renderChordLyricLine(chordLine, lyricLine) {
}

function getAllChordTokens(chordLine) {
const chordLineNodes = getChordLineNodes(chordLine);
const chordLineNodes = htmlToElement(chordLine);

const allChordTokens = [];
// using an object as a counter instead of an integer
Expand All @@ -54,12 +55,6 @@ function getAllChordTokens(chordLine) {
return allChordTokens;
}

function getChordLineNodes(chordLine) {
// Since a chordLine is only made of ChordMark-generated html, we consider it safe
// eslint-disable-next-line no-unsanitized/method
return document.createRange().createContextualFragment(chordLine);
}

// recursive
function addChordTokens(startNode, allNodes, textIndex) {
startNode.childNodes.forEach((childNode) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { parseSong, renderSong } from '../../../../src/chordMark';
import htmlToElement from '../../../../src/core/dom/htmlToElement';
import stripTags from '../../../../src/core/dom/stripTags';

describe('renderChordLyricLine', () => {
Expand Down Expand Up @@ -312,8 +313,7 @@ describe('renderChordLyricLine', () => {
// helpers functions
function getAllNodesOf(html, className) {
const allNodesOf = [];
// eslint-disable-next-line no-unsanitized/method
const startNode = document.createRange().createContextualFragment(html);
const startNode = htmlToElement(html);
addNodesOf(startNode, className, allNodesOf);
return allNodesOf;
}
Expand Down

0 comments on commit 1fd8a32

Please sign in to comment.