Skip to content

Commit

Permalink
the code highlighter html handling is now a liability; it can double …
Browse files Browse the repository at this point in the history
…encode things and serves no other purpose. I deleted it all.
  • Loading branch information
adamdruppe committed Feb 18, 2012
1 parent 6aa03d5 commit 2dc42a7
Showing 1 changed file with 2 additions and 114 deletions.
116 changes: 2 additions & 114 deletions src/doc.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
struct Escape
{
const char *strings[256];

static const char *escapeChar(unsigned c);
};

struct Section
Expand Down Expand Up @@ -1818,73 +1816,7 @@ void highlightText(Scope *sc, Dsymbol *s, OutBuffer *buf, unsigned offset)
iLineStart = i + 1;
break;

case '<':
leadingBlank = 0;
if (inCode)
break;
p = &buf->data[i];

// Skip over comments
if (p[1] == '!' && p[2] == '-' && p[3] == '-')
{ unsigned j = i + 4;
p += 4;
while (1)
{
if (j == buf->offset)
goto L1;
if (p[0] == '-' && p[1] == '-' && p[2] == '>')
{
i = j + 2; // place on closing '>'
break;
}
j++;
p++;
}
break;
}

// Skip over HTML tag
if (isalpha(p[1]) || (p[1] == '/' && isalpha(p[2])))
{ unsigned j = i + 2;
p += 2;
while (1)
{
if (j == buf->offset)
goto L1;
if (p[0] == '>')
{
i = j; // place on closing '>'
break;
}
j++;
p++;
}
break;
}

L1:
// Replace '<' with '&lt;' character entity
se = Escape::escapeChar('<');
if (se)
{ size_t len = strlen(se);
buf->remove(i, 1);
i = buf->insert(i, se, len);
i--; // point to ';'
}
break;

case '>':
leadingBlank = 0;
if (inCode)
break;
// Replace '>' with '&gt;' character entity
se = Escape::escapeChar('>');
if (se)
{ size_t len = strlen(se);
buf->remove(i, 1);
i = buf->insert(i, se, len);
i--; // point to ';'
}
break;

case '&':
Expand All @@ -1894,14 +1826,6 @@ void highlightText(Scope *sc, Dsymbol *s, OutBuffer *buf, unsigned offset)
p = &buf->data[i];
if (p[1] == '#' || isalpha(p[1]))
break; // already a character entity
// Replace '&' with '&amp;' character entity
se = Escape::escapeChar('&');
if (se)
{ size_t len = strlen(se);
buf->remove(i, 1);
i = buf->insert(i, se, len);
i--; // point to ';'
}
break;

case '-':
Expand Down Expand Up @@ -2044,15 +1968,7 @@ void highlightCode(Scope *sc, Dsymbol *s, OutBuffer *buf, unsigned offset)
{ unsigned char c = buf->data[i];
const char *se;

se = Escape::escapeChar(c);
if (se)
{
size_t len = strlen(se);
buf->remove(i, 1);
i = buf->insert(i, se, len);
i--; // point to ';'
}
else if (isIdStart(&buf->data[i]))
if (isIdStart(&buf->data[i]))
{ unsigned j;

j = skippastident(buf, i);
Expand Down Expand Up @@ -2084,10 +2000,7 @@ void highlightCode(Scope *sc, Dsymbol *s, OutBuffer *buf, unsigned offset)
void highlightCode3(OutBuffer *buf, unsigned char *p, unsigned char *pend)
{
for (; p < pend; p++)
{ const char *s = Escape::escapeChar(*p);
if (s)
buf->writestring(s);
else
{
buf->writeByte(*p);
}
}
Expand Down Expand Up @@ -2163,31 +2076,6 @@ void highlightCode2(Scope *sc, Dsymbol *s, OutBuffer *buf, unsigned offset)
global.errors = errorsave;
}

/***************************************
* Find character string to replace c with.
*/

const char *Escape::escapeChar(unsigned c)
{ const char *s;

switch (c)
{
case '<':
s = "&lt;";
break;
case '>':
s = "&gt;";
break;
case '&':
s = "&amp;";
break;
default:
s = NULL;
break;
}
return s;
}

/****************************************
* Determine if p points to the start of an identifier.
*/
Expand Down

1 comment on commit 2dc42a7

@adamdruppe
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me explain this a little. In the old scheme, D code had to be escaped, and it used a hard-coded table to do it. It also tracked whether we were in html comments or tags.

All of that hardcoded html stuff is unnecessary with the encoding moved to general. If we keep it,


if(a > 0)

is converted to if(a > 0) in the first step..... then re-encoded to if(a &gt; 0) in the second step, which clearly isn't what we wanted.

I tested this on some files with code examples and found nothing broken.

Please sign in to comment.