如何在一个项目中拥有多个标记的js实例?
我无法克服的问题是,我无法实现有 2 个并行实例的状态,哦 markedjs
它们在我正在通过的配置方面完全独立工作。
换句话说,我需要两个不同的降价处理程序,因为在一种情况下我想使用算法 X 来解析降价文本,另一种情况下使用算法 Z 来解析降价文本。但是从我在官方文档中读到的内容来看,这是......不可能......?真的吗?
多次调用marked.use()来覆盖同一个函数将优先考虑最后分配的版本。重写函数可以返回 false 以回退到序列中的上一个重写,或者如果所有重写都返回 false,则恢复默认行为。返回任何其他值(包括什么都不返回)将防止回退行为。
事实上,这就是它在我这边的工作方式 - 我在应用程序的两个不同部分使用 marked.parse()
,并且我看到两个地方都反映了更改,即使我尝试有条件地更改配置(使用标志什么的,没关系,结果总是一样的)。
如何修复它?如何开发出如此无意义的解决方案呢?
My problem, which I cannot overcome is that I cannot achieve a state where I have 2 parallel instances oh markedjs
which work fully independently in terms of configuration I am passing through.
In other words I need two different markdown handlers, as in one case I want to parse markdowned text using say algorithm X, and the other using alghorithm Z. But from what I read in official docs it's... impossible...? Really?
Calling marked.use() to override the same function multiple times will give priority to the version that was assigned last. Overriding functions can return false to fall back to the previous override in the sequence, or resume default behavior if all overrides return false. Returning any other value (including nothing) will prevent fallback behavior.
And indeed, that's how it works on my end - I use marked.parse()
in two different parts of app and I see changes reflected in both places even though I try to conditionally change the configuration (using flag or something, doesn't matter, the result is always the same).
How to fix it? How can one develop such nonsensefull solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个答案有点晚了。
为了避免这种情况,您可以实例化一个新的
Marked
对象并向其传递扩展名,例如:文档: https://marked.js.org/using_advanced#instance
A little late on this answer.
To avoid this, you can instantiate a new
Marked
object and pass extensions to that, e.g.:Documentation: https://marked.js.org/using_advanced#instance