-
Notifications
You must be signed in to change notification settings - Fork 72
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
🧮 Fix math-spacing in paragraphs #1032
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.
Looking ok - only a couple suggestions to tidy things up. Most of my comments just trying to get a full understanding of what's going on.
@@ -8,6 +8,20 @@ import { stateError, stateWarn } from './utils.js'; | |||
|
|||
const COLON_OPTION_REGEX = /^:(?<option>[^:\s]+?):(\s*(?<value>.*)){0,1}\s*$/; | |||
|
|||
function computeBlockTightness( | |||
src: string, | |||
map: [number, number] | null | undefined, |
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.
Requires correct mapping back to original source.
Ah, and this is added on all directives. But only used by math for now.
@@ -51,6 +65,7 @@ function runDirectives(state: StateCore): boolean { | |||
directiveOpen.meta = { | |||
arg, | |||
options: simplifyDirectiveOptions(options), | |||
tight: computeBlockTightness(state.src, token.map), |
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.
It feels slightly extreme to be passing the entire source content around to compute this... it seems like it could be possible to do this by inspecting the previous/next tokens in state.tokens
to look for blank lines? But that would probably require some dicey token stream logic... easier for now to just do things explicitly based on the content.
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.
Yeah, I think that there are certainly better ways to do this. I will spend a bit of time on that now that we have tests...!
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 that we could look this up if we took over the block-level parsing. But currently we are not doing that for fences (```
), only colon-fences (:::
). That means that the previous token is a paragraph_close
and there is no indication of blank lines (and it also doesn't have a map on it so we can't look to that to compare the line numbers).
I think that the current way of doing it is probably ok, I am going to cache the splitting of lines, which is the most time intensive part (I think).
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.
Ok - I take it back, that is being shared in unexpected ways for the caching. Reverting the caching changes.
5a2bceb
to
92bae38
Compare
See #787