如何在发布之前从 wmd markdown 编辑器拦截并修改 markdown?

发布于 2024-08-07 02:57:15 字数 2693 浏览 7 评论 0原文

我正在启动一个 Stack Exchange 站点,我希望能够在 Markdown 脚本获取问题文本之前和之后拦截问题文本。

我希望能够在问题窗口中输入[custom-tag]要更改的内容[/custom-tag],然后删除要更改的内容(作为标准降价引擎将无法解释它)存储它,然后用我自己的(服务器端)引擎处理后要更改的内容替换输出中的标签。

我第一步就失败了;我找不到 markdown javascript。它是否隐藏在 /content/js/master.js 中?

编辑:我将尝试通过一个我想要实现的目标的示例使这一点更清楚。

我正在运行一个面向扑克的 SE 网站。玩家讨论扑克牌局,但他们不会输入牌局中发生的情况的纯文本记录,而是使用转换器使其更具可读性。

因此,他们不会在论坛上发布此内容:

PokerStars Game #29112867044:  Omaha Pot Limit ($100/$200) - 2009/06/07 19:51:27 ET
Table 'Thomsen' 9-max Seat #2 is the button
Seat 2: Mary & Joey ($14729 in chips) 
Seat 4: William ($28306 in chips) 
Mary & Joey: posts small blind $100
William: posts big blind $200
*** HOLE CARDS ***
Mary & Joey: raises $400 to $600
William: calls $400
*** FLOP *** [6d Td 3c]
William: checks 
Mary & Joey: checks 
*** TURN *** [6d Td 3c] [Kc]
William: checks 
Mary & Joey: checks 
*** RIVER *** [6d Td 3c Kc] [7d]
William: bets $600
Mary & Joey: folds 
Uncalled bet ($600) returned to William
William collected $1198 from pot
William: doesn't show hand 
*** SUMMARY ***
Total pot $1200 | Rake $2 
Board [6d Td 3c Kc 7d]
Seat 2: Mary & Joey (button) (small blind) folded on the River
Seat 4: William (big blind) collected ($1198)

他们将首先访问第 3 方网站并将其转换为:

PokerStars Pot-Limit Omaha,$200.00 BB(2 手牌)
SB ($14729)
BB ($28306)

翻牌前
SB 下注 $600,BB 跟注 $400

翻牌:($1200) 6, 10< img src="https://i.sstatic.net/s4GYk.gif" alt="">, 3(2 名玩家)
BB 检查,SB 检查

转向:($1200) K(2 名玩家)
BB 检查,SB 检查

河牌:($1200) 7(2 名玩家)
BB 下注 600 美元,1 倍

总底池: $1200 | Rake: $2

我想删除用户必须访问第 3 方网站的步骤,将其粘贴到他们的手中,选择 HTML 输出,然后将结果复制并粘贴到问题中。相反,我希望他们能够用 [hand][/hand] 标签包装原始手测试,并且转换将自动处理。

编辑2:

经过进一步调查,这似乎是不可能的(没有大量 hacky JS)。 首先需要解决 Ajax 跨域问题,才能使用任何外部服务进行转换。

然后,如果您设法覆盖 WMD 预览 - 您仍然需要弄清楚当实际答案正常呈现时该怎么做。一种方法是让 JS 在呈现任何问题或答案时查找标签,并使用转换后的版本更新 DOM - 这会降低性能 POV。

我想我必须等待并希望 SE 允许我们通过其他方式来覆盖这个问题。

I'm starting a Stack Exchange site and I want to be able to intercept the question text before and after the markdown script gets at it.

I want to be be able to enter [custom-tag]stuff to be altered[/custom-tag] in the question window, and then have the stuff to be altered removed (as the standard markdown engine won't be able to interpret it) store it, and then replace the tags in the output with the stuff to be altered after it has been processed by my own (server-side) engine.

I'm failing at the first step; I can't find the markdown javascript is. Is it somewhere hidden in /content/js/master.js?

Edit: I will try and make this a bit clearer with an example of what I am trying to achieve.

I'm running a Poker oriented SE site. Players discuss poker hands but instead of entering the plain text transcript of what happened in a hand, they will use a converter to make it more readable.

So, instead of posting up this on a forum:

PokerStars Game #29112867044:  Omaha Pot Limit ($100/$200) - 2009/06/07 19:51:27 ET
Table 'Thomsen' 9-max Seat #2 is the button
Seat 2: Mary & Joey ($14729 in chips) 
Seat 4: William ($28306 in chips) 
Mary & Joey: posts small blind $100
William: posts big blind $200
*** HOLE CARDS ***
Mary & Joey: raises $400 to $600
William: calls $400
*** FLOP *** [6d Td 3c]
William: checks 
Mary & Joey: checks 
*** TURN *** [6d Td 3c] [Kc]
William: checks 
Mary & Joey: checks 
*** RIVER *** [6d Td 3c Kc] [7d]
William: bets $600
Mary & Joey: folds 
Uncalled bet ($600) returned to William
William collected $1198 from pot
William: doesn't show hand 
*** SUMMARY ***
Total pot $1200 | Rake $2 
Board [6d Td 3c Kc 7d]
Seat 2: Mary & Joey (button) (small blind) folded on the River
Seat 4: William (big blind) collected ($1198)

they will first go to a 3rd party website and convert it to this:

PokerStars Pot-Limit Omaha, $200.00 BB (2 handed)

SB ($14729)
BB ($28306)

Preflop:
SB bets $600, BB calls $400

Flop: ($1200) 6, 10, 3(2 players)
BB checks, SB checks

Turn: ($1200) K(2 players)
BB checks, SB checks

River: ($1200) 7(2 players)
BB bets $600, 1 fold

Total pot: $1200 | Rake: $2

I want to cut out the step where the user has to go to a 3rd party website, paste in their hand, select HTML output and then copy and paste the result into the question. Instead I want them to just be able to wrap the raw hand test with [hand][/hand] tags and the conversion will be handled automatically.

Edit 2:

On further investigation it looks like this is not possible (without a lot of hacky JS).
One would need to get around Ajax cross domain issues firstly to use any external service to do the converting.

Then if you manage to override the WMD preview - you still have to work out what to do when the actual answer is rendered normally. One way to do it would be to have JS look for the tag whenever any question or answer is rendered and update the DOM with a converted version -which would suck from a performance POV.

I think I'll have to wait and hope SE allow some other way for us to override this.

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

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

发布评论

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

评论(1

酷遇一生 2024-08-14 02:57:15

当您键入时,WMD 会自动填充预览元素,对吗?嗯,它需要有一个转换器来做到这一点。该转换器就是 Showdown(您可以在此处获取)。以下是它的用法(从源文件中提取):

// Showdown usage:

var text = "Markdown *rocks*.";

var converter = new Showdown.converter();
var html = converter.makeHtml(text);

这意味着您可以不使用提供的预览元素,而是使用您自己填充的预览元素。此外,您需要自己监听文本区域上的 keypress 事件并解析文本,然后调用 Showdown。当输出符合您的要求时,将其放入您自己的预览元素中。

WMD automatically populates the preview element as you type, right? Well, it needs to have a converter somewhere to do this. That converter is Showdown (which you could obtain here). Here is its usage (pulled from the source file):

// Showdown usage:

var text = "Markdown *rocks*.";

var converter = new Showdown.converter();
var html = converter.makeHtml(text);

This means that you can simply not use the preview element that is provided, in favor of your own that you populate yourself. Furthermore, you will need to listen to the keypress event on the textarea yourself and do your parsing of the text, followed by calling Showdown. When the output is as you like it, throw it into your own preview element.

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