Skip to content

Commit

Permalink
Added support for \-- and \--- to prevent interpretation as ndash and…
Browse files Browse the repository at this point in the history
… mdash
  • Loading branch information
Dimitri van Heesch committed Apr 13, 2014
1 parent 4ccfb9e commit 385b87e
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 4 deletions.
16 changes: 16 additions & 0 deletions doc/commands.doc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -3076,6 +3078,20 @@ class Receiver
character has to be escaped in some cases, because it is used
for Markdown tables.

<hr>
\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 (--).

<hr>
\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 (---).

<hr>
\htmlonly <center> \endhtmlonly
<h2>
Expand Down
2 changes: 2 additions & 0 deletions src/cmdmapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ CommandMap cmdMap[] =
{ "parblock", CMD_PARBLOCK },
{ "endparblock", CMD_ENDPARBLOCK },
{ "diafile", CMD_DIAFILE },
{ "--", CMD_NDASH },
{ "---", CMD_MDASH },
{ 0, 0 },
};

Expand Down
4 changes: 3 additions & 1 deletion src/cmdmapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/commentscan.l
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,12 @@ RCSTAG "$"{ID}":"[^\n$]+"$"
<Comment>^{B}*([\-:|]{B}*)*("--"|"---")({B}*[\-:|])*{B}*/\n { // horizontal line (dashed)
addOutput(yytext);
}
<Comment>{CMD}"---" { // escaped mdash
addOutput(yytext);
}
<Comment>{CMD}"--" { // escaped mdash
addOutput(yytext);
}
<Comment>"---" { // mdash
addOutput(insidePre || Doxygen::markdownSupport ? yytext : "&mdash;");
}
Expand Down
29 changes: 29 additions & 0 deletions src/docparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,15 @@ static bool defaultHandleToken(DocNode *parent,int tok, QList<DocNode> &children
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;
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/docparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/doctokenizer.l
Original file line number Diff line number Diff line change
Expand Up @@ -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}"::"
Expand Down
3 changes: 2 additions & 1 deletion src/htmlentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ static struct htmlEntityInfo
{ SYM(DoubleColon), "::", "::", "::", "::", "::", "::", "::", { "::", DocSymbol::Perl_string }},
{ SYM(Percent), "%", "%", "%", "%", "\\%", "%", "%", { "%", DocSymbol::Perl_char }},
{ SYM(Pipe), "|", "|", "|", "|", "$|$", "|", "|", { "|", DocSymbol::Perl_char }},
{ SYM(Quot), "\"", "\"", "\"", "&quot;", "\"", "\"", "\"", { "\"", DocSymbol::Perl_char }}
{ SYM(Quot), "\"", "\"", "\"", "&quot;", "\"", "\"", "\"", { "\"", DocSymbol::Perl_char }},
{ SYM(Minus), "-", "-", "-", "-", "-\\/", "-", "-", { "-", DocSymbol::Perl_char }}
};

static const int g_numHtmlEntities = (int)(sizeof(g_htmlEntities)/ sizeof(*g_htmlEntities));
Expand Down
10 changes: 10 additions & 0 deletions src/markdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 385b87e

Please sign in to comment.