Procházet zdrojové kódy

Fix handling of sections headers with equal signs (closes #20)

tags/v0.2
Ben Kurtovic před 12 roky
rodič
revize
11cf5def75
2 změnil soubory, kde provedl 22 přidání a 26 odebrání
  1. +20
    -24
      mwparserfromhell/parser/tokenizer.c
  2. +2
    -2
      mwparserfromhell/parser/tokenizer.py

+ 20
- 24
mwparserfromhell/parser/tokenizer.c Zobrazit soubor

@@ -759,11 +759,10 @@ Tokenizer_parse_heading(Tokenizer* self)
if (BAD_ROUTE) {
RESET_ROUTE();
self->head = reset + best - 1;
char text[best + 1];
for (i = 0; i < best; i++) text[i] = *"=";
text[best] = *"";
if (Tokenizer_write_text_then_stack(self, text))
return -1;
for (i = 0; i < best; i++) {
if (Tokenizer_write_text(self, *"="))
return -1;
}
self->global ^= GL_HEADING;
return 0;
}
@@ -799,13 +798,12 @@ Tokenizer_parse_heading(Tokenizer* self)
Py_DECREF(token);
if (heading->level < best) {
diff = best - heading->level;
char difftext[diff + 1];
for (i = 0; i < diff; i++) difftext[i] = *"=";
difftext[diff] = *"";
if (Tokenizer_write_text_then_stack(self, difftext)) {
Py_DECREF(heading->title);
free(heading);
return -1;
for (i = 0; i < diff; i++) {
if (Tokenizer_write_text(self, *"=")) {
Py_DECREF(heading->title);
free(heading);
return -1;
}
}
}
if (Tokenizer_write_all(self, heading->title)) {
@@ -851,22 +849,20 @@ Tokenizer_handle_heading_end(Tokenizer* self)
RESET_ROUTE();
if (level < best) {
diff = best - level;
char difftext[diff + 1];
for (i = 0; i < diff; i++) difftext[i] = *"=";
difftext[diff] = *"";
if (Tokenizer_write_text_then_stack(self, difftext))
return NULL;
for (i = 0; i < diff; i++) {
if (Tokenizer_write_text(self, *"="))
return NULL;
}
}
self->head = reset + best - 1;
}
else {
char text[best + 1];
for (i = 0; i < best; i++) text[i] = *"=";
text[best] = *"";
if (Tokenizer_write_text_then_stack(self, text)) {
Py_DECREF(after->title);
free(after);
return NULL;
for (i = 0; i < best; i++) {
if (Tokenizer_write_text(self, *"=")) {
Py_DECREF(after->title);
free(after);
return NULL;
}
}
if (Tokenizer_write_all(self, after->title)) {
Py_DECREF(after->title);


+ 2
- 2
mwparserfromhell/parser/tokenizer.py Zobrazit soubor

@@ -339,14 +339,14 @@ class Tokenizer(object):
current = int(log(self._context / contexts.HEADING_LEVEL_1, 2)) + 1
level = min(current, min(best, 6))

try:
try: # Try to check for a heading closure after this one
after, after_level = self._parse(self._context)
except BadRoute:
if level < best:
self._write_text("=" * (best - level))
self._head = reset + best - 1
return self._pop(), level
else:
else: # Found another closure
self._write_text("=" * best)
self._write_all(after)
return self._pop(), after_level


Načítá se…
Zrušit
Uložit