Fixed square brackets processing
This commit is contained in:
parent
c978b2a777
commit
521bed1d55
@ -217,41 +217,40 @@ int process_md(article_info article, char **out)
|
|||||||
while (buff[i + 2 + n] != ']')
|
while (buff[i + 2 + n] != ']')
|
||||||
n++;
|
n++;
|
||||||
|
|
||||||
if (buff[i + 2 + n + 1] != '(')
|
if (buff[i + 2 + n + 1] == '(') {
|
||||||
continue;
|
int k = 0;
|
||||||
|
while (buff[i + 2 + n + 2 + k] != ')')
|
||||||
|
k++;
|
||||||
|
|
||||||
int k = 0;
|
char *internal_text = malloc(n + 1);
|
||||||
while (buff[i + 2 + n + 2 + k] != ')')
|
memcpy(internal_text, buff + i + 2, n);
|
||||||
k++;
|
internal_text[n] = '\0';
|
||||||
|
|
||||||
char *internal_text = malloc(n + 1);
|
char *src = malloc(k + 1);
|
||||||
memcpy(internal_text, buff + i + 2, n);
|
memcpy(src, buff + i + 2 + n + 2, k);
|
||||||
internal_text[n] = '\0';
|
src[k] = '\0';
|
||||||
|
|
||||||
char *src = malloc(k + 1);
|
size_t append_line_length = snprintf(NULL, 0, "<a href=\"%s\"><img src=\"%s\" alt=\"%s\"></a>", src, src, internal_text) + 1;
|
||||||
memcpy(src, buff + i + 2 + n + 2, k);
|
char *append = malloc(append_line_length);
|
||||||
src[k] = '\0';
|
char *tmp_out = realloc(*out, strlen(*out) + append_line_length);
|
||||||
|
if (append == NULL || tmp_out == NULL)
|
||||||
|
{
|
||||||
|
perror("Couldn't allocate memory for new element");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
*out = tmp_out;
|
||||||
|
|
||||||
|
snprintf(append, append_line_length, "<a href=\"%s\"><img src=\"%s\" alt=\"%s\"></a>", src, src, internal_text);
|
||||||
|
strcat(*out, append);
|
||||||
|
|
||||||
|
i += 2 + n + 2 + k;
|
||||||
|
|
||||||
|
free(append);
|
||||||
|
free(src);
|
||||||
|
free(internal_text);
|
||||||
|
|
||||||
size_t append_line_length = snprintf(NULL, 0, "<a href=\"%s\"><img src=\"%s\" alt=\"%s\"></a>", src, src, internal_text) + 1;
|
|
||||||
char *append = malloc(append_line_length);
|
|
||||||
char *tmp_out = realloc(*out, strlen(*out) + append_line_length);
|
|
||||||
if (append == NULL || tmp_out == NULL)
|
|
||||||
{
|
|
||||||
perror("Couldn't allocate memory for new element");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
*out = tmp_out;
|
|
||||||
|
|
||||||
snprintf(append, append_line_length, "<a href=\"%s\"><img src=\"%s\" alt=\"%s\"></a>", src, src, internal_text);
|
|
||||||
strcat(*out, append);
|
|
||||||
|
|
||||||
i += 2 + n + 2 + k;
|
|
||||||
|
|
||||||
free(append);
|
|
||||||
free(src);
|
|
||||||
free(internal_text);
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buff[i] == '[')
|
if (buff[i] == '[')
|
||||||
@ -260,41 +259,40 @@ int process_md(article_info article, char **out)
|
|||||||
while (buff[i + 1 + n] != ']')
|
while (buff[i + 1 + n] != ']')
|
||||||
n++;
|
n++;
|
||||||
|
|
||||||
if (buff[i + 1 + n + 1] != '(')
|
if (buff[i + 1 + n + 1] == '(') {
|
||||||
continue;
|
int k = 0;
|
||||||
|
while (buff[i + 1 + n + 2 + k] != ')')
|
||||||
|
k++;
|
||||||
|
|
||||||
int k = 0;
|
char *internal_text = malloc(n + 1);
|
||||||
while (buff[i + 1 + n + 2 + k] != ')')
|
memcpy(internal_text, buff + i + 1, n);
|
||||||
k++;
|
internal_text[n] = '\0';
|
||||||
|
|
||||||
char *internal_text = malloc(n + 1);
|
char *href = malloc(k + 1);
|
||||||
memcpy(internal_text, buff + i + 1, n);
|
memcpy(href, buff + i + 1 + n + 2, k);
|
||||||
internal_text[n] = '\0';
|
href[k] = '\0';
|
||||||
|
|
||||||
char *href = malloc(k + 1);
|
size_t append_line_length = snprintf(NULL, 0, "<a href=\"%s\">%s</a>", href, internal_text) + 1;
|
||||||
memcpy(href, buff + i + 1 + n + 2, k);
|
char *append = malloc(append_line_length);
|
||||||
href[k] = '\0';
|
char *tmp_out = realloc(*out, strlen(*out) + append_line_length);
|
||||||
|
if (append == NULL || tmp_out == NULL)
|
||||||
|
{
|
||||||
|
perror("Couldn't allocate memory for new element");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
*out = tmp_out;
|
||||||
|
|
||||||
|
snprintf(append, append_line_length, "<a href=\"%s\">%s</a>", href, internal_text);
|
||||||
|
strcat(*out, append);
|
||||||
|
|
||||||
|
i += 1 + n + 2 + k;
|
||||||
|
|
||||||
|
free(append);
|
||||||
|
free(href);
|
||||||
|
free(internal_text);
|
||||||
|
|
||||||
size_t append_line_length = snprintf(NULL, 0, "<a href=\"%s\">%s</a>", href, internal_text) + 1;
|
|
||||||
char *append = malloc(append_line_length);
|
|
||||||
char *tmp_out = realloc(*out, strlen(*out) + append_line_length);
|
|
||||||
if (append == NULL || tmp_out == NULL)
|
|
||||||
{
|
|
||||||
perror("Couldn't allocate memory for new element");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
*out = tmp_out;
|
|
||||||
|
|
||||||
snprintf(append, append_line_length, "<a href=\"%s\">%s</a>", href, internal_text);
|
|
||||||
strcat(*out, append);
|
|
||||||
|
|
||||||
i += 1 + n + 2 + k;
|
|
||||||
|
|
||||||
free(append);
|
|
||||||
free(href);
|
|
||||||
free(internal_text);
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t len = strlen(*out);
|
size_t len = strlen(*out);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user