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

🧮 Fix math-spacing in paragraphs #1032

Merged
merged 4 commits into from
Mar 26, 2024
Merged

🧮 Fix math-spacing in paragraphs #1032

merged 4 commits into from
Mar 26, 2024

Conversation

rowanc1
Copy link
Member

@rowanc1 rowanc1 commented Mar 25, 2024

See #787

@rowanc1 rowanc1 requested a review from fwkoch March 25, 2024 21:34
Copy link
Collaborator

@fwkoch fwkoch left a 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,
Copy link
Collaborator

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.

packages/myst-directives/src/math.ts Outdated Show resolved Hide resolved
packages/myst-parser/src/fromMarkdown.ts Show resolved Hide resolved
packages/myst-parser/src/tokensToMyst.ts Show resolved Hide resolved
packages/myst-transforms/src/math.ts Show resolved Hide resolved
@@ -51,6 +65,7 @@ function runDirectives(state: StateCore): boolean {
directiveOpen.meta = {
arg,
options: simplifyDirectiveOptions(options),
tight: computeBlockTightness(state.src, token.map),
Copy link
Collaborator

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.

Copy link
Member Author

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...!

Copy link
Member Author

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).

Copy link
Member Author

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.

@rowanc1 rowanc1 force-pushed the feat/math-spacing branch from 5a2bceb to 92bae38 Compare March 26, 2024 17:28
@rowanc1 rowanc1 merged commit 2010854 into main Mar 26, 2024
4 checks passed
@rowanc1 rowanc1 deleted the feat/math-spacing branch March 26, 2024 17:34
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.

2 participants