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 inconsistent rendering of block mathematical expressions #29677

Merged
merged 3 commits into from
Mar 11, 2024

Conversation

yp05327
Copy link
Contributor

@yp05327 yp05327 commented Mar 8, 2024

Fix #28735

GitHub render \```math\``` as a block now.
Add display class will render it as a block.

After:
image
image

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 8, 2024
@pull-request-size pull-request-size bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Mar 8, 2024
@silverwind
Copy link
Member

silverwind commented Mar 8, 2024

Where is this display class from? I would recommend using tailwind, e.g. tw-block for display: block, ref.

@yp05327
Copy link
Contributor Author

yp05327 commented Mar 8, 2024

const displayMode = el.classList.contains('display');
const nodeName = displayMode ? 'p' : 'span';
try {
const tempEl = document.createElement(nodeName);
katex.render(source, tempEl, {
maxSize: MAX_SIZE,
maxExpand: MAX_EXPAND,
displayMode,
});
target.replaceWith(tempEl);
} catch (error) {
displayError(target, error);
}
}

It is used for select the display mode in js. It doesn't look like a class for css.

@silverwind
Copy link
Member

silverwind commented Mar 8, 2024

Ah I see, the JS is then turning it into katex-display in the output which does the block rendering.

I also tested this with inline math and can confirm it does not regress them.

image

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Mar 8, 2024
@silverwind silverwind added type/bug backport/v1.21 This PR should be backported to Gitea 1.21 labels Mar 8, 2024
@silverwind
Copy link
Member

silverwind commented Mar 8, 2024

Refactor for the future: Turn display class into data-is-display="true" for clarity.

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 11, 2024
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 11, 2024
@lunny lunny enabled auto-merge (squash) March 11, 2024 04:33
@lunny lunny merged commit 8fc1a8f into go-gitea:main Mar 11, 2024
26 checks passed
@GiteaBot GiteaBot added this to the 1.23.0 milestone Mar 11, 2024
GiteaBot pushed a commit to GiteaBot/gitea that referenced this pull request Mar 11, 2024
@GiteaBot GiteaBot added backport/done All backports for this PR have been created and removed reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. labels Mar 11, 2024
silverwind pushed a commit that referenced this pull request Mar 11, 2024
…#29711)

Backport #29677 by @yp05327

Fix #28735

GitHub render `\```math\``` ` as a block now.
Add `display` class will render it as a block.

After:

![image](https://github.com/go-gitea/gitea/assets/18380374/2a1c20c7-438e-4ab1-8c66-cf91c8343087)

![image](https://github.com/go-gitea/gitea/assets/18380374/b81b8a93-8bca-46a5-b7db-e0d2f53e1342)

Co-authored-by: yp05327 <576951401@qq.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
zjjhot added a commit to zjjhot/gitea that referenced this pull request Mar 12, 2024
* giteaofficial/main:
  Some performance optimization on dashboard and issues page (go-gitea#29010)
  Remove jQuery AJAX from the issue branch reference selection (go-gitea#29722)
  Lazy load object format with command line and don't do it in OpenRepository (go-gitea#29712)
  remove repetitive words (go-gitea#29695)
  Sync branches first (go-gitea#29714)
  Add a warning for disallowed email domains (go-gitea#29658)
  Fix inconsistent rendering of block mathematical expressions (go-gitea#29677)
@lunny lunny modified the milestones: 1.23.0, 1.22.0 Mar 13, 2024
@yp05327 yp05327 deleted the fix-markup-math branch March 26, 2024 00:03
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Jun 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/done All backports for this PR have been created backport/v1.21 This PR should be backported to Gitea 1.21 lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent rendering of block mathematical expressions
5 participants