mirror of https://github.com/go-gitea/gitea.git
Fix markdown render behaviors (#34122)
* Fix #27645 * Add config options `MATH_CODE_BLOCK_DETECTION`, problematic syntaxes are disabled by default * Fix #33639 * Add config options `RENDER_OPTIONS_*`, old behaviors are keptpull/34126/head
parent
ee6929d96b
commit
e1c2d05bde
@ -0,0 +1,51 @@
|
|||||||
|
// Copyright 2025 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package setting
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestLoadMarkup(t *testing.T) {
|
||||||
|
cfg, _ := NewConfigProviderFromData(``)
|
||||||
|
loadMarkupFrom(cfg)
|
||||||
|
assert.Equal(t, MarkdownMathCodeBlockOptions{ParseInlineDollar: true, ParseBlockDollar: true}, Markdown.MathCodeBlockOptions)
|
||||||
|
assert.Equal(t, MarkdownRenderOptions{NewLineHardBreak: true, ShortIssuePattern: true}, Markdown.RenderOptionsComment)
|
||||||
|
assert.Equal(t, MarkdownRenderOptions{ShortIssuePattern: true}, Markdown.RenderOptionsWiki)
|
||||||
|
assert.Equal(t, MarkdownRenderOptions{}, Markdown.RenderOptionsRepoFile)
|
||||||
|
|
||||||
|
t.Run("Math", func(t *testing.T) {
|
||||||
|
cfg, _ = NewConfigProviderFromData(`
|
||||||
|
[markdown]
|
||||||
|
MATH_CODE_BLOCK_DETECTION = none
|
||||||
|
`)
|
||||||
|
loadMarkupFrom(cfg)
|
||||||
|
assert.Equal(t, MarkdownMathCodeBlockOptions{}, Markdown.MathCodeBlockOptions)
|
||||||
|
|
||||||
|
cfg, _ = NewConfigProviderFromData(`
|
||||||
|
[markdown]
|
||||||
|
MATH_CODE_BLOCK_DETECTION = inline-dollar, inline-parentheses, block-dollar, block-square-brackets
|
||||||
|
`)
|
||||||
|
loadMarkupFrom(cfg)
|
||||||
|
assert.Equal(t, MarkdownMathCodeBlockOptions{ParseInlineDollar: true, ParseInlineParentheses: true, ParseBlockDollar: true, ParseBlockSquareBrackets: true}, Markdown.MathCodeBlockOptions)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Render", func(t *testing.T) {
|
||||||
|
cfg, _ = NewConfigProviderFromData(`
|
||||||
|
[markdown]
|
||||||
|
RENDER_OPTIONS_COMMENT = none
|
||||||
|
`)
|
||||||
|
loadMarkupFrom(cfg)
|
||||||
|
assert.Equal(t, MarkdownRenderOptions{}, Markdown.RenderOptionsComment)
|
||||||
|
|
||||||
|
cfg, _ = NewConfigProviderFromData(`
|
||||||
|
[markdown]
|
||||||
|
RENDER_OPTIONS_REPO_FILE = short-issue-pattern, new-line-hard-break
|
||||||
|
`)
|
||||||
|
loadMarkupFrom(cfg)
|
||||||
|
assert.Equal(t, MarkdownRenderOptions{NewLineHardBreak: true, ShortIssuePattern: true}, Markdown.RenderOptionsRepoFile)
|
||||||
|
})
|
||||||
|
}
|
||||||
@ -1,16 +1,17 @@
|
|||||||
export async function initMarkupRenderAsciicast(elMarkup: HTMLElement): Promise<void> {
|
import {queryElems} from '../utils/dom.ts';
|
||||||
const el = elMarkup.querySelector('.asciinema-player-container');
|
|
||||||
if (!el) return;
|
|
||||||
|
|
||||||
const [player] = await Promise.all([
|
export async function initMarkupRenderAsciicast(elMarkup: HTMLElement): Promise<void> {
|
||||||
// @ts-expect-error: module exports no types
|
queryElems(elMarkup, '.asciinema-player-container', async (el) => {
|
||||||
import(/* webpackChunkName: "asciinema-player" */'asciinema-player'),
|
const [player] = await Promise.all([
|
||||||
import(/* webpackChunkName: "asciinema-player" */'asciinema-player/dist/bundle/asciinema-player.css'),
|
// @ts-expect-error: module exports no types
|
||||||
]);
|
import(/* webpackChunkName: "asciinema-player" */'asciinema-player'),
|
||||||
|
import(/* webpackChunkName: "asciinema-player" */'asciinema-player/dist/bundle/asciinema-player.css'),
|
||||||
|
]);
|
||||||
|
|
||||||
player.create(el.getAttribute('data-asciinema-player-src'), el, {
|
player.create(el.getAttribute('data-asciinema-player-src'), el, {
|
||||||
// poster (a preview frame) to display until the playback is started.
|
// poster (a preview frame) to display until the playback is started.
|
||||||
// Set it to 1 hour (also means the end if the video is shorter) to make the preview frame show more.
|
// Set it to 1 hour (also means the end if the video is shorter) to make the preview frame show more.
|
||||||
poster: 'npt:1:0:0',
|
poster: 'npt:1:0:0',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue