-
Notifications
You must be signed in to change notification settings - Fork 20
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
if (!grammar) { | ||
return text.characters; | ||
} | ||
|
||
const tokens = Prism.tokenize(string, grammar); | ||
let offset = 0; | ||
if (opts.blockPerLine && block === previousBlock) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Caching the last computed tokens is a nice optimization. Improves the first decoration pass.
I'll add it to my PR
@@ -44,53 +44,113 @@ function PrismPlugin(opts) { | |||
opts.onlyIn = opts.onlyIn || defaultOnlyIn; | |||
opts.getSyntax = opts.getSyntax || defaultGetSyntax; | |||
opts.renderToken = opts.renderToken || defaultTokenRender; | |||
opts.blockPerLine = opts.blockPerLine || false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking to make it the default behavior (and not have an option for it)
|
||
const gap = Math.max(start - offset, 0) | ||
let s = offset - start + gap; | ||
let e = nextOffset - start + gap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's a bug here when nextOffset > end
Testing with this text:
<!-- Some
HTML -->
We have a call addMark(0, 18, 'comment')
on the first text line, that fails because the comment mark extends beyond the end of the text.
I'm glad that you took a look at it. I haven't worked on it since then. I think the only blocker is ianstormtaylor/slate#893 |
Closed in favor of #5 |
Hey @Soreine this solves #4.
It's a bit convoluted, but I tried to leave as much existing code in place as possible, while keeping the new logic not too crazy to understand.
Basically if
options.blockPerLine
, then theblock
passed into the decorator is assumed to be the outer-most block. And it tokenizes that outer-most block's text, and then applies the marks to the individual leaf text nodes.