| 1234567891011121314151617181920 |
- /** 协议/富文本文章 u-parse 标签样式 */
- export const ARTICLE_TAG_STYLE = {
- p: 'margin:0 0 20rpx;line-height:1.8;font-size:28rpx;color:#333;',
- img: 'max-width:100%;height:auto;display:block;',
- table: 'border-collapse:collapse;min-width:100%;font-size:24rpx;',
- th: 'border:1px solid #e5e5e5;padding:16rpx 20rpx;background:#f7f7f7;white-space:nowrap;font-size:24rpx;',
- td: 'border:1px solid #e5e5e5;padding:16rpx 20rpx;white-space:nowrap;font-size:24rpx;',
- }
- /** 预处理 CMS 富文本:图片自适应、宽表格横向滚动 */
- export function formatArticleHtml(html) {
- if (!html || typeof html !== 'string') return ''
- let result = html.replace(/<img\b/gi, '<img style="max-width:100%;height:auto;display:block;"')
- result = result.replace(
- /<table\b/gi,
- '<div class="article-table-scroll" style="width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;"><table'
- )
- result = result.replace(/<\/table>/gi, '</table></div>')
- return result
- }
|