20 lines
756 B
JavaScript
20 lines
756 B
JavaScript
import assert from 'node:assert/strict'
|
|
import test from 'node:test'
|
|
|
|
import { normalizeRichTextImages } from '../src/utils/richText.mjs'
|
|
|
|
test('富文本图片移除固定尺寸并添加响应式内联样式', () => {
|
|
const html = '<p>正文</p><img src="/a.png" width="800" height="1200" style="width:800px;height:1200px;border-radius:8px;">'
|
|
const result = normalizeRichTextImages(html)
|
|
|
|
assert.doesNotMatch(result, /width="800"|height="1200"|width:800px|height:1200px/)
|
|
assert.match(result, /width:100%;max-width:100%;height:auto;box-sizing:border-box;/)
|
|
assert.match(result, /border-radius:8px;/)
|
|
})
|
|
|
|
test('非图片富文本保持不变', () => {
|
|
const html = '<p>普通正文</p>'
|
|
|
|
assert.equal(normalizeRichTextImages(html), html)
|
|
})
|