From 824e66a62f7d899201e9e8edf3cc8cd683c5be9d Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Fri, 2 Jul 2021 00:23:59 -0700 Subject: [PATCH] Add some comments. --- src/platform/web/dom/deserialize.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/platform/web/dom/deserialize.js b/src/platform/web/dom/deserialize.js index a848cb16..41acf792 100644 --- a/src/platform/web/dom/deserialize.js +++ b/src/platform/web/dom/deserialize.js @@ -7,12 +7,22 @@ import { HeaderBlock, ListBlock, CodeBlock, FormatPart, NewLinePart, RulePart, T * strong, em, strike, code, hr, br, div, table, thead, tbody, tr, th, td, caption, pre, span, img */ +/** + * Nodes that don't have any properties to them other than their tag. + * While has `href`, and has `src`, these have... themselves. + */ const basicNodes = ["EM", "STRONG", "CODE", "DEL", "P", "DIV", "SPAN" ] +/** + * Return a builder function for a particular tag. + */ function basicWrapper(tag) { return (_, children) => new FormatPart(tag, children); } +/** + * Return a builder function for a particular header level. + */ function headerWrapper(level) { return (_, children) => new HeaderBlock(level, children); } @@ -74,6 +84,18 @@ function buildNodeMap() { return map; } +/** + * Handlers for various nodes. + * + * Each handler has two properties: `descend` and `parsefn`. + * If `descend` is true, the node's children should be + * parsed just like any other node, and fed as a second argument + * to `parsefn`. If not, the node's children are either to be ignored + * (as in
) or processed specially (as in 
    ). + * + * The `parsefn` combines a node's data and its children into + * an internal representation node. + */ const nodes = buildNodeMap(); function parseNode(node) { @@ -95,6 +117,7 @@ function parseNodes(nodes) { const parsed = []; for (let i = 0; i < len; i ++) { let node = parseNode(nodes[i]); + // Just ignore invalid / unknown tags. if (node) { parsed.push(node); }