[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

BlueCloth bold/italic problem.

Lloyd Zusman

11/20/2004 3:02:00 AM

I have discovered that in the latest release of BlueCloth, it's
impossible to render 2-character words in either bold or italic.

I looked through the source code, and I found the reason why:

# Pattern to match strong emphasis in Markdown text
BoldRegexp = %r{ (\*\*|__) (\S|\S.+?\S) \1 }x

# Pattern to match normal emphasis in Markdown text
ItalicRegexp = %r{ (\*|_) (\S|\S.+?\S) \1 }x

Notice that the regexps only match strings that are either 1 character
long or at least 3 characters long. To fix this, I believe that the
code needs to be changed as follows:

# Pattern to match strong emphasis in Markdown text
BoldRegexp = %r{ (\*\*|__) (\S|\S.*?\S) \1 }x

# Pattern to match normal emphasis in Markdown text
ItalicRegexp = %r{ (\*|_) (\S|\S.*?\S) \1 }x

(I replaced ".+?" with ".*?")

Is there any reason for why this change shouldn't be made? If so, is
there another way to get BlueCloth to render 2-character words in bold
or italics?

Thanks in advance.


--
Lloyd Zusman
ljz@asfast.com
God bless you.



1 Answer

Lloyd Zusman

11/20/2004 6:37:00 AM

0

Lloyd Zusman <ljz@asfast.com> writes:

> I have discovered that in the latest release of BlueCloth, it's
> impossible to render 2-character words in either bold or italic.
>
> I looked through the source code, and I found the reason why:
>
> # Pattern to match strong emphasis in Markdown text
> BoldRegexp = %r{ (\*\*|__) (\S|\S.+?\S) \1 }x
>
> # Pattern to match normal emphasis in Markdown text
> ItalicRegexp = %r{ (\*|_) (\S|\S.+?\S) \1 }x
>
> Notice that the regexps only match strings that are either 1 character
> long or at least 3 characters long. To fix this, I believe that the
> code needs to be changed as follows:
>
> # Pattern to match strong emphasis in Markdown text
> BoldRegexp = %r{ (\*\*|__) (\S|\S.*?\S) \1 }x
>
> # Pattern to match normal emphasis in Markdown text
> ItalicRegexp = %r{ (\*|_) (\S|\S.*?\S) \1 }x
>
> (I replaced ".+?" with ".*?")

Also, the bold and italic conversions fail if the string spans more than
one line. For example ...

_BlueCloth will not turn this into
italics because it spans two lines_

Therefore, I suggest the following change, as well:

# Pattern to match strong emphasis in Markdown text
BoldRegexp = %r{ (\*\*|__) (\S|\S.*?\S) \1 }xm

# Pattern to match normal emphasis in Markdown text
ItalicRegexp = %r{ (\*|_) (\S|\S.*?\S) \1 }xm

(note the 'm' at the right side of the regexps)



--
Lloyd Zusman
ljz@asfast.com
God bless you.