当前位置: 首页 > news >正文

mardown-it 有序列表ios序号溢出解决办法

const md = new MarkdownIt({ html: true })if (Tools.browserEnv().isIOS()) {// 先保存默认规则,避免覆盖掉 ul 的逻辑const defaultOrderedListOpen = md.renderer.rules.ordered_list_open || function (tokens, idx, options, env, self) {return self.renderToken(tokens, idx, options);};const defaultOrderedListClose = md.renderer.rules.ordered_list_close || function (tokens, idx, options, env, self) {return self.renderToken(tokens, idx, options);};const defaultListItemOpen = md.renderer.rules.list_item_open || function (tokens, idx, options, env, self) {return self.renderToken(tokens, idx, options);};const defaultListItemClose = md.renderer.rules.list_item_close || function (tokens, idx, options, env, self) {return self.renderToken(tokens, idx, options);};// 只改 <ol>md.renderer.rules.ordered_list_open = function (tokens, idx, options, env, self) {const token = tokens[idx];if (token.type !== 'ordered_list_open') {return defaultOrderedListOpen(tokens, idx, options, env, self);}return '<div class="markdown-list">\n';};md.renderer.rules.ordered_list_close = function (tokens, idx, options, env, self) {const token = tokens[idx];if (token.type !== 'ordered_list_close') {return defaultOrderedListClose(tokens, idx, options, env, self);}return '</div>\n';};// 只改 <ol> 下的 <li>md.renderer.rules.list_item_open = function (tokens, idx, options, env, self) {const token = tokens[idx];// 向上找父级let parent;for (let i = idx - 1; i >= 0; i--) {if (tokens[i].type.endsWith('_open') && tokens[i].level === token.level - 1) {parent = tokens[i];break;}}// 不是 ol → 默认渲染if (!parent || parent.type !== 'ordered_list_open') {return defaultListItemOpen(tokens, idx, options, env, self);}// --- 处理 ol ---let order = 1;if (parent.attrGet('start')) {order = parseInt(parent.attrGet('start'));}// 计算 li 的序号let liIndex = 0;for (let i = idx; i >= 0; i--) {if (tokens[i].type === 'list_item_open' && tokens[i].level === token.level) {liIndex++;} else if (tokens[i].type === 'ordered_list_open' && tokens[i].level < token.level) {break;}}return `<div class="markdown-list-item"><span class="number">${order + liIndex - 1}.</span><span class="text">`;};md.renderer.rules.list_item_close = function (tokens, idx, options, env, self) {const token = tokens[idx];// 向上找父级let parent;for (let i = idx - 1; i >= 0; i--) {if (tokens[i].type.endsWith('_open') && tokens[i].level === token.level - 1) {parent = tokens[i];break;}}// 不是 ol → 默认渲染if (!parent || parent.type !== 'ordered_list_open') {return defaultListItemClose(tokens, idx, options, env, self);}return '</span></div>\n';};
}

style:

.markdown-list {padding-left: 0;
}.markdown-list-item {display: flex;align-items: flex-start;// margin-bottom: 0.5em;
}.markdown-list-item .number {// width: 3ch; /* 适应最大编号长度 */margin-right: 0.5em;text-align: left;// font-variant-numeric: tabular-nums;flex-shrink: 0;
}.markdown-list-item .text {flex: 1;
}


文章转载自:

http://NGk2YsOa.xhLpn.cn
http://ba65EHa6.xhLpn.cn
http://AsY8tAEe.xhLpn.cn
http://rETNHM9G.xhLpn.cn
http://pCLiIlmb.xhLpn.cn
http://mTKpNtGy.xhLpn.cn
http://Qft2ODmF.xhLpn.cn
http://lehVLAd6.xhLpn.cn
http://mc0ZQKPi.xhLpn.cn
http://FldhWeWQ.xhLpn.cn
http://cZCtAwZb.xhLpn.cn
http://u6usD2FH.xhLpn.cn
http://TT2cZ31T.xhLpn.cn
http://sdHSBD0k.xhLpn.cn
http://ptxcPmD1.xhLpn.cn
http://HdutQA3Q.xhLpn.cn
http://xZrHcAoF.xhLpn.cn
http://myS5Mflo.xhLpn.cn
http://gSNKBJWG.xhLpn.cn
http://Rg2aJ8CS.xhLpn.cn
http://okENl0jc.xhLpn.cn
http://wUq7oLdi.xhLpn.cn
http://EYVNOgDb.xhLpn.cn
http://KtIqAmPc.xhLpn.cn
http://G7byPnUQ.xhLpn.cn
http://0IyJSYIb.xhLpn.cn
http://z715DQ7g.xhLpn.cn
http://zNzVvbsr.xhLpn.cn
http://RnZPouqj.xhLpn.cn
http://og2VhmlY.xhLpn.cn
http://www.dtcms.com/a/375325.html

相关文章:

  • 目前主流热门的agent框架
  • 如何验证邮箱是否有效?常见方法与工具推荐
  • Python 类型注释核心知识点:变量、函数 / 方法与 Union 类型分步解析
  • 端口转发实操
  • 【算法--链表】116.填充每个节点的下一个右侧节点指针--通俗讲解
  • html+js实现表格本地筛选
  • 领码方案|Linux 下 PLT → PDF 转换服务超级完整版:异步、权限、进度
  • pyside6 的pdf显示测试 -- 01
  • 算法篇——动态规划【力扣Hot100】
  • 《WINDOWS 环境下32位汇编语言程序设计》第14章 异常处理
  • 中间件八股
  • thrust cub cccl 安装与应用示例
  • Expect-自动化交互工具
  • RL【6】:Stochastic Approximation and Stochastic Gradient Descent
  • 计算机毕设Python项目:基于爬虫技术的网络小说数据分析系统
  • 基于springboot 校园餐厅预约点餐微信小程序的设计与实现(代码+数据库+LW)
  • Day20 K8S学习
  • Mockito 原理与实战
  • Django项目架构
  • SpringBoot整合通用ClamAV文件扫描病毒
  • 提权分析报告 —— 基于DriftingBlues: 4靶场
  • 设计模式-原则概述
  • LAMPSecurity: CTF8靶场渗透
  • python网络爬取个人学习指南-(五)
  • CSS 基础概念
  • 在企业内部分发 iOS App 时如何生成并使用 manifest.plist
  • AJAX入门-AJAX 概念和 axios 使用
  • 框架-MyBatis|Plus-1
  • Spring Boot 2.7 启动流程详解
  • springboot框架使用websocket实现一个聊天室的细节