Question

I've tried searching online, but it seems that topics covering this subject are very scarce, and -- short of the information on PageDown's Google Code page, there doesn't seem to be too much more on the topic (much less anything comprehensive)

I'm trying to add custom formatting to PageDown using either the preBlockGamut or the preSpanGamut, neither of which are accomplishing what I am hoping for it to do.

What I'm trying to do should be simple: I want any text that appears between two tildes to be formatted between <del> tags.

I have tried various ways so far with the preBlockGamut, with this one providing the closest thing to what I'm looking for:

converter.hooks.chain("preBlockGamut", function (text, rbg) {
  return text.replace(/~(.*?)~/, function (whole, inner) {
    return "<del>" + inner +"</del>";
  });
});

This works only somewhat as expected, in that it surrounds the first instance of the text like so: <del>T{inner text}</del>T. This only happens on the first instance, and I also have no idea where the T's are coming from because -- so far as I can tell with my code -- it isn't anywhere in the regex or the replacement.

I know that preBlockGamut should be used for block-level statements, and so I've tried a similar approach with preSpanGamut, with no better luck.

Does anyone on here have any experience with this that can possibly provide some insight into this issue? I'm obviously doing something wrong, but I can't seem to figure out where.

Était-ce utile?

La solution

After spending a while looking through PageDown's files, I found the source of my issue.

Markdown.Converter.js has the following lines:

// attacklab: Replace ~ with ~T
// This lets us use tilde as an escape char to avoid md5 hashes
// The choice of character is arbitray; anything that isn't
// magic in Markdown will work.
text = text.replace(/~/g, "~T");

This executes before the preBlockGamut hook would take affect, resulting in ~{inner text}~ becoming ~T{inner text}~T which then parsed as <del>T{inner text}</del>T.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top