维基媒体如何转变其模型语法?

发布于 2024-12-04 04:48:13 字数 183 浏览 1 评论 0原文

我想知道维基媒体如何将其模型语法 ({{model|options}}) 转换为 html 代码。 我有一个简单模型 ({{.*?}}) 的正则表达式,但对于嵌套模型则失败(例如: {{model|options 包含 {{submodel|options} }...}})

I would like to know how does Wikimedia transform its model syntax ({{model|options}}) into html code.
I have a regex for a simple model ({{.*?}}) but it fails for a nested model (ex: {{model|options containing a {{submodel|options}}...}})

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不必在意 2024-12-11 04:48:13

记住,

有些人在遇到问题时会想:“我知道,我会用
正则表达式。”现在他们有两个问题。- Jamie Zawinski

也就是说,您可以阅读: 论坛标签。实现它们的最佳方法是什么? 我做了一个嵌套标签的示例,两者都带有“纯”正则表达式和“更稳定”的 C# 解析器使用了一些正则表达式,但使堆栈不受正则表达式的控制。

您可以使用平衡组来实现。 “基本”正则表达式(有些人不认为它们是真正的正则表达式),

但我不会用正则表达式之类的东西来编程像 Wiki 这样的东西。正则表达式的问题在于,对它们进行编程非常困难。他们不会回溯(有一个选项可以做到这一点,但很难构建一个不需要回溯或只需要有限回溯的正则表达式),当他们开始回溯时,那就结束了:他们可以等待几分钟寻找正确的捕获组合。

Remember,

Some people, when confronted with a problem, think "I know, I'll use
regular expressions." Now they have two problems. - Jamie Zawinski

That said, you can read: Forum tags. What is the best way to implement them? I made an example of nested tags, both with "pure" Regex and with a "more stable" C# parser that uses a little of Regexes but keeps the stack out of the Regex hands.

You can do it with balancing groups. They aren't part of "base" Regex (and some persons don't consider them to be true regexes),

But I wouldn't program something as big as Wiki with something like a regex. The problem of regexes is that it's quite difficult to program them so that they don't backtrack (there is an option to do it, but it's difficult to build a regex that doesn't need backtracking or that need only limited amout of backtracking), and when they begin to backtrack it's the end: they could stall for minutes searching for the right combination of captures.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文