Literal @c, @source_listing with :marker, and a large-directory speedup

Three changes.

@c now takes its content literally, like @code -- it is the inline form
and @code the block form of the same thing.  The named close "c@" is
required, and characters that are special in a target no longer break
the file: @c a_b c@ renders correctly everywhere.  The Markdown
converter stops quoting inline code, since nothing needs protecting.

@source_file is renamed @source_listing.  Code read from a file is its
own klammer; @code is only for a block written inline (its never-
implemented :filename and :pattern options are removed).  The new
:marker P option lists the region between two lines that are exactly
//P, so the source file declares its own extractable regions.  A marker
missing or not appearing exactly twice is an error, never a fallback.

Rendering a document that sits in a large directory was paying a
recursive walk of that directory's whole tree on every @eval -- 27
seconds for a document that renders in a third of one.  The walk is now
a non-recursive look decided once per directory.

Assembled from dev commit 071b1b183de4.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-16 16:58:50 +02:00
parent 8b38a34841
commit bd39d9a369
8 changed files with 284 additions and 47 deletions

View File

@@ -322,9 +322,46 @@ void Machine::mark_literal_klammer_content(katom_list& katoms)
if (literal_names.empty()) return;
// Scan for matching @name ... name@ spans.
// Stop at ## (ignore-rest) since everything after it will be removed.
//
// REMOVED TEXT IS SKIPPED. This pass runs first in process_katoms(), before
// mark_ignored_katoms() takes out the "#" forms, and that ordering is not
// accidental: a literal klammer's content must be marked before anything
// else can interpret what is inside it, or removal would take a "#" that
// belongs to the literal body. The cost is that this scan sees text the
// writer has removed, so a literal klammer merely NAMED in a comment --
//
// # @image and @code share the same arguments.
//
// -- was found as an opening delimiter, went unclosed, and failed the whole
// file (TODO #40, diagnosed 2026-08-05). "##" was already handled, which is
// half the case; the fix is to teach the scan the other three removal forms
// rather than to reorder the passes.
//
// The converse still holds, structurally: this skipping happens only while
// looking for an OPENING delimiter, and finding one jumps k past the whole
// span, so a "#" inside literal content is never examined here and stays
// content.
for (auto k = katoms.begin(); k != katoms.end(); ++k) {
if (k->m_type == katom_t::ignore_rest) break;
if (k->m_type == katom_t::ignore_rest) break; // "##": rest of the file
if (k->m_type == katom_t::ignore_line) { // "#": rest of the line
while (k + 1 != katoms.end() && (k + 1)->m_type != katom_t::newline) {
++k;
}
continue;
}
if (k->m_type == katom_t::ignore_begin) { // "#[ ... ]#", nestable
int removed = 1;
while (++k != katoms.end() && removed > 0) {
if (k->m_type == katom_t::ignore_begin) {
++removed;
} else if (k->m_type == katom_t::ignore_end) {
--removed;
}
}
if (k == katoms.end()) break; // unterminated: the rest is removed
--k; // the loop's ++k steps past the "]#"
continue;
}
if (k->m_type != katom_t::apply_begin) continue;
std::string name = trim_char(k->m_text, '@');
if (literal_names.count(name) == 0) continue;