|
From: Blake W. <bw...@la...> - 2008-02-16 04:04:21
|
Waylan Limberg wrote:
> Thanks for the report. However, this makes it imposable to represent
> the string of an escapes backtick "\`" in a code span.
Argh. :)
>>>> s = "`code with a \` in it`"
> A double backtick won't work either.
>>>> s = "`` code with a \` in it``"
> This highlights the problem.
Okay, I've gotten a little closer with the attached patch.
In [7]: print markdown.markdown( "`code with a \` in it`" ).strip()
<p><code>code with a ` in it</code>
</p>
In [8]: print markdown.markdown( "`` code with a \` in it``" ).strip()
<p><code>code with a ` in it</code>
</p>
In [9]: print markdown.markdown( "`` code with a \`` in it``" ).strip()
<p><code>code with a `` in it</code>
</p>
> The string is being broken into two
> strings with a textnode containing the escaped backtick between. We
> can't run a pattern across two strings. The patterns code would need
> to be completely rewritten to fix that.
I think that way would lead to madness. It seems like it might be
simpler if the escaping mechanism were just a simple function, that you
could call from a lot of places, many times per line.
> Hmm, while typing this it occurred to me that we should be able to
> escape the escape character. I believe that presently, this would also
> create that textnode between two strings though. Maybe the the escape
> regex could be reworked. I'll see what I can do.
I don't think it really fits in as a pattern, since it can happen
multiple times per line, and in the middle of other patterns. Perhaps
it should be on a lower level, i.e. in createTextNode, or something?
The worst part of that, I believe, is that it would mess up the parsing
of all the other patterns, since they'ld have to avoid breaking on, say,
\\` for the code case.
Hey, what if the escape character turned the following character into
its hex-escape, as a pre-transformation? Something along these lines:
In [4]: def hexesc(m):
...: return "&#x%x;" % ord(m.group(1))
...:
In [5]: re.sub( r"\\(.)", hexesc, "abc \\ def" )
Out[5]: 'abc   def'
and then take that string, and run it through the patterns?
Later,
Blake.
|