From 385b87e08c23b1392d0e6d6fbdb6ef463fa28477 Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Sun, 13 Apr 2014 11:33:52 +0200 Subject: Added support for \-- and \--- to prevent interpretation as ndash and mdash --- doc/commands.doc | 16 ++++++++++++++++ src/cmdmapper.cpp | 2 ++ src/cmdmapper.h | 4 +++- src/commentscan.l | 6 ++++++ src/docparser.cpp | 29 +++++++++++++++++++++++++++++ src/docparser.h | 2 +- src/doctokenizer.l | 2 +- src/htmlentity.cpp | 3 ++- src/markdown.cpp | 10 ++++++++++ 9 files changed, 70 insertions(+), 4 deletions(-) diff --git a/doc/commands.doc b/doc/commands.doc index 4c3c2fc..0f36e61 100644 --- a/doc/commands.doc +++ b/doc/commands.doc @@ -209,6 +209,8 @@ documentation: \refitem cmdchardot \\\. \refitem cmddcolon \:: \refitem cmdpipe \\| +\refitem cmdndash \\\-- +\refitem cmdmdash \\\--- \endsecreflist The following subsections provide a list of all commands that are recognized by @@ -3077,6 +3079,20 @@ class Receiver for Markdown tables.
+\section cmdndash \\-- + + \addindex \\\-- + This command writes two dashes (\--) to the output. This allows + writing two consecutive dashes to the output instead of one n-dash character (--). + +
+\section cmdmdash \\--- + + \addindex \\\--- + This command writes three dashes (\---) to the output. This allows + writing three consecutuve dashes to the output instead of one m-dash character (---). + +
\htmlonly
\endhtmlonly

\htmlonly --- \endhtmlonly diff --git a/src/cmdmapper.cpp b/src/cmdmapper.cpp index 6320169..45469f2 100644 --- a/src/cmdmapper.cpp +++ b/src/cmdmapper.cpp @@ -136,6 +136,8 @@ CommandMap cmdMap[] = { "parblock", CMD_PARBLOCK }, { "endparblock", CMD_ENDPARBLOCK }, { "diafile", CMD_DIAFILE }, + { "--", CMD_NDASH }, + { "---", CMD_MDASH }, { 0, 0 }, }; diff --git a/src/cmdmapper.h b/src/cmdmapper.h index eafc77b..d89e368 100644 --- a/src/cmdmapper.h +++ b/src/cmdmapper.h @@ -125,7 +125,9 @@ enum CommandType CMD_PARBLOCK = 95, CMD_ENDPARBLOCK = 96, CMD_DIAFILE = 97, - CMD_LATEXINCLUDE = 98 + CMD_LATEXINCLUDE = 98, + CMD_NDASH = 99, + CMD_MDASH = 100 }; enum HtmlTagType diff --git a/src/commentscan.l b/src/commentscan.l index 4b25dff..bd20bf0 100644 --- a/src/commentscan.l +++ b/src/commentscan.l @@ -1200,6 +1200,12 @@ RCSTAG "$"{ID}":"[^\n$]+"$" ^{B}*([\-:|]{B}*)*("--"|"---")({B}*[\-:|])*{B}*/\n { // horizontal line (dashed) addOutput(yytext); } +{CMD}"---" { // escaped mdash + addOutput(yytext); + } +{CMD}"--" { // escaped mdash + addOutput(yytext); + } "---" { // mdash addOutput(insidePre || Doxygen::markdownSupport ? yytext : "—"); } diff --git a/src/docparser.cpp b/src/docparser.cpp index 3f7a8bc..e5e2895 100644 --- a/src/docparser.cpp +++ b/src/docparser.cpp @@ -1271,6 +1271,15 @@ reparsetoken: case CMD_PERCENT: children.append(new DocSymbol(parent,DocSymbol::Sym_Percent)); break; + case CMD_NDASH: + children.append(new DocSymbol(parent,DocSymbol::Sym_Minus)); + children.append(new DocSymbol(parent,DocSymbol::Sym_Minus)); + break; + case CMD_MDASH: + children.append(new DocSymbol(parent,DocSymbol::Sym_Minus)); + children.append(new DocSymbol(parent,DocSymbol::Sym_Minus)); + children.append(new DocSymbol(parent,DocSymbol::Sym_Minus)); + break; case CMD_QUOTE: children.append(new DocSymbol(parent,DocSymbol::Sym_Quot)); break; @@ -3281,6 +3290,8 @@ int DocIndexEntry::parse() case CMD_HASH: m_entry+='#'; break; case CMD_DCOLON: m_entry+="::"; break; case CMD_PERCENT: m_entry+='%'; break; + case CMD_NDASH: m_entry+="--"; break; + case CMD_MDASH: m_entry+="---"; break; case CMD_QUOTE: m_entry+='"'; break; default: warn_doc_error(g_fileName,doctokenizerYYlineno,"Unexpected command %s found as argument of \\addindex", @@ -5373,6 +5384,15 @@ int DocPara::handleCommand(const QCString &cmdName) case CMD_PERCENT: m_children.append(new DocSymbol(this,DocSymbol::Sym_Percent)); break; + case CMD_NDASH: + m_children.append(new DocSymbol(this,DocSymbol::Sym_Minus)); + m_children.append(new DocSymbol(this,DocSymbol::Sym_Minus)); + break; + case CMD_MDASH: + m_children.append(new DocSymbol(this,DocSymbol::Sym_Minus)); + m_children.append(new DocSymbol(this,DocSymbol::Sym_Minus)); + m_children.append(new DocSymbol(this,DocSymbol::Sym_Minus)); + break; case CMD_QUOTE: m_children.append(new DocSymbol(this,DocSymbol::Sym_Quot)); break; @@ -6828,6 +6848,15 @@ void DocText::parse() case CMD_PERCENT: m_children.append(new DocSymbol(this,DocSymbol::Sym_Percent)); break; + case CMD_NDASH: + m_children.append(new DocSymbol(this,DocSymbol::Sym_Minus)); + m_children.append(new DocSymbol(this,DocSymbol::Sym_Minus)); + break; + case CMD_MDASH: + m_children.append(new DocSymbol(this,DocSymbol::Sym_Minus)); + m_children.append(new DocSymbol(this,DocSymbol::Sym_Minus)); + m_children.append(new DocSymbol(this,DocSymbol::Sym_Minus)); + break; case CMD_QUOTE: m_children.append(new DocSymbol(this,DocSymbol::Sym_Quot)); break; diff --git a/src/docparser.h b/src/docparser.h index b37a4a5..fb4f084 100644 --- a/src/docparser.h +++ b/src/docparser.h @@ -395,7 +395,7 @@ class DocSymbol : public DocNode /* doxygen commands mapped */ Sym_BSlash, Sym_At, Sym_Less, Sym_Greater, Sym_Amp, Sym_Dollar, Sym_Hash, Sym_DoubleColon, Sym_Percent, Sym_Pipe, - Sym_Quot + Sym_Quot, Sym_Minus }; enum PerlType { Perl_unknown = 0, Perl_string, Perl_char, Perl_symbol, Perl_umlaut, Perl_acute, Perl_grave, Perl_circ, Perl_slash, Perl_tilde, diff --git a/src/doctokenizer.l b/src/doctokenizer.l index 942c7ef..7ffbbb3 100644 --- a/src/doctokenizer.l +++ b/src/doctokenizer.l @@ -350,7 +350,7 @@ HFILEMASK ("."{FILESCHAR}*{FILEECHAR}+)* FILEMASK ({FILESCHAR}*{FILEECHAR}+("."{FILESCHAR}*{FILEECHAR}+)*)|{HFILEMASK} LINKMASK [^ \t\n\r\\@<&${}]+("("[^\n)]*")")?({BLANK}*("const"|"volatile"){BLANK}+)? VERBATIM "verbatim"{BLANK}* -SPCMD1 {CMD}([a-z_A-Z][a-z_A-Z0-9]*|{VERBATIM}) +SPCMD1 {CMD}([a-z_A-Z][a-z_A-Z0-9]*|{VERBATIM}|"--"|"---") SPCMD2 {CMD}[\\@<>&$#%~".|] SPCMD3 {CMD}form#[0-9]+ SPCMD4 {CMD}"::" diff --git a/src/htmlentity.cpp b/src/htmlentity.cpp index c1a9ad0..c49491e 100644 --- a/src/htmlentity.cpp +++ b/src/htmlentity.cpp @@ -311,7 +311,8 @@ static struct htmlEntityInfo { SYM(DoubleColon), "::", "::", "::", "::", "::", "::", "::", { "::", DocSymbol::Perl_string }}, { SYM(Percent), "%", "%", "%", "%", "\\%", "%", "%", { "%", DocSymbol::Perl_char }}, { SYM(Pipe), "|", "|", "|", "|", "$|$", "|", "|", { "|", DocSymbol::Perl_char }}, - { SYM(Quot), "\"", "\"", "\"", """, "\"", "\"", "\"", { "\"", DocSymbol::Perl_char }} + { SYM(Quot), "\"", "\"", "\"", """, "\"", "\"", "\"", { "\"", DocSymbol::Perl_char }}, + { SYM(Minus), "-", "-", "-", "-", "-\\/", "-", "-", { "-", DocSymbol::Perl_char }} }; static const int g_numHtmlEntities = (int)(sizeof(g_htmlEntities)/ sizeof(*g_htmlEntities)); diff --git a/src/markdown.cpp b/src/markdown.cpp index 593c45e..291e1dc 100644 --- a/src/markdown.cpp +++ b/src/markdown.cpp @@ -1004,6 +1004,16 @@ static int processSpecialCommand(GrowBuf &out, const char *data, int offset, int if (c=='[' || c==']' || c=='*' || c=='+' || c=='-' || c=='!' || c=='(' || c==')' || c=='.' || c=='`' || c=='_') { + if (c=='-' && size>3 && data[2]=='-' && data[3]=='-') // \--- + { + out.addStr(&data[1],3); + return 4; + } + else if (c=='-' && size>2 && data[2]=='-') // \-- + { + out.addStr(&data[1],2); + return 3; + } out.addStr(&data[1],1); return 2; } -- cgit v0.12