ext/mmd/html.c in rmultimarkdown-6.2.2.1 vs ext/mmd/html.c in rmultimarkdown-6.4.0.1
- old
+ new
@@ -111,10 +111,15 @@
case '>':
print_const(">");
break;
+ case '\n':
+ case '\r':
+ print_const("<br/>\n");
+ break;
+
default:
if (obfuscate && ((int) c == (((int) c) & 127))) {
if (ran_num_next() % 2 == 0) {
printf("&#%d;", (int) c);
} else {
@@ -207,10 +212,11 @@
case GERMANGUILL:
print_const("»");
break;
case FRENCH:
+ case SPANISH:
print_const("«");
break;
case SWEDISH:
print( "”");
@@ -231,10 +237,11 @@
case GERMANGUILL:
print_const("«");
break;
case FRENCH:
+ case SPANISH:
print_const("»");
break;
case SWEDISH:
case DUTCH:
@@ -255,15 +262,10 @@
for (i = 0; result[i]; i++) {
result[i] = tolower(result[i]);
}
- if (strstr(&result[strlen(result) - 2], "px")) {
- // Leave 'px' alone
- return result;
- }
-
// Trim anything other than digits
for (i = 0; result[i]; i++) {
if (result[i] < '0' || result[i] > '9') {
result[i] = '\0';
return result;
@@ -369,10 +371,16 @@
while (a) {
if (strcmp(a->key, "width") == 0) {
width = strip_dimension_units(a->value);
+ if (strlen(width) + 2 == strlen(a->value)) {
+ if (strcmp(&(a->value[strlen(width)]), "px") == 0) {
+ a->value[strlen(width)] = '\0';
+ }
+ }
+
if (strcmp(a->value, width) == 0) {
print_const(" ");
print(a->key);
print_const("=\"");
print(a->value);
@@ -384,10 +392,16 @@
width = a->value;
}
} else if (strcmp(a->key, "height") == 0) {
height = strip_dimension_units(a->value);
+ if (strlen(height) + 2 == strlen(a->value)) {
+ if (strcmp(&(a->value[strlen(height)]), "px") == 0) {
+ a->value[strlen(height)] = '\0';
+ }
+ }
+
if (strcmp(a->value, height) == 0) {
print_const(" ");
print(a->key);
print_const("=\"");
print(a->value);
@@ -671,10 +685,12 @@
printf("<h%1d id=\"%s\">", temp_short + scratch->base_header_level - 1, temp_char);
free(temp_char);
}
mmd_export_token_tree_html(out, source, t->child, scratch);
+ trim_trailing_whitespace_d_string(out);
+
printf("</h%1d>", temp_short + scratch->base_header_level - 1);
scratch->padded = 0;
break;
case BLOCK_HR:
@@ -881,11 +897,11 @@
// Are we followed by a caption?
if (table_has_caption(t)) {
temp_token = t->next->child;
if (temp_token->next &&
- temp_token->next->type == PAIR_BRACKET) {
+ temp_token->next->type == PAIR_BRACKET) {
temp_token = temp_token->next;
}
temp_char = label_from_token(source, temp_token);
printf("<caption style=\"caption-side: bottom;\" id=\"%s\">", temp_char);
@@ -1123,11 +1139,11 @@
print_const("=");
break;
case ESCAPED_CHARACTER:
if (!(scratch->extensions & EXT_COMPATIBILITY) &&
- (source[t->start + 1] == ' ')) {
+ (source[t->start + 1] == ' ')) {
print_const(" ");
} else {
mmd_print_char_html(out, source[t->start + 1], false);
}
@@ -1342,11 +1358,11 @@
mmd_export_token_tree_html(out, source, t->child, scratch);
break;
case PAIR_BRACKET:
if ((scratch->extensions & EXT_NOTES) &&
- (t->next && t->next->type == PAIR_BRACKET_CITATION)) {
+ (t->next && t->next->type == PAIR_BRACKET_CITATION)) {
goto parse_citation;
}
case PAIR_BRACKET_IMAGE:
parse_brackets(source, scratch, t, &temp_link, &temp_short, &temp_bool);
@@ -1358,12 +1374,12 @@
} else {
// Image -- should it be a figure (e.g. image is only thing in paragraph)?
temp_token = t->next;
if (temp_token &&
- ((temp_token->type == PAIR_BRACKET) ||
- (temp_token->type == PAIR_PAREN))) {
+ ((temp_token->type == PAIR_BRACKET) ||
+ (temp_token->type == PAIR_PAREN))) {
temp_token = temp_token->next;
}
if (temp_token && temp_token->type == TEXT_NL) {
temp_token = temp_token->next;
@@ -1517,27 +1533,27 @@
// No locator
if (temp_short2 == scratch->used_citations->size) {
// This is a re-use of a previously used note
printf("<a href=\"#cn:%d\" title=\"%s\" class=\"citation\">(%d)</a>",
- temp_short, LC("see citation"), temp_short);
+ temp_short, LC("see citation"), temp_short);
} else {
// This is the first time this note was used
printf("<a href=\"#cn:%d\" id=\"cnref:%d\" title=\"%s\" class=\"citation\">(%d)</a>",
- temp_short, temp_short, LC("see citation"), temp_short);
+ temp_short, temp_short, LC("see citation"), temp_short);
}
} else {
// Locator present
if (temp_short2 == scratch->used_citations->size) {
// This is a re-use of a previously used note
printf("<a href=\"#cn:%d\" title=\"%s\" class=\"citation\">(%s, %d)</a>",
- temp_short, LC("see citation"), temp_char, temp_short);
+ temp_short, LC("see citation"), temp_char, temp_short);
} else {
// This is the first time this note was used
printf("<a href=\"#cn:%d\" id=\"cnref:%d\" title=\"%s\" class=\"citation\">(%s, %d)</a>",
- temp_short, temp_short, LC("see citation"), temp_char, temp_short);
+ temp_short, temp_short, LC("see citation"), temp_char, temp_short);
}
}
} else {
// This is a "nocite"
}
@@ -1580,11 +1596,11 @@
} else {
temp_short3 = temp_short;
}
printf("<a href=\"#fn:%d\" title=\"%s\" class=\"footnote\"><sup>%d</sup></a>",
- temp_short3, LC("see footnote"), temp_short);
+ temp_short3, LC("see footnote"), temp_short);
} else {
// This is the first time this note was used
if (scratch->extensions & EXT_RANDOM_FOOT) {
srand(scratch->random_seed_base + temp_short);
@@ -1592,11 +1608,11 @@
} else {
temp_short3 = temp_short;
}
printf("<a href=\"#fn:%d\" id=\"fnref:%d\" title=\"%s\" class=\"footnote\"><sup>%d</sup></a>",
- temp_short3, temp_short3, LC("see footnote"), temp_short);
+ temp_short3, temp_short3, LC("see footnote"), temp_short);
}
} else {
// Note-based syntax disabled
mmd_export_token_tree_html(out, source, t->child, scratch);
}
@@ -1632,19 +1648,19 @@
if (temp_short2 == scratch->used_glossaries->size) {
// This is a re-use of a previously used note
printf("<a href=\"#gn:%d\" title=\"%s\" class=\"glossary\">",
- temp_short, LC("see glossary"));
+ temp_short, LC("see glossary"));
mmd_print_string_html(out, temp_note->clean_text, false);
print_const("</a>");
} else {
// This is the first time this note was used
printf("<a href=\"#gn:%d\" id=\"gnref:%d\" title=\"%s\" class=\"glossary\">",
- temp_short, temp_short, LC("see glossary"));
+ temp_short, temp_short, LC("see glossary"));
mmd_print_string_html(out, temp_note->clean_text, false);
print_const("</a>");
}
} else {
// Note-based syntax disabled
@@ -1717,11 +1733,11 @@
case PAIR_CRITIC_COM:
// Ignore if we're rejecting or accepting
if ((scratch->extensions & EXT_CRITIC_REJECT) ||
- (scratch->extensions & EXT_CRITIC_ACCEPT)) {
+ (scratch->extensions & EXT_CRITIC_ACCEPT)) {
break;
}
if (scratch->extensions & EXT_CRITIC) {
t->child->type = TEXT_EMPTY;
@@ -1737,11 +1753,11 @@
case PAIR_CRITIC_HI:
// Ignore if we're rejecting or accepting
if ((scratch->extensions & EXT_CRITIC_REJECT) ||
- (scratch->extensions & EXT_CRITIC_ACCEPT)) {
+ (scratch->extensions & EXT_CRITIC_ACCEPT)) {
t->child->type = TEXT_EMPTY;
t->child->mate->type = TEXT_EMPTY;
mmd_export_token_tree_html(out, source, t->child, scratch);
break;
}
@@ -1766,12 +1782,12 @@
print_const(">");
break;
case PAIR_CRITIC_SUB_DEL:
if ((scratch->extensions & EXT_CRITIC) &&
- (t->next) &&
- (t->next->type == PAIR_CRITIC_SUB_ADD)) {
+ (t->next) &&
+ (t->next->type == PAIR_CRITIC_SUB_ADD)) {
t->child->type = TEXT_EMPTY;
t->child->mate->type = TEXT_EMPTY;
if (scratch->extensions & EXT_CRITIC_ACCEPT) {
@@ -1788,12 +1804,12 @@
break;
case PAIR_CRITIC_SUB_ADD:
if ((scratch->extensions & EXT_CRITIC) &&
- (t->prev) &&
- (t->prev->type == PAIR_CRITIC_SUB_DEL)) {
+ (t->prev) &&
+ (t->prev->type == PAIR_CRITIC_SUB_DEL)) {
t->child->type = TEXT_EMPTY;
t->child->mate->type = TEXT_EMPTY;
if (scratch->extensions & EXT_CRITIC_REJECT) {
@@ -2042,10 +2058,12 @@
void mmd_export_token_html_raw(DString * out, const char * source, token * t, scratch_pad * scratch) {
if (t == NULL) {
return;
}
+ char * temp;
+
switch (t->type) {
case BACKTICK:
print_token(t);
break;
@@ -2063,44 +2081,88 @@
case ANGLE_LEFT:
print_const("<");
break;
+ case CRITIC_COM_OPEN:
+ print_const("{>>");
+ break;
+
+ case CRITIC_COM_CLOSE:
+ print_const("<<}");
+ break;
+
+ case CRITIC_SUB_DIV:
+ print_const("~>");
+ break;
+
+ case CRITIC_SUB_DIV_A:
+ print_const("~");
+ break;
+
+ case CRITIC_SUB_DIV_B:
+ print_const(">");
+ break;
+
case ESCAPED_CHARACTER:
print_const("\\");
- mmd_print_char_html(out, source[t->start + 1], false);
+
+ if (t->next && t->next->type == TEXT_EMPTY && source[t->start + 1] == ' ') {
+ } else {
+ mmd_print_char_html(out, source[t->start + 1], false);
+ }
+
break;
+ case HTML_COMMENT_START:
+ print_const("<!--");
+ break;
+
+ case HTML_COMMENT_STOP:
+ print_const("-->");
+ break;
+
case HTML_ENTITY:
print_const("&");
d_string_append_c_array(out, &(source[t->start + 1]), t->len - 1);
break;
+ case MARKER_LIST_BULLET:
+ case MARKER_LIST_ENUMERATOR:
+ print_token(t);
+
+ temp = NULL;
+
+ if (t->next) {
+ temp = (char *) &source[t->next->start];
+ }
+
+ source = (char *) &source[t->start + t->len];
+
+ while (char_is_whitespace(*source) &&
+ ((temp == NULL) ||
+ (source < temp))) {
+ print_char(*source);
+ source++;
+ }
+
+ break;
+
case MATH_BRACKET_OPEN:
print_const("\\\\[");
break;
case MATH_BRACKET_CLOSE:
print_const("\\\\]");
break;
case MATH_DOLLAR_SINGLE:
- if (t->mate) {
- (t->start < t->mate->start) ? ( print_const("\\(") ) : ( print_const("\\)") );
- } else {
- print_const("$");
- }
-
+ print_const("$");
break;
case MATH_DOLLAR_DOUBLE:
- if (t->mate) {
- (t->start < t->mate->start) ? ( print_const("\\[") ) : ( print_const("\\]") );
- } else {
- print_const("$$");
- }
-
+ print_const("$$");
break;
case MATH_PAREN_OPEN:
print_const("\\\\(");
break;
@@ -2165,10 +2227,28 @@
case MATH_BRACKET_CLOSE:
print_const("\\]");
break;
+ case MATH_DOLLAR_SINGLE:
+ if (t->mate) {
+ (t->start < t->mate->start) ? ( print_const("\\(") ) : ( print_const("\\)") );
+ } else {
+ print_const("$");
+ }
+
+ break;
+
+ case MATH_DOLLAR_DOUBLE:
+ if (t->mate) {
+ (t->start < t->mate->start) ? ( print_const("\\[") ) : ( print_const("\\]") );
+ } else {
+ print_const("$$");
+ }
+
+ break;
+
case MATH_PAREN_OPEN:
print_const("\\(");
break;
case MATH_PAREN_CLOSE:
@@ -2246,16 +2326,18 @@
} else if (strcmp(m->key, "htmlheaderlevel") == 0) {
} else if (strcmp(m->key, "language") == 0) {
} else if (strcmp(m->key, "latexbegin") == 0) {
} else if (strcmp(m->key, "latexconfig") == 0) {
} else if (strcmp(m->key, "latexfooter") == 0) {
+ } else if (strcmp(m->key, "latexheader") == 0) {
} else if (strcmp(m->key, "latexheaderlevel") == 0) {
} else if (strcmp(m->key, "latexinput") == 0) {
} else if (strcmp(m->key, "latexleader") == 0) {
} else if (strcmp(m->key, "latexmode") == 0) {
} else if (strcmp(m->key, "mmdfooter") == 0) {
} else if (strcmp(m->key, "mmdheader") == 0) {
+ } else if (strcmp(m->key, "odfheader") == 0) {
} else if (strcmp(m->key, "quoteslanguage") == 0) {
} else if (strcmp(m->key, "title") == 0) {
print_const("\t<title>");
mmd_print_string_html(out, m->value, false);
print_const("</title>\n");
@@ -2276,9 +2358,20 @@
print_const("</head>\n<body>\n\n");
}
void mmd_end_complete_html(DString * out, const char * source, scratch_pad * scratch) {
+ meta * m;
+
+ // Iterate over metadata keys
+
+ for (m = scratch->meta_hash; m != NULL; m = m->hh.next) {
+ if (strcmp(m->key, "htmlfooter") == 0) {
+ print(m->value);
+ print_char('\n');
+ }
+ }
+
print_const("\n\n</body>\n</html>\n");
}
void mmd_export_token_tree_html_raw(DString * out, const char * source, token * t, scratch_pad * scratch) {