31 htmlFileNode.AssembleRealPath(path, lang::Inclusion::Include);
40 Lox_Info(
"Reading HTML file: {}", path )
45 }
catch (std::exception&) {
56 constexpr integer writeBufferPadSize= 20;
57 writeBuffer.
_(
Fill(0, writeBufferPadSize));
58 char* writeBufferStart= writeBuffer.
VBuffer();
59 char* wb = writeBufferStart + writeBufferPadSize;
64 if (
app.machine.GetExitCode().Integral() )
72 bool fileChanged =
false;
73 int cntELReplacements = 0;
74 int cntELRefReplacements= 0;
77 size_t lineStartRemaining = mfc.
Remaining();
78 while (!mfc.
IsEOF()) {
79 char c= char( mfc.
Next<
NC>() );
82 if (c ==
'\n') { *wb++=
'\n'; lineNo++; lineStartRemaining= mfc.
Remaining();
continue; }
88 if ( isElAnchor || isElRefAnchor ) {
94 if (mfc.
Remaining() < 8) { *wb++=
'\"'; *wb++=
' ';
continue; }
101 && mfc()==
'\"',
"DXL/HTML/JOB")
109 bool isAnchor=
false;
110 while (mfc.
Remaining() && (c= mfc()) !=
'\"') {
111 if (c==
'#') {isAnchor=
true;
continue;}
112 if (!isAnchor) fileName.
_(c);
116 dxl.GetELDecoration( styles, isElRefAnchor,
htmlFileNode, fileName, anchor,
117 lineNo,
int(lineStartRemaining - mfc.
Remaining() - 9) );
121 "DXL/HTML/JOB",
"Write buffer overflow detected" )
122 writeBuffer.
SetLength(wb - writeBufferStart);
124 for (
int i= 1; i < styles.
Size(); ++i )
125 writeBuffer.
_<
NC>(
' ' )._<
NC>( styles.
Get(i) );
126 writeBuffer.
_<
NC>(
"\" href=\"" );
128 if ( anchor.
IsNotEmpty() ) writeBuffer.
_<
NC>(
'#' )._<NC>( anchor );
129 writeBuffer.
_<
NC>(
'\"' );
132 if (isElAnchor) ++cntELReplacements;
133 else ++cntELRefReplacements;
141 if (c !=
'#') { *wb++= c;
continue; }
156 c= char( mfc.
Next<
NC>() );
160 if (c ==
'#' ) { *wb++=
'#';
continue;}
173 if ( !isalpha(c) &&
String(
".%^_&").IndexOf(c) < 0 ) {
182 int colNo= int(lineStartRemaining - mfc.
Remaining() - 2);
185 {
auto exclIt= exclamations.begin();
186 for (; exclIt!=exclamations.end(); ++exclIt )
187 if ( (*exclIt)->Matches(lineNo, colNo ) )
189 if (exclIt != exclamations.end()) {
197 bool suppressedAnchor;
198 linkString.
Reset(c); {
199 bool foundEnd=
false;
202 if ( c ==
'\\') { linkString.
_<
NC>(c); linkString.
_<
NC>(char(mfc.
Next()));
continue; }
203 if ( c ==
'\"') { foundEnd=
true;
break;}
204 if ( c ==
'\n') { lineNo++;
break; }
206 if (linkString.
Length() == 511 ) {
207 Lox_Warning(
"Found unterminated XLink pattern {!Q} in HTML file {}:{}:{}",
208 linkString, path, lineNo, colNo )
216 bool illegalHTMLEntity= ( linkString.
CharAt(suppressedAnchor ? 1 : 0) ==
'&'
217 && ( ( suppressedAnchor && !linkString.
StartsWith(
"%<"))
218 || (!suppressedAnchor && !linkString.
StartsWith(
"<")) ) ) ;
219 if ( !foundEnd || illegalHTMLEntity ) {
222 for (
auto lsC : linkString )
224 if ( !illegalHTMLEntity) {
226 Lox_Warning(
"Found unterminated XLink pattern {!Q} in HTML file {}:{}:{}",
227 linkString, path, lineNo -1, colNo )
232 if (suppressedAnchor)
238 if (verbosity >= Verbosity::Info)
239 Lox_Info(
"Found XLink pattern {!Q} in HTML file {}:{}:{}",
240 linkString, path, lineNo, colNo )
249 "Write buffer overflow detected" )
250 writeBuffer.
SetLength(wb - writeBufferStart);
255 writeBuffer.
_<
NC>(
"#")._<NC>(
"\"");
256 if ( suppressedAnchor )
257 writeBuffer.
_<
NC>(
"%");
258 writeBuffer.
_<
NC>(linkString)._<NC>(
"\"");
264 ALIB_ASSERT_ERROR(css.Size(),
"DXL/HTML/JOB",
"No styles given for XLink {}", linkString )
267 if (!suppressedAnchor) {
268 writeBuffer.
_<
NC>(
"<a class=\"" );
269 for (
int i= 0; i < css.Size(); ++i )
270 writeBuffer.
_<
NC>( css.Get(i) )._<
NC>(
' ' );
272 writeBuffer.
_<
NC>(
"\" href=\"" )
278 writeBuffer.
_<
NC>(
"\">" )
284 writeBuffer.
_<
NC>( css.IsCodeEntity() ?
"<code" :
"<span" );
285 writeBuffer.
_<
NC>(
" class=\"" );
286 for (
int i= 1; i < css.Size(); ++i )
287 writeBuffer.
_<
NC>( css.Get(i) )._<
NC>(
' ' );
289 writeBuffer.
_<
NC>(
"\">" );
291 ._<NC>( css.IsCodeEntity() ?
"</code>" :
"</span>" );
298 dxl.Stats.HTMLFileLines.fetch_add(lineNo);
299 dxl.Stats.ELReplacements .fetch_add(cntELReplacements);
300 dxl.Stats.ELREFReplacements.fetch_add(cntELRefReplacements);
303 if ( fileChanged &&
app.cli.DryRun != cli::DryRunModes::Application) {
307 tempPath << path <<
".tmp";
309 if ( !outFile.is_open() ) {
315 "Write buffer overflow detected" )
316 outFile.write(writeBuffer.
Buffer() + writeBufferPadSize, wb - writeBufferStart - writeBufferPadSize);
319 if ( outFile.fail() ) {
327 std::filesystem::rename(tempPath.
Terminate(), path.Terminate(), ec);
328 if ( ec.value() != 0 ) {