格式化

This commit is contained in:
2025-07-17 15:22:56 +08:00
parent e2f5afb805
commit efe649df60

View File

@@ -22,18 +22,18 @@
<div class="headtop"> <div class="headtop">
{eq name=":cookie('think_lang')" value="zh-cn"} {eq name=":cookie('think_lang')" value="zh-cn"}
<a href="{:url('/index/topic/nas/index')}"> <a href="{:url('/index/topic/nas/index')}">
{else/} {else/}
<a> <a>
{/eq} {/eq}
<img src="__IMAGES__/logo.png" class="logoicoimg"> <img src="__IMAGES__/logo.png" class="logoicoimg">
</a> </a>
<div style="display: flex;"> <div style="display: flex;">
<img src="__IMAGES__/fenlei.png" class="ssicoimg" id="flico"> <img src="__IMAGES__/fenlei.png" class="ssicoimg" id="flico">
<img src="__IMAGES__/sousuo.png" class="ssicoimg" id="ssico" style="margin-right:32px"> <img src="__IMAGES__/sousuo.png" class="ssicoimg" id="ssico" style="margin-right:32px">
</div> </div>
</div> </div>
<!-- 文章内容 --> <!-- 文章内容 -->
<div class="ql-container"> <div class="ql-container">
<div id="rendered-content" class="nhlp-app-content ql-editor"> <div id="rendered-content" class="nhlp-app-content ql-editor">
{$article.content|raw|default=''} {$article.content|raw|default=''}
</div> </div>
@@ -42,7 +42,8 @@
<div class="nhlpapp-search"> <div class="nhlpapp-search">
<div class="nhlpappshtop"> <div class="nhlpappshtop">
<div class="nhlpapp-shdiv"> <div class="nhlpapp-shdiv">
<input class="nhlp-ipt" id="search-input" placeholder="{:lang_i18n('请输入搜索关键字,如安装赛博云空间,影视库')}" autocomplete="off"> <input class="nhlp-ipt" id="search-input" placeholder="{:lang_i18n('请输入搜索关键字,如安装赛博云空间,影视库')}"
autocomplete="off">
<img src="__IMAGES__/ssapp.png" class="searchimg"> <img src="__IMAGES__/ssapp.png" class="searchimg">
</div> </div>
<span class="closetx">{:lang_i18n('取消')}</span> <span class="closetx">{:lang_i18n('取消')}</span>
@@ -52,7 +53,7 @@
<div class="dropdown" id="dropdown"></div> <div class="dropdown" id="dropdown"></div>
</div> </div>
<!-- 分类文章目录 --> <!-- 分类文章目录 -->
<div class="nhlpapp-pagescate" {:style(['display' => $Request.get.view == 'more' ? 'block' : 'none'])}> <div class="nhlpapp-pagescate" {:style(['display'=> $Request.get.view == 'more' ? 'block' : 'none'])}>
<div class="nars-hlpdt-ml"> <div class="nars-hlpdt-ml">
{notempty name="article_categorys"} {notempty name="article_categorys"}
<div class="nav-tree"> <div class="nav-tree">
@@ -60,14 +61,16 @@
<div class="categoryhelp"> <div class="categoryhelp">
<div class="categoryhelp-title"> <div class="categoryhelp-title">
<div> <div>
<img src="__IMAGES__/nars-jt.png" class="arrow {if condition='$ac.id == $Request.get.cid'}rotate{/if}"> <img src="__IMAGES__/nars-jt.png"
class="arrow {if condition='$ac.id == $Request.get.cid'}rotate{/if}">
</div> </div>
<span>{$ac.name}</span> <span>{$ac.name}</span>
</div> </div>
<ul class="sub-list" {if condition='$ac.id == $Request.get.cid'}style="display: block;"{/if}> <ul class="sub-list" {if condition='$ac.id == $Request.get.cid' }style="display: block;" {/if}>
{volist name="ac.article" id="ar"} {volist name="ac.article" id="ar"}
<li> <li>
<a href="{:url('/index/topic/nas/help_detail', ['cid' => $ac.id , 'id' => $ar.id])}" style="padding-top: 6px;"> <a href="{:url('/index/topic/nas/help_detail', ['cid' => $ac.id , 'id' => $ar.id])}"
style="padding-top: 6px;">
{$ar.title} {$ar.title}
</a> </a>
</li> </li>
@@ -79,7 +82,7 @@
{/notempty} {/notempty}
</div> </div>
</div> </div>
<!-- 顶部国家选择--> <!-- 顶部国家选择-->
<div class="top-country"> <div class="top-country">
<div class="mask"></div> <div class="mask"></div>
<div class="action-sheet"> <div class="action-sheet">
@@ -134,10 +137,10 @@
$('.nhlpapp-search').hide(); $('.nhlpapp-search').hide();
}); });
// 顶部国家选择 // 顶部国家选择
$('.top-country-toggle').click(function(){ $('.top-country-toggle').click(function () {
$(".mask,.action-sheet").show(); $(".mask,.action-sheet").show();
}) })
$('.top-country .close-icon').click(function(){ $('.top-country .close-icon').click(function () {
$(".mask,.action-sheet").hide(); $(".mask,.action-sheet").hide();
}) })
// 搜索 // 搜索
@@ -172,25 +175,22 @@
}) })
}, 300); }, 300);
}); });
// 英文截断 // 英文截断处理
// 处理 #rendered-content 内的内容 $('#rendered-content').html(function (i, html) {
$('#rendered-content').html(function(i, html) {
// 1. 先保护真正的空行(只包含&nbsp;的标签) // 1. 先保护真正的空行(只包含&nbsp;的标签)
html = html.replace(/<(p|h[1-6])>(<strong>)?(&nbsp;| )*(<\/strong>)?<\/\1>/g, function(match) { html = html.replace(/<(p|h[1-6])>(<strong>)?(&nbsp;| )*(<\/strong>)?<\/\1>/g, function (match) {
// 统一空行格式为 <p>&nbsp;</p> 或 <h2>&nbsp;</h2> 形式 // 统一空行格式为 <p>&nbsp;</p> 或 <h2>&nbsp;</h2> 形式
return match.replace(/(<p>|<h[1-6]>)\s*(<strong>)?\s*(&nbsp;| )*\s*(<\/strong>)?\s*(<\/p>|<\/h[1-6]>)/, return match.replace(/(<p>|<h[1-6]>)\s*(<strong>)?\s*(&nbsp;| )*\s*(<\/strong>)?\s*(<\/p>|<\/h[1-6]>)/,
function(m) { function (m) {
var tag = m.match(/<(p|h[1-6])>/)[1]; var tag = m.match(/<(p|h[1-6])>/)[1];
return '<' + tag + '>&nbsp;</' + tag + '>'; return '<' + tag + '>&nbsp;</' + tag + '>';
}); });
}); });
// 2. 替换其他&nbsp;为普通空格(保留单词间的空格) // 2. 替换其他&nbsp;为普通空格(保留单词间的空格)
html = html.replace(/&nbsp;(?=\w)/g, ' '); html = html.replace(/&nbsp;(?=\w)/g, ' ');
return html; return html;
}); });
// 添加CSS样式确保英文单词完整换行 // 添加CSS样式确保英文单词完整换行
$('#rendered-content').css({ $('#rendered-content').css({
'word-wrap': 'break-word', 'word-wrap': 'break-word',
@@ -198,17 +198,17 @@
'word-break': 'normal', 'word-break': 'normal',
'white-space': 'normal' 'white-space': 'normal'
}); });
// 优化英文单词间的空格处理 // 优化英文单词间的空格处理
$('#rendered-content').find('p, h1, h2, h3, h4, h5, h6').each(function() { $('#rendered-content').find('p, h1, h2, h3, h4, h5, h6').each(function () {
var $el = $(this); var $el = $(this);
// 只处理非空行 // 只处理非空行
if ($el.html().trim() !== '&nbsp;') { if ($el.html().trim() !== '&nbsp;') {
var html = $el.html() var html = $el.html()
.replace(/([a-zA-Z])(&nbsp;| )+([a-zA-Z])/g, '$1 $3') // 单词间保留一个空格 .replace(/([a-zA-Z])(&nbsp;| )+([a-zA-Z])/g, '$1 $3') // 单词间保留一个空格
.replace(/(\d)(&nbsp;| )+([a-zA-Z])/g, '$1 $3') // 数字和单词间 .replace(/(\d)(&nbsp;| )+([a-zA-Z])/g, '$1 $3') // 数字和单词间
.replace(/([a-zA-Z])(&nbsp;| )+(\d)/g, '$1 $3'); // 单词和数字间 .replace(/([a-zA-Z])(&nbsp;| )+(\d)/g, '$1 $3'); // 单词和数字间
$el.html(html); $el.html(html);
} }
}); });
}); });