Comments (13)
没事,我先采取其他方案避免这个问题,后续这个问题查到原因我再回复
from lute.
可能需要提供更多信息才好定位问题,比如:
- 输入的 Markdown 文本
- Lute 参数选项
from lute.
和markdown文本应该没什么关系,我上传了一个能够复现的最小化项目,代码仓库链接
from lute.
非常抱歉,我目前没有时间看这个问题……
from lute.
这个问题我看主要引起的原因是由于nuxt这个环境下,它给window设置了属性window.process: { client: boolean, server: boolean },而普通浏览器环境下的window不存在该属性。Lute引擎代码中有三四处判断了$global(window).process === 'undefined',这在nuxt环境下是不准确的,自行调试在各判断处补充为 $global.process.client || $global.process === 'undefined'后不再出现报错,具体你们可以参考一下看修复方案需要咋整
from lute.
请看下是不是类似这个地方:
from lute.
from lute.
对没错,就是类似于这样的地方,不过此处并没有产生报错,我也没有做修改,下面有几处产生的报错的和这里是一样的。我修改的是lute.min.js,截图放附件了
…
------------------ 原始邮件 ------------------ 发件人: "88250/lute" @.>; 发送时间: 2023年3月28日(星期二) 中午11:52 @.>; @.@.>; 主题: Re: [88250/lute] 关于nuxt3报错“Cannot convert undefined or null to object” (Issue #191) 请看下是不是类似这个地方: https://github.com/gopherjs/gopherjs/blob/df0fbb1be49872e28d6cf1415d3f8ffc8bd76c90/compiler/prelude/prelude.go#L75 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>
请问修复了吗?我现在也遇到了这个问题,想在nuxt3中实现SSR渲染。
from lute.
大概37行,加一个判断就行
if(!i){return;}
我看根源是 process.argv是undefined的时候没判断导致
源码
h=$global.process;if(!(h===undefined)){i=h.argv;$pkg.Args=$makeSlice(FK,($parseInt(i.length)-1>>0));
修改之后
h=$global.process;if(!(h===undefined)){i=h.argv;if(!i){return;}$pkg.Args=$makeSlice(FK,($parseInt(i.length)-1>>0));
改完之后可用
const lute=Lute.New();const html = lute.MarkdownStr("", "# hello");html
另外我是直接引用的,如下:
// nuxt.config.ts
const staticV = "202304191333"
app: {
head: {
script: [
{
src: appBase + "lib/lute/lute-1.7.5-20230410.min.js?v=" + staticV,
body: true,
},
],
},
},
我这是ssr=fasle的spa方案。ssr的话可能还得踩坑
from lute.
个人实践下来,在nuxt3框架下不建议使用这个渲染引擎,首先他在浏览器环境下判断window.process属性,将浏览器环境误判断了为了node环境,目前没有什么很好的办法,当前采取的方案是修改源码,并迁移cdn;其次在服务器端也存在问题,nuxt3的服务端为nitro,是采用的es6规范运行的,而lute.min.js本身为commonjs模块,使用上不兼容,强行引入将导致build失败,可能外置一个node服务进行md解析会好一点。
后续可能会尝试在服务器端解析时采用别的markdown引擎转换成html,在浏览器端再使用vditor的静态方法对解析的html文本进行二次渲染,不过尚未比较如marked和lute两者在将markdown转换成html时会有什么差别。
from lute.
个人实践下来,在nuxt3框架下不建议使用这个渲染引擎,首先他在浏览器环境下判断window.process属性,将浏览器环境误判断了为了node环境,目前没有什么很好的办法,当前采取的方案是修改源码,并迁移cdn;其次在服务器端也存在问题,nuxt3的服务端为nitro,是采用的es6规范运行的,而lute.min.js本身为commonjs模块,使用上不兼容,强行引入将导致build失败,可能外置一个node服务进行md解析会好一点。
后续可能会尝试在服务器端解析时采用别的markdown引擎转换成html,在浏览器端再使用vditor的静态方法对解析的html文本进行二次渲染,不过尚未比较如marked和lute两者在将markdown转换成html时会有什么差别。
纠正一下,nuxt3生产环境应该不会被误判,它不具备window.process属性
from lute.
ssr已验证,我上面的修复版,可以完美运行。
可以看看我的:https://github.com/terwer/zhi/blob/dev/apps/zhi-server-vue3-ssr/src/server/index.ts#L86
服务端效果
客户端效果
from lute.
这个问题我们关闭了,目前没有办法从根源上解决,感谢各位讨论。
from lute.
Related Issues (20)
- 列表渲染异常 HOT 6
- Please add support for wikilinks HOT 3
- vite import导入,打包报错 HOT 6
- VditorIRDOM2Md 公式多出一个换行
- 1.7.3 及以上版本的术语拼写修正失效了 HOT 1
- 语法树提供源码映射 HOT 16
- 改进自动链接解析
- XSS 代码注入漏洞 HOT 1
- XSS 代码注入漏洞
- XSS 代码注入漏洞
- XSS 代码注入漏洞
- XSS 代码注入漏洞
- 针对 XSS 处理的架构改进 HOT 1
- 换行+冒号会被识别为表格
- 在 Vditor 中设置多个自定义渲染器时,无论编辑器模式,始终调用最后一种渲染器
- 链接含下划线时,自动添加转义斜线问题 HOT 2
- 跟进 CommonMark 0.31
- 渲染 Markdown 引用块能否支持 GitHub 扩展语法
- 支持保留 `\r\n`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lute.