mobiledoc-kit icon indicating copy to clipboard operation
mobiledoc-kit copied to clipboard

Future consideration: make all node types unique

Open joshfrench opened this issue 9 years ago • 3 comments

I'm tinkering on a mobiledoc-to-react renderer that takes an alternate approach. It starts by mapping the sections/markers to an actual tree structure. For example:

[MARKUP_SECTION_TYPE, 'p', {}, [
  [MARKUP_MARKER_TYPE, 'a', {href: "#"}, [
    "link text"
  ]]
]]

From there it's easy to project that into a tree of React components. But that tree structure could just as easily be mapped to other formats: HTML, XML/RSS, AMP, &c. At that point, adding a new render target only requires walking the tree with a new transform function -- you don't need to reinvent the bulk of the renderer.

To help identify each node as it's walked, it would be easier if each node type had a unique identifier instead of giving both section types and marker types overlapping IDs. Currently MARKUP_SECTION_TYPE = ATOM_MARKER_TYPE = 1 which means you need to look at surrounding context to unambiguously identify a node.

I realize this would involve releasing a new version of the Mobiledoc format, so I'll just leave it here for future consideration :)

joshfrench avatar Aug 30 '16 18:08 joshfrench

@joshfrench This is very cool! Thanks for the suggestion — makes sense to me (for the next mobiledoc format version). I'm going to make a roll-up issue that captures ideas for changes to the mobiledoc format and link this to it.

bantic avatar Aug 31 '16 15:08 bantic

I'm mostly hesitant to do this because we already plan what may be sweeping changes to the format in the 2.0 timeline to support collaborate editing. Updating the format itself causes some churn in the ecosystem and we're incentivized to keep that minimal.

mixonic avatar Nov 07 '16 19:11 mixonic

:+1: This isn't a blocker currently

joshfrench avatar Nov 07 '16 20:11 joshfrench