@@ -89,12 +89,20 @@ enum class ExplicitPageResult
89
89
c==' >' || c==' :' || c==' ,' || \
90
90
c==' ;' || c==' \' ' || c==' "' || c==' `' )
91
91
92
- // is character at position i in data allowed before an emphasis section
92
+ // is character c allowed before an emphasis section
93
93
#define isOpenEmphChar (c ) \
94
94
(c==' \n ' || c==' ' || c==' \' ' || c==' <' || \
95
95
c==' >' || c==' {' || c==' (' || c==' [' || \
96
96
c==' ,' || c==' :' || c==' ;' )
97
97
98
+ // test for non breakable space (UTF-8)
99
+ #define isUtf8Nbsp (c1,c2 ) \
100
+ (c1==static_cast <char >(0xc2 ) && c2==static_cast <char >(0xa0 ))
101
+
102
+ #define isAllowedEmphStr (data,offset ) \
103
+ (!(offset>0 && isOpenEmphChar(data.data()[-1 ])) && \
104
+ !(offset>1 && isUtf8Nbsp(data.data()[-2 ],data.data()[-1 ])))
105
+
98
106
// is character at position i in data an escape that prevents ending an emphasis section
99
107
// so for example *bla (*.txt) is cool*
100
108
#define ignoreCloseEmphChar (c,cn ) \
@@ -1117,7 +1125,7 @@ int Markdown::Private::processEmphasis(std::string_view data,size_t offset)
1117
1125
AUTO_TRACE (" data='{}' offset={}" ,Trace::trunc (data),offset);
1118
1126
const size_t size = data.size ();
1119
1127
1120
- if ((offset> 0 && ! isOpenEmphChar ( data. data ()[- 1 ]) ) || // invalid char before * or _
1128
+ if (isAllowedEmphStr ( data,offset ) || // invalid char before * or _
1121
1129
(size>1 && data[0 ]!=data[1 ] && !(isIdChar (data[1 ]) || extraChar (data[1 ]))) || // invalid char after * or _
1122
1130
(size>2 && data[0 ]==data[1 ] && !(isIdChar (data[2 ]) || extraChar (data[2 ])))) // invalid char after ** or __
1123
1131
{
0 commit comments