question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Modify Text interface to be compatible with "universal syntax tree" (unist)

See original GitHub issue

Problem The unified ecosystem provides a vast amount of utility functions for tree traversal, transformation and validation. It also supports easy parsing of html and markdown out of the box. We (and I can image others too) would love to leverage those tools in combination with slate. However both trees are not compatible: Slate expects leaf nodes of the following shape:

interface Text {
   text: string
}

while leaf (literal) nodes defined in unist have the following shape:

interface Literal {
   type: "text",
   value: string
}

Solution As you can see the only incompatibility is the name of the value key text vs value (And just renaming that across slate does the trick)

Context In my fork I have a version of slate that is fully compatible with unist-style trees. I was just wondering if support for this is something you’re interested in and if I should therefore put the work into a PR. It would most definitely result in a breaking change so I can understand if you don’t.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:7
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
dylanscommented, Aug 12, 2021

I personally am a fan of this change (not sure how others on the core slate team feel), though it’s a breaking change and it would have significant impact on users that persist slate documents.

I can see a couple of paths towards getting this to work, assuming this is a change that the Slate team wants to support:

  • Make the key configurable (with a default of text, and some future plan to change that default to value)
  • Support text or value as the key and have the code base treat them interchangeably
  • Change from text to value and introduce a breaking change at some point in the future (maybe 1.0)
2reactions
dylanscommented, Apr 8, 2022

I think if we followed my proposed approach we could make it work, along with your note. Interested in raising a PR?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Text Processing with Unified / Benjamin - Observable
unified is an interface for processing text using syntax trees. It's what powers remark, retext, and rehype, and allows for processing ...
Read more >
TxtAST Interface - textlint
Unist. TxtAST have a minimum of compatibility for unist: Universal Syntax Tree. We discuss about Unist in Compliances tests for TxtNode #141.
Read more >
Syntax trees in TypeScript - unified
All unified syntax trees are based off unist (universal syntax tree). The core types are available in a types only package: @types/unist ....
Read more >
SyntaxTree Class (Microsoft.CodeAnalysis)
The options used by the parser to produce the syntax tree. ... If the new source text is a minor change from the...
Read more >
Simplified abstract syntax tree based semantic features ...
Abstract Software change prediction aims to identify the change-prone parts of source code, which can help software practitioners allocate ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found