Sync up more markdown bug fixes from upstream.

This commit is contained in:
Michael Sweet 2017-05-01 09:48:15 -04:00
parent 3bb60cc92b
commit 1146488efb

121
mmd.c
View File

@ -695,7 +695,7 @@ mmd_parse_inline(mmd_t *parent, /* I - Parent node */
for (lineptr = line, text = NULL, type = MMD_TYPE_NORMAL_TEXT; *lineptr; lineptr ++)
{
if (isspace(*lineptr & 255))
if (isspace(*lineptr & 255) && type != MMD_TYPE_CODE_TEXT)
{
if (text)
{
@ -706,23 +706,20 @@ mmd_parse_inline(mmd_t *parent, /* I - Parent node */
whitespace = 1;
}
else if (!text)
{
if (*lineptr == '\\' && lineptr[1])
{
/*
* Escaped character...
*/
lineptr ++;
text = lineptr;
}
else if (*lineptr == '!' && lineptr[1] == '[')
{
/*
* Image...
*/
if (text)
{
mmd_add(parent, type, whitespace, text, NULL);
text = NULL;
whitespace = 0;
}
lineptr = mmd_parse_link(lineptr + 1, &text, &url);
if (url)
@ -741,6 +738,14 @@ mmd_parse_inline(mmd_t *parent, /* I - Parent node */
* Link...
*/
if (text)
{
mmd_add(parent, type, whitespace, text, NULL);
text = NULL;
whitespace = 0;
}
lineptr = mmd_parse_link(lineptr, &text, &url);
if (text && *text == '`')
@ -769,6 +774,14 @@ mmd_parse_inline(mmd_t *parent, /* I - Parent node */
* Autolink...
*/
if (text)
{
mmd_add(parent, type, whitespace, text, NULL);
text = NULL;
whitespace = 0;
}
url = lineptr + 1;
lineptr = strchr(lineptr + 1, '>');
@ -780,57 +793,75 @@ mmd_parse_inline(mmd_t *parent, /* I - Parent node */
whitespace = 0;
lineptr --;
}
else if (*lineptr == '`')
else if (*lineptr == '*' && type != MMD_TYPE_CODE_TEXT)
{
type = MMD_TYPE_CODE_TEXT;
text = lineptr + 1;
lineptr ++;
if (text)
{
*lineptr = '\0';
mmd_add(parent, type, whitespace, text, NULL);
*lineptr = '*';
text = NULL;
whitespace = 0;
}
else if (*lineptr == '*')
if (type == MMD_TYPE_NORMAL_TEXT)
{
if (lineptr[1] == '*' && !isspace(lineptr[2] & 255))
{
type = MMD_TYPE_STRONG_TEXT;
lineptr += 2;
lineptr ++;
}
else if (!isspace(lineptr[1] & 255))
{
type = MMD_TYPE_EMPHASIZED_TEXT;
lineptr ++;
}
text = lineptr + 1;
}
else
{
if (lineptr[1] == '*')
lineptr ++;
type = MMD_TYPE_NORMAL_TEXT;
}
}
else if (*lineptr == '`')
{
if (text)
{
*lineptr = '\0';
mmd_add(parent, type, whitespace, text, NULL);
if (!*lineptr)
break;
text = NULL;
whitespace = 0;
}
if (type == MMD_TYPE_CODE_TEXT)
{
type = MMD_TYPE_NORMAL_TEXT;
}
else
{
type = MMD_TYPE_CODE_TEXT;
text = lineptr + 1;
}
}
else if (!text)
{
if (*lineptr == '\\' && lineptr[1])
{
/*
* Escaped character...
*/
lineptr ++;
}
text = lineptr;
}
else if (*lineptr == '*' && type != MMD_TYPE_NORMAL_TEXT)
{
*lineptr = '\0';
if (lineptr[1] == '*')
{
lineptr ++;
*lineptr = '\0';
}
mmd_add(parent, type, whitespace, text, NULL);
text = NULL;
whitespace = 0;
type = MMD_TYPE_NORMAL_TEXT;
}
else if (*lineptr == '`' && type == MMD_TYPE_CODE_TEXT)
{
*lineptr = '\0';
mmd_add(parent, type, whitespace, text, NULL);
text = NULL;
whitespace = 0;
type = MMD_TYPE_NORMAL_TEXT;
}
else if (*lineptr == '\\' && lineptr[1])
{
/*