How can I intercept and modify markdown from the wmd markdown editor before it posts?

StackOverflow https://stackoverflow.com/questions/1561012

  •  21-09-2019
  •  | 
  •  

문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top