MCPcopy Create free account
hub / github.com/dail8859/NotepadNext / convertRange

Method convertRange

src/HtmlConverter.cpp:72–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70}
71
72void HtmlConverter::convertRange(QTextStream &stream, int start, int end)
73{
74 ensureDocumentStyled(start, end);
75
76 // Create the raw html and keep track of the used styles
77 QByteArray html;
78 QTextStream html_stream(&html);
79 QSet<int> usedStyles;
80 int currentStyle = -1;
81
82 for (int i = start; i < end; ++i) {
83 int style = editor->styleAt(i);
84
85 if (style != currentStyle) {
86 currentStyle = style;
87 usedStyles.insert(currentStyle);
88
89 html_stream << "</span><span class=\"s" << currentStyle << "\">";
90 }
91
92 const int ch = editor->charAt(i);
93 if (ch == '\r'){
94 if (editor->charAt(i + 1) != '\n') {
95 AddCharEscaped(html_stream, ch);
96 }
97 }
98 else {
99 AddCharEscaped(html_stream, ch);
100 }
101 }
102 html_stream.flush();
103
104
105 // Generate the CSS for just the styles that were used
106 QByteArray css;
107 QTextStream css_stream(&css);
108 for (const int style : usedStyles) {
109 StyleToCss(css_stream, editor, style);
110 }
111 css_stream.flush();
112
113
114 // Generate the entire document
115 stream << "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd\">" << Qt::endl;
116 stream << "<html>" << Qt::endl;
117 stream << "<head>" << Qt::endl;
118 stream << "<meta http-equiv=Content-Type content=\"text/html; charset=UTF-8\">" << Qt::endl;
119 stream << "<title>Exported from Notepad Next</title>" << Qt::endl;
120 stream << "<!--StartFragment-->" << Qt::endl;
121 stream << "<style type=\"text/css\">" << Qt::endl;
122 stream << "div.main {" << Qt::endl;
123 stream << " white-space: pre;" << Qt::endl;
124 stream << " line-height: 1;" << Qt::endl;
125 stream << "}" << Qt::endl;
126 stream << css;
127 stream << "</style>" << Qt::endl;
128 stream << "</head>" << Qt::endl;
129 stream << "<body>" << Qt::endl;

Callers

nothing calls this directly

Calls 2

StyleToCssFunction · 0.85
AddCharEscapedFunction · 0.70

Tested by

no test coverage detected