diff options
-rw-r--r-- | src/markdown.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/markdown.cpp b/src/markdown.cpp index d63492e..0a71aae 100644 --- a/src/markdown.cpp +++ b/src/markdown.cpp @@ -108,8 +108,8 @@ static Entry *g_current; static QCString g_fileName; static int g_lineNr; static int g_indentLevel=0; // 0 is outside markdown, -1=page level -static char g_doxynbsputf8[3] = {'\xc2', '\xa0', '\0'}; // UTF-8 nbsp -static char *g_doxynbsp = "&_doxy_nbsp;"; +static const char g_utf8_nbsp[3] = {'\xc2', '\xa0', '\0'}; // UTF-8 nbsp +static const char *g_doxy_nsbp = "&_doxy_nbsp;"; // doxygen escape command for UTF-8 nbsp //---------- const int codeBlockIndent = 4; @@ -1029,6 +1029,17 @@ static int processCodeSpan(GrowBuf &out, const char *data, int /*offset*/, int s return end; } +static void addStrEscapeUtf8Nbsp(GrowBuf &out,const char *s,int len) +{ + if (strnstr(s,g_doxy_nsbp,len)==0) // no escape needed -> fast + { + out.addStr(s,len); + } + else // escape needed -> slow + { + out.addStr(substitute(QCString(s).left(len),g_doxy_nsbp,g_utf8_nbsp)); + } +} static int processSpecialCommand(GrowBuf &out, const char *data, int offset, int size) { @@ -1045,7 +1056,7 @@ static int processSpecialCommand(GrowBuf &out, const char *data, int offset, int if (qstrncmp(&data[i+1],endBlockName,l)==0) { //printf("found end at %d\n",i); - out.addStr(substitute(QCString(data).left(i+1+l),g_doxynbsp,g_doxynbsputf8)); + addStrEscapeUtf8Nbsp(out,data,i+1+l); return i+1+l; } } @@ -2175,7 +2186,7 @@ static void writeFencedCodeBlock(GrowBuf &out,const char *data,const char *lng, { out.addStr("{"+lang+"}"); } - out.addStr(substitute(QCString(data+blockStart).left(blockEnd-blockStart),g_doxynbsp,g_doxynbsputf8)); + addStrEscapeUtf8Nbsp(out,data+blockStart,blockEnd-blockStart); out.addStr("\n"); out.addStr("@endcode\n"); } @@ -2485,7 +2496,7 @@ static QCString detab(const QCString &s,int &refIndent) // special handling of the UTF-8 nbsp character 0xc2 0xa0 if (c == '\xc2' && data[i] == '\xa0') { - out.addStr(g_doxynbsp); + out.addStr(g_doxy_nsbp); i++; } else @@ -2562,7 +2573,7 @@ QCString processMarkdown(const QCString &fileName,const int lineNr,Entry *e,cons processInline(out,s,s.length()); out.addChar(0); Debug::print(Debug::Markdown,0,"======== Markdown =========\n---- input ------- \n%s\n---- output -----\n%s\n=========\n",qPrint(input),qPrint(out.get())); - return substitute(out.get(),g_doxynbsp," "); + return substitute(out.get(),g_doxy_nsbp," "); } //--------------------------------------------------------------------------- |