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

VitePress 中以中文字符结尾的字体加粗 Markdown 格式无法解析

背景

在编写vitepress项目过程中,发现了一个markdown格式解析的问题。

md文件中,以中文句号结尾的字体加粗,无法正确解析:

不只是中文句号,只要是加粗语句中以中文字符结尾,都无法被正确解析

需要将中文字符移动到外部,才能被解析为正确的markdown格式

但如果在typora笔记软件上的话,是一切正常的。

原因

在vitepess的github项目上发起了issue,收到外国coder的回复

以句号结尾的字体加粗md格式无法被正确解析 · Issue #4752 · vuejs/vitepress · GitHub

原因是这是markdown语法的规范,中文(CJK)用户来说是个问题,因为他们的文本周围没有空格

加粗语句星号后处加上空格就可以被正确解析。

解决方案

在项目的配置文件处加上以下markdown自定义解析代码。

import { defineConfig } from 'vitepress';export default defineConfig({markdown: {config(md) {// https://github.com/markdown-it/markdown-it/blob/a367c44154d6c906c8652ed779af6a21f7eaed2e/lib/rules_inline/state_inline.mjs#L88md.inline.State.prototype.scanDelims = function (start, canSplitWord) {const max = this.posMax;const marker = this.src.charCodeAt(start);// treat beginning of the line as a whitespaceconst lastChar = start > 0 ? this.src.charCodeAt(start - 1) : 0x20;let pos = start;while (pos < max && this.src.charCodeAt(pos) === marker) {pos++;}const count = pos - start;// treat end of the line as a whitespaceconst nextChar = pos < max ? this.src.charCodeAt(pos) : 0x20;const isLastPunctChar = md.utils.isMdAsciiPunct(lastChar); // MODIFIEDconst isNextPunctChar = md.utils.isMdAsciiPunct(nextChar); // MODIFIEDconst isLastWhiteSpace = md.utils.isWhiteSpace(lastChar);const isNextWhiteSpace = md.utils.isWhiteSpace(nextChar);const left_flanking =!isNextWhiteSpace &&(!isNextPunctChar || isLastWhiteSpace || isLastPunctChar);const right_flanking =!isLastWhiteSpace &&(!isLastPunctChar || isNextWhiteSpace || isNextPunctChar);const can_open =left_flanking && (canSplitWord || !right_flanking || isLastPunctChar);const can_close =right_flanking && (canSplitWord || !left_flanking || isNextPunctChar);return { can_open, can_close, length: count };};},},
});

http://www.xdnf.cn/news/7641.html

相关文章:

  • 颠覆传统:PROFINET转EthernetIP在油墨生产线的成功应用
  • 小土堆pytorch--神经网路-卷积层池化层
  • 时尚外观+专业性能丨特伦斯V30Pro重新定义便携电子钢琴
  • 深入剖析Zynq AMP模式下CPU1中断响应机制:从原理到创新实践
  • 【八股战神篇】Java虚拟机(JVM)高频面试题
  • Spring Validation校验
  • 吃透 Golang 基础:数据结构之数组
  • 高级SQL技巧:窗口函数与复杂查询优化实战
  • RestFul操作ElasticSearch:索引与文档全攻略
  • 【基于SpringBoot的图书购买系统】深度讲解 分页查询用户信息,分析前后端交互的原理
  • [Java实战] Docker 快速启动 Sentinel 控制台(二十八)
  • 【node.js】核心进阶
  • IP风险画像技术:如何用20+维度数据构建网络安全护城河?
  • 73.矩阵置零
  • 【b站计算机拓荒者】【2025】微信小程序开发教程 - 3 项目目录结构
  • 《Flask vs Django:项目规模、灵活性与开发时间的深入比较》
  • IDEA2025版本使用Big Data Tools连接Linux上Hadoop的HDFS
  • C# 语法篇:字段的定义和运算
  • linux crontab定时执行python找不到module问题解决
  • window 安装 wsl + cuda + Docker
  • 2025年通信系统与智能计算国际学术会议(CSIC2025)
  • vue2+webpack环境变量配置
  • 将 /dev/vdb1 的空间全部合并到 /dev/mapper/centos-root(即扩展 CentOS 的根分区)
  • .NET外挂系列:3. 了解 harmony 中灵活的纯手工注入方式
  • 保密行业工作沟通安全:吱吱软件的“四重防泄露”设计
  • 自动化测试脚本点击运行后,打开Chrome很久??
  • java中的Filter使用详解
  • [Linux] Linux线程信号的原理与应用
  • Python实现VTK - 自学笔记(4):用Widgets实现三维交互控制
  • AI智能分析网关V4人员摔倒检测打造医院/工厂等多场景智能安全防护体系