Ticket #51 (new defect)
Opened 12 months ago
Bold italic creates improperly nested tags
| Reported by: | chas | Owned by: | deveiant |
|---|---|---|---|
| Priority: | normal | Milestone: | Bugfixes |
| Component: | API | Version: | |
| Severity: | normal | Keywords: | |
| Cc: |
Description
When converting ***bold italic text*** to bold italic, the result is
<strong><em>bold italic text</strong></em>
because the Regex grabs the first ** of the final *** instead of closing the * first. The easiest solution is to parse *** as nested tags.
Thus this:
# 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
### Transform italic- and bold-encoded text in a copy of the specified +str+
### and return it.
def transform_italic_and_bold( str, rs )
@log.debug " Transforming italic and bold"
str.
gsub( BoldRegexp, %{<strong>\\2</strong>} ).
gsub( ItalicRegexp, %{<em>\\2</em>} )
end
Becomes this:
# Pattern to match strong emphasis and emphasis in Markdown text
BoldItalicRegexp = %r{ (\*\*\*|___) (\S|\S.+?\S) \1 }x
# 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
### Transform italic- and bold-encoded text in a copy of the specified +str+
### and return it.
def transform_italic_and_bold( str, rs )
@log.debug " Transforming italic and bold"
str.
gsub( BoldItalicRegexp, %{<strong><em>\\2</em></strong>} ).
gsub( BoldRegexp, %{<strong>\\2</strong>} ).
gsub( ItalicRegexp, %{<em>\\2</em>} )
end
A workaround is to mix _ and * syntax: _**bold italic text**_ or **_bold italic text_**.
Note: See
TracTickets for help on using
tickets.
