Skip to content
This repository has been archived by the owner on Feb 21, 2019. It is now read-only.

Multi line comment not working. #4

Closed
vidoss opened this issue Jun 9, 2017 · 3 comments
Closed

Multi line comment not working. #4

vidoss opened this issue Jun 9, 2017 · 3 comments
Labels

Comments

@vidoss
Copy link

vidoss commented Jun 9, 2017

Since the decorator gets one text node at a time, multi-line comments with /* */ are not color coded as comments. Not sure how this can be fixed. Maybe marks should be applied as transform() onChange instead of plugin decorator. Any thoughts ?

@Soreine Soreine added the bug label Jun 9, 2017
@Soreine
Copy link
Contributor

Soreine commented Jun 9, 2017

This problem does not exists if your code nodes contain a single text node, with newlines character inside.

However, that generally leads to poor performance when writing inside large code chunks. That's why in slate-edit-code we took the approach to split code in multiple line nodes. The problem with that approach is that Prism is not fed the whole text.

Maybe slate-prism could ask which code block each code line belongs to. The plugin would manage a dictionary of code blocks, code lines, and their texts, so that when it has to decorate a specific line, it has all the necessary context. I think the main performance bottleneck is not Prism itself, but the DOM operations of marks, so this could still be fast.

I don't know what would yield the use of marks. Maybe @SamyPesse had thought about it. I see one big downside though, that it affects the document data. slate-prism should ideally just have rendering implications.

Edit: My bad. There's no concept of decorators in Slate. We use marks. I removed the irrelevant parts.

@ianstormtaylor
Copy link

ianstormtaylor commented Oct 11, 2017

@Soreine I think slate-prism could take an optional argument like blockPerLine: true, and then the match function of the decorator rule could match the container, and pass the block.text of the container to Prism, which would include all of the code lines.

Then when applying the tokens to the, use text.characters still. And to keep performance, just retain a reference to the previous block.text and tokens, and if the text matches, just re-use the tokens, so you don't have to parse again for each line.

@Soreine
Copy link
Contributor

Soreine commented Oct 14, 2017

Fixed by #5

@Soreine Soreine closed this as completed Oct 14, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants