-
Notifications
You must be signed in to change notification settings - Fork 102
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
Return start/end positions on AST nodes #88
Comments
Hey @jamiebuilds ! I follow you on twitter! (also interviewed to join the discord product infra team ~6 months ago but sadly got a really good offer from another place that felt like a slightly better fit. Sad to miss the opportunity to work with you though!) This has been something I've been interested in for a while (it's always tough to carve out time to work on this, so I've got drafts of thinking about this from quite a while back). There's a bit of a challenge here because the rules don't by default return where inside them their content starts. As far as I'm aware there's not a great API for finding out, from a regular expression, where a capturing group starts in the source string:
(It looks like the We could definitely add the ability to specify the index where the start of the result is outside of the regex, and maybe use some indexOf hacks for matcher functions that don't return that information. My guess is maybe adding another function to a rule, like Of course, doing that in a way that doesn't increase the bundle size a bunch is tricky, but I've been needing to do some optimizations there for a while anyways. tbh I'm not coping super well with COVID and the world right now—i'm managing about enough daily energy to do work and acquire food, and that's... basically it. If you're interested in trying to prototype something for this I'd be happy to help with guidance/code reviews. Otherwise I'll try to prioritize this soon, but probably won't be able to get to it for a while, as it's a pretty significant task. |
Hey @ariabuckles! I've experimented with the some of this. I built a small editor on top of Slate that uses some of the same code structures as in simple-markdown. In that editor, I apply all the styles as column start-end I ended up using the same sort of export let underlineRule: Rule = {
kind: "underline",
match: /^__((?:\\[\s\S]|[^\\])+?)__(?!_)/,
parse: (match, parse) => {
parse(match[1], 2) // 2nd param is "offset"
},
} You can see the code here: https://gist.github.com/jamiebuilds/b653a755b17d5e39ae5f545e251bf08f In that code, I also found some ways to rely on recursion to reduce the amount of code needed (going back to the Also, if you do ever want to revisit Discord, we can totally do that. It's been a fantastic place to work for me, and I'm happy to help get you started with that if you'd ever like to. Please take care of yourself, open source can wait. |
It would be really nice if AST nodes had start/end positions for every node:
Right now it's impossible to reconstruct this data from just the AST.
The text was updated successfully, but these errors were encountered: