Skip to content

Commit

Permalink
added escape char to captions
Browse files Browse the repository at this point in the history
  • Loading branch information
Mandarancio committed Jun 29, 2018
1 parent 7e252a7 commit 99b5d18
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
4 changes: 2 additions & 2 deletions examples/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facil
| D | E | F |
| G | H | I |

@caption(This is a table.)
@caption(This is a table \(with 3 columns\).)

@/

Expand All @@ -41,7 +41,7 @@ int main(int argc, char** argv)
return 0;
}
```
@caption(This is a simple code.)
@caption(This is a simple code \\\\not a very interesting example....)
@/
ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in
Expand Down
13 changes: 9 additions & 4 deletions src/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ struct hoedown_document {
return lenstr < lenpre ? 0 : strncmp(pre, str, lenpre) == 0;
}


int
is_separator(uint8_t chr)
{
Expand Down Expand Up @@ -1243,10 +1242,12 @@ char_autolink_email(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, si
}
if (startsWith("@caption(", (char*)data))
{

/** skip it **/
size_t i;
for (i=9;data[i] != ')' && data[i] != '\n' && i < size; i++){}
for (i=9; data[i] != '\n' && i < size; i++){
if (data[i] == ')' && data[i-1] != '\\')
break;
}
return i+1;
}
hoedown_buffer *link;
Expand Down Expand Up @@ -2757,7 +2758,9 @@ parse_caption(hoedown_document *doc,
if (!data || size <= 0)
return NULL;
uint32_t i=0;
while (i < size && (data[i] !=')' && data[i] !='\n')){
while (i < size && data[i] !='\n'){
if (data[i] == ')' && (i==0 || data[i-1] != '\\'))
break;
i++;
}
if (i) {
Expand All @@ -2766,6 +2769,8 @@ parse_caption(hoedown_document *doc,
uint8_t * tmp = malloc(sizeof(uint8_t) * (buf->size+1));
tmp[buf->size] = 0;
memcpy(tmp, buf->data, buf->size);
// clean escape chars
tmp = (uint8_t*)clean_string((char*)tmp, buf->size);
hoedown_buffer_free(buf);
return tmp;
}
Expand Down
21 changes: 21 additions & 0 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,24 @@ remove_char(char *source,
}
*i = 0;
}

char*
clean_string (char *string,
size_t size)
{
char* i = string;
char* j = string;
size_t flag = 0;
while(*j != 0)
{
*i = *j++;
if (flag || *i != '\\'){
i++;
flag = 0;
} else{
flag = 1;
}
}
*i = 0;
return string;
}
4 changes: 4 additions & 0 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#ifndef SCIDOWN_UTILS_H
#define SCIDOWN_UTILS_H

#include <string.h>

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -53,6 +55,8 @@ Strings* add_string (Strings *head,

void remove_char (char *source,
char target);
char* clean_string (char *string,
size_t size);

#ifdef __cplusplus
}
Expand Down

0 comments on commit 99b5d18

Please sign in to comment.