deploy: auto commit repo-root changes 2026-07-05 11:43:29
This commit is contained in:
@@ -40,7 +40,8 @@
|
||||
<div class="nd-content__inner" v-html="block.html"></div>
|
||||
<!-- #endif -->
|
||||
<!-- #ifndef H5 -->
|
||||
<rich-text :nodes="block.html" />
|
||||
<u-parse class="nd-content__parser" :html="block.html" :tag-style="richTextTagStyle"
|
||||
:selectable="true" />
|
||||
<!-- #endif -->
|
||||
<text v-if="block.translated" class="nd-content__translate">{{ block.translated }}</text>
|
||||
</view>
|
||||
@@ -268,12 +269,36 @@ const translatedTitle = computed(() => translatedParts.value.title)
|
||||
const translatedAbstract = computed(() => translatedParts.value.abstract)
|
||||
const translatedBodyLines = computed(() => translatedParts.value.body)
|
||||
|
||||
const richTextTagStyle = {
|
||||
p: 'margin:0;line-height:1.52;font-size:22rpx;color:#333;word-break:break-word;',
|
||||
div: 'margin:0;line-height:1.52;font-size:22rpx;color:#333;word-break:break-word;',
|
||||
li: 'margin:0;line-height:1.52;font-size:22rpx;color:#333;word-break:break-word;',
|
||||
h1: 'margin:8rpx 0;font-size:34rpx;font-weight:700;line-height:1.35;color:#1f2937;',
|
||||
h2: 'margin:8rpx 0;font-size:30rpx;font-weight:700;line-height:1.38;color:#1f2937;',
|
||||
h3: 'margin:8rpx 0;font-size:28rpx;font-weight:700;line-height:1.4;color:#1f2937;',
|
||||
blockquote: 'margin:8rpx 0;padding:8rpx 16rpx;border-left:6rpx solid #d6def2;background:#f7f9fc;color:#4b5563;',
|
||||
img: 'max-width:100%;height:auto;display:block;margin:10px 0;',
|
||||
}
|
||||
|
||||
const normalizeImageAttrs = (attrs: string) => {
|
||||
let normalized = String(attrs || '').replace(/\/\s*$/, '').trim()
|
||||
if (!/\breferrerpolicy\s*=/i.test(normalized)) {
|
||||
normalized = `${normalized} referrerpolicy="no-referrer"`.trim()
|
||||
}
|
||||
|
||||
const imageStyle = 'max-width:100%;height:auto;display:block;margin:10px 0;'
|
||||
const styleMatch = normalized.match(/(^|\s)style=(["'])(.*?)\2/i)
|
||||
if (styleMatch) {
|
||||
const mergedStyle = `${styleMatch[3].replace(/;?\s*$/, ';')}${imageStyle}`
|
||||
return normalized.replace(styleMatch[0], `${styleMatch[1]}style=${styleMatch[2]}${mergedStyle}${styleMatch[2]}`)
|
||||
}
|
||||
|
||||
return `${normalized} style="${imageStyle}"`.trim()
|
||||
}
|
||||
|
||||
const normalizeHtml = (html: string) => {
|
||||
if (!html) return ''
|
||||
return String(html).replace(
|
||||
/<img\s+([^>]*)>/gi,
|
||||
'<img $1 referrerpolicy="no-referrer" style="max-width:100%;height:auto;display:block;margin:10px 0;">'
|
||||
)
|
||||
return String(html).replace(/<img\b([^>]*)>/gi, (_match, attrs = '') => `<img ${normalizeImageAttrs(attrs)}>`)
|
||||
}
|
||||
|
||||
const stripHtmlText = (html: string) => {
|
||||
|
||||
Reference in New Issue
Block a user