From d302d45b6439ca473affa809f82d63cacc3bd584 Mon Sep 17 00:00:00 2001 From: Anders Weinstein Date: Tue, 6 Jul 2021 09:44:32 -0400 Subject: [PATCH] fix toSlate parser to handle cdata inside mark (for code tag) --- package.json | 2 +- src/data/content/learning/slate/toslate.ts | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 20270142..68fa6b84 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "course-editor", - "version": "0.43.25", + "version": "0.43.26", "description": "Course Authoring Web Application for the Open Learning Initiative", "main": "./src/app.tsx", "author": "Carnegie Mellon University", diff --git a/src/data/content/learning/slate/toslate.ts b/src/data/content/learning/slate/toslate.ts index 2545b86e..a6e5023a 100644 --- a/src/data/content/learning/slate/toslate.ts +++ b/src/data/content/learning/slate/toslate.ts @@ -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 @@ -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(), });