Skip to content

Commit b517d30

Browse files
authored
Merge pull request #26 from sillsdev/EscapeHtml
fix: #21 Escape html (e.g. < becomes &lt;)
2 parents 6221ae9 + 9e78a00 commit b517d30

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/pull.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,13 @@ async function outputPage(page: NotionPage) {
234234
)
235235
);
236236

237-
// One half of a horrible hack to make heading links work.
238-
// See the other half and explanation in HeadingTransformer.ts.
239237
for (const block_t of blocks) {
240238
const block = block_t as any;
239+
240+
escapeHtml(block);
241+
242+
// One half of a horrible hack to make heading links work.
243+
// See the other half and explanation in CustomTransformers.ts => headingCustomTransformer.
241244
if (block.type.startsWith("heading"))
242245
block.type = block.type.replace("heading", "my_heading");
243246
}
@@ -269,3 +272,25 @@ async function outputPage(page: NotionPage) {
269272

270273
++counts.output_normally;
271274
}
275+
276+
function escapeHtml(block: any): void {
277+
const blockContent = block[block.type];
278+
279+
if (blockContent.rich_text?.length) {
280+
for (let i = 0; i < blockContent.rich_text.length; i++) {
281+
const rt = blockContent.rich_text[i];
282+
283+
// See https://github.com/sillsdev/docu-notion/issues/21.
284+
if (
285+
rt?.plain_text &&
286+
block.type !== "code" &&
287+
rt.type !== "code" &&
288+
!rt.annotations?.code
289+
) {
290+
rt.plain_text = rt.plain_text
291+
.replaceAll("<", "&lt;")
292+
.replaceAll(">", "&gt;");
293+
}
294+
}
295+
}
296+
}

0 commit comments

Comments
 (0)