Skip to content

Commit

Permalink
Merge pull request #827 from Simon-Initiative/LEGACY-408-code-cdata
Browse files Browse the repository at this point in the history
fix toSlate parser to handle cdata inside mark (for code tag)
  • Loading branch information
rgachuhi authored Jul 6, 2021
2 parents 352c557 + d302d45 commit 5af6a9c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/data/content/learning/slate/toslate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ function handleBlock(item: Object, json: ValueJSON, backingTextProvider: Object)
}

// Given a style mark object, determine if it is the parent of
// another, nested mark. A regular mark would have a #text attr,
// so we simply check for that to be undefined.
// another, nested mark. A regular mark would have either a #text
// or #cdata attr, so we simply check that neither is defined.
function isNestedMark(item: Object): boolean {
return item['#text'] === undefined;
return item['#text'] === undefined && item['#cdata'] === undefined;
}

// Given a style mark object, determine if it is empty, that is it
Expand Down Expand Up @@ -345,9 +345,11 @@ function processMark(item: Object,
return;
}

// terminal mark should have unmarked text in either #cdata or #text attr
const itemText = item['#cdata'] !== undefined ? item['#cdata'] : item['#text'];
parent.nodes.push({
object: 'text',
text: item['#text'],
text: itemText,
marks: previousMarks.toArray(),
});

Expand Down

0 comments on commit 5af6a9c

Please sign in to comment.