preview: preserve minimum indentation when htmlizing plain/text with <br> tags

This commit is contained in:
Jean-Francois Dockes 2011-06-22 16:10:32 +02:00
parent ce44c0a875
commit 860da987b7

View File

@ -361,10 +361,11 @@ bool PlainToRich::plaintorich(const string& in,
// Input character iterator // Input character iterator
Utf8Iter chariter(in); Utf8Iter chariter(in);
// State variable used to limit the number of consecutive empty lines, // State variables used to limit the number of consecutive empty lines,
// and convert all eol to '\n' // convert all eol to '\n', and preserve some indentation
int eol = 0; int eol = 0;
int hadcr = 0; int hadcr = 0;
int inindent = 1;
// Value for numbered anchors at each term match // Value for numbered anchors at each term match
int anchoridx = 1; int anchoridx = 1;
@ -425,7 +426,8 @@ bool PlainToRich::plaintorich(const string& in,
eol++; eol++;
continue; continue;
} else if (eol) { } else if (eol) {
// Do line break; // Got non eol char in line break state. Do line break;
inindent = 1;
hadcr = 0; hadcr = 0;
if (eol > 2) if (eol > 2)
eol = 2; eol = 2;
@ -447,6 +449,7 @@ bool PlainToRich::plaintorich(const string& in,
switch (car) { switch (car) {
case '<': case '<':
inindent = 0;
if (m_inputhtml) { if (m_inputhtml) {
if (!inparamvalue) if (!inparamvalue)
intag = true; intag = true;
@ -456,6 +459,7 @@ bool PlainToRich::plaintorich(const string& in,
} }
break; break;
case '>': case '>':
inindent = 0;
if (m_inputhtml) { if (m_inputhtml) {
if (!inparamvalue) if (!inparamvalue)
intag = false; intag = false;
@ -463,6 +467,7 @@ bool PlainToRich::plaintorich(const string& in,
chariter.appendchartostring(*olit); chariter.appendchartostring(*olit);
break; break;
case '&': case '&':
inindent = 0;
if (m_inputhtml) { if (m_inputhtml) {
chariter.appendchartostring(*olit); chariter.appendchartostring(*olit);
} else { } else {
@ -470,12 +475,30 @@ bool PlainToRich::plaintorich(const string& in,
} }
break; break;
case '"': case '"':
inindent = 0;
if (m_inputhtml && intag) { if (m_inputhtml && intag) {
inparamvalue = !inparamvalue; inparamvalue = !inparamvalue;
} }
chariter.appendchartostring(*olit); chariter.appendchartostring(*olit);
break; break;
case ' ':
if (m_eolbr && inindent) {
*olit += "&nbsp;";
} else {
chariter.appendchartostring(*olit);
}
break;
case '\t':
if (m_eolbr && inindent) {
*olit += "&nbsp;&nbsp;&nbsp;&nbsp;";
} else {
chariter.appendchartostring(*olit);
}
break;
default: default:
inindent = 0;
chariter.appendchartostring(*olit); chariter.appendchartostring(*olit);
} }