Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: flatten childToken arrays #3172

Merged
merged 1 commit into from
Jan 27, 2024
Merged

feat: flatten childToken arrays #3172

merged 1 commit into from
Jan 27, 2024

Conversation

UziTech
Copy link
Member

@UziTech UziTech commented Jan 20, 2024

Marked version: 11.1.1

Description

Flatten custom extension childToken arrays before running them through walk tokens. This will allow custom extensions to have child tokens like the table token where the rows field is an array of arrays of tokens.

Contributor

  • Test(s) exist to ensure functionality and minimize regression (if no tests added, list tests covering this PR); or,
  • no tests required for this PR.
  • If submitting new feature, it has been documented in the appropriate places.

Committer

In most cases, this should be a different person than the contributor.

Copy link

vercel bot commented Jan 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
marked-website ✅ Ready (Inspect) Visit Preview Jan 20, 2024 8:02pm

@UziTech
Copy link
Member Author

UziTech commented Jan 20, 2024

@calculuschild this should work to walk arrays of arrays of tokens.

One question: Should we flatten with infinite depth? or should we only flatten 1 or 2 levels deep?

The only issue I found with doing Infinite depth is there can be a stack overflow if there is a circular dependency. I don't think that is a big issue but something to think about.

a = [1]
b = [2]
a.push(b)
b.push(a)
a.flat(Infinity) 

Copy link
Contributor

@calculuschild calculuschild left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think infinite depth shouldn't be a problem. If people are designing extensions in such a way to cause a cyclic dependency, that's a fault of the extension, not Marked, right?

@UziTech
Copy link
Member Author

UziTech commented Jan 21, 2024

I agree. This shouldn't affect core marked at all. Only extensions

Copy link
Member

@styfle styfle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could also use a large-ish depth instead of Infinity, perhaps 1000, and still cover most use cases.

But I agree, its only for self-referencing extensions which is probably a small minority.

@UziTech UziTech merged commit 4826841 into master Jan 27, 2024
8 checks passed
@UziTech UziTech deleted the flatten-walkTokens branch January 27, 2024 00:26
github-actions bot pushed a commit that referenced this pull request Jan 27, 2024
# [11.2.0](v11.1.1...v11.2.0) (2024-01-27)

### Bug Fixes

* Fix ENOENT error message in CLI ([#3165](#3165)) ([bf44ae8](bf44ae8))

### Features

* flatten childToken arrays ([#3172](#3172)) ([4826841](4826841))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Register Walktokens Behavior for extensions with different token structure
5 participants