32 htmlFileNode.AssembleRealPath(path, lang::Inclusion::Include);
41 Lox_Info(
"Reading HTML file: {}", path )
44 if(errc != std::errc()) {
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;
78 while (!mfc.
IsEOF()) {
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=\"" );
127 if ( fileName.
IsNotEmpty() ) writeBuffer._<
NC>( fileName );
128 if ( anchor.
IsNotEmpty() ) writeBuffer._<
NC>(
'#' )._<NC>( anchor );
129 writeBuffer._<
NC>(
'\"' );
130 wb= writeBuffer.VBuffer() + writeBuffer.Length();
132 if (isElAnchor) ++cntELReplacements;
133 else ++cntELRefReplacements;
141 if (c !=
'#') { *wb++= c;
continue; }
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>(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 )
215 bool illegalHTMLEntity= ( linkString.
CharAt(suppressedAnchor ? 1 : 0) ==
'&'
216 && ( ( suppressedAnchor && !linkString.
StartsWith(
"%<"))
217 || (!suppressedAnchor && !linkString.
StartsWith(
"<")) ) ) ;
218 if ( !foundEnd || illegalHTMLEntity ) {
221 for (
auto lsC : linkString )
223 if ( !illegalHTMLEntity) {
225 Lox_Warning(
"Found unterminated XLink pattern {!Q} in HTML file {}:{}:{}",
226 linkString, path, lineNo -1, colNo )
231 if (suppressedAnchor)
237 if (verbosity >= Verbosity::Info)
238 Lox_Info(
"Found XLink pattern {!Q} in HTML file {}:{}:{}",
239 linkString, path, lineNo, colNo )
247 ALIB_ASSERT_ERROR(wb - writeBufferStart < writeBuffer.Capacity(),
"DXL/HTML/JOB",
248 "Write buffer overflow detected" )
249 writeBuffer.SetLength(wb - writeBufferStart);
254 writeBuffer._<
NC>(
"#")._<NC>(
"\"");
255 if ( suppressedAnchor )
256 writeBuffer._<
NC>(
"%");
257 writeBuffer._<
NC>(linkString)._<NC>(
"\"");
263 ALIB_ASSERT_ERROR(css.Size(),
"DXL/HTML/JOB",
"No styles given for XLink {}", linkString )
266 if (!suppressedAnchor) {
267 writeBuffer._<
NC>(
"<a class=\"" );
268 for (
int i= 0; i < css.Size(); ++i )
269 writeBuffer._<
NC>( css.Get(i) )._<
NC>(
' ' );
270 writeBuffer.DeleteEnd(1);
271 writeBuffer._<
NC>(
"\" href=\"" )
277 writeBuffer._<
NC>(
"\">" )
283 writeBuffer._<
NC>( css.IsCodeEntity() ?
"<code" :
"<span" );
284 writeBuffer._<
NC>(
" class=\"" );
285 for (
int i= 1; i < css.Size(); ++i )
286 writeBuffer._<
NC>( css.Get(i) )._<
NC>(
' ' );
287 writeBuffer.DeleteEnd(1);
288 writeBuffer._<
NC>(
"\">" );
290 ._<NC>( css.IsCodeEntity() ?
"</code>" :
"</span>" );
292 wb= writeBuffer.VBuffer() + writeBuffer.Length();
296 dxl.Stats.HTMLFileLines.fetch_add(lineNo);
297 dxl.Stats.ELReplacements .fetch_add(cntELReplacements);
298 dxl.Stats.ELREFReplacements.fetch_add(cntELRefReplacements);
301 if ( fileChanged && !
app.dryrun) {
305 tempPath << path <<
".tmp";
307 if ( !outFile.is_open() ) {
312 ALIB_ASSERT_ERROR(wb - writeBufferStart < writeBuffer.Capacity(),
"DXL/HTML/JOB",
313 "Write buffer overflow detected" )
314 outFile.write(writeBuffer.Buffer() + writeBufferPadSize, wb - writeBufferStart - writeBufferPadSize);
317 if ( outFile.fail() ) {
325 std::filesystem::rename(tempPath.
Terminate(), path.Terminate(), ec);
326 if ( ec.value() != 0 ) {