From 6835275408e1629f450d163e0cc5221c977e87d2 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sun, 13 Sep 2026 20:53:26 -0400 Subject: epub and html: no errors left over the sample set epubcheck 5.3.0 over the 35 sample epubs went from 1302 remaining errors to none. The six causes for those remaining errors fixed here. most of the count was one of them: - Tables (1123 errors, 86%) where the writer emitted obsolete attributes, removed in 2014; table also now in div instead of a paragraph. also fixed: - Navigation (115). Every level 4 heading's nav entry ended "#0", the ocn of an object that has no ocn and so no id. - Duplicate ids (37). (from three unrelated sources). - The publication identifier (27 warnings). dc:identifier was a hardcoded hex string, not a UUID, and the same one in all 35 files, so two documents in one library collided. It is now UUID v5 over the document's own uid: a real RFC 4122 identifier, stable across builds and distinct per document. - Image manifest entries (15). media-type was "image/" plus the file extension, giving "image/jpg", which is not a media type; epubcheck reads it as a foreign resource and wants a fallback. There is now a mapping, which also covers svg and webp. Item ids came from the file basename, and "2bits_02_01-100.png" gave an id starting with a digit, which is not an XML name; ids are now prefixed and sanitised. - An ocn resolving to no segment (9). A poem block and its first verse share one ocn; the verses are written into a segment and the block itself is not. Also dropped from the package document: an xmlns:xsi that nothing used, and a prefix declaration for the rendition vocabulary, which is a reserved prefix and needed no declaring. The package now carries xml:lang. test-epub-validity.sh now allows no fatal and no error. Two NAV-011 warnings remain and are described in it. Three reference .ssp files change, all of them the anchor tag disambiguation above. (assisted by Claude-Code) --- src/sisudoc/outputs/io_out/xmls.d | 91 +++++++++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 28 deletions(-) (limited to 'src/sisudoc/outputs/io_out/xmls.d') diff --git a/src/sisudoc/outputs/io_out/xmls.d b/src/sisudoc/outputs/io_out/xmls.d index 097ce44..c1e733e 100644 --- a/src/sisudoc/outputs/io_out/xmls.d +++ b/src/sisudoc/outputs/io_out/xmls.d @@ -205,6 +205,17 @@ template outputXHTMLs() { .replaceAll(rgx.inline_cite, ("$1")); return _txt; } + /+ ↓ the heading element for a markup level. + Markup goes to level 7; HTML stops at h6, and an is simply + not an element, so the deepest three markup levels share h6 and + are told apart by the "heading" class and their ocn. Level 0 is + the document title, which is h1 in a segment of its own. + +/ + int _heading_element_level(O)(O obj, string _xml_type) { + int _lev = obj.metainfo.heading_lev_markup.to!int; + if (_xml_type == "epub" && _lev == 0) { return 1; } + return (_lev > 6) ? 6 : _lev; + } string _xhtml_anchor_tags(O)(O obj) { string tags=""; if (obj.tags.anchor_tags.length > 0) { @@ -495,13 +506,13 @@ string tail(M)(M doc_matters) { string o; o = format(q"┃
-
%s
-

+

@@ -579,7 +590,9 @@ string tail(M)(M doc_matters) { if (_xml_type == "seg" || _xml_type == "epub") { seg_lvs = (_xml_type == "epub") ? "seg_lv1to4" : "seg_lv4"; foreach (m; _txt.match(rgx.inline_link_hash)) { - if (m.captures["hash"] in doc_matters.has.tag_associations) { + if ((m.captures["hash"] in doc_matters.has.tag_associations) + && (seg_lvs in doc_matters.has.tag_associations[(m.captures["hash"])]) + ) { if ( m.captures["hash"] == doc_matters.has.tag_associations[(m.captures["hash"])][seg_lvs] @@ -928,15 +941,13 @@ string tail(M)(M doc_matters) { (doc_matters.opt.action.ocn_off) ? "" : ((obj.metainfo.object_number.empty) ? "" : obj.metainfo.identifier), - ((_xml_type == "epub" && obj.metainfo.heading_lev_markup == 0) ? 1 - : obj.metainfo.heading_lev_markup), + _heading_element_level(obj, _xml_type), obj.metainfo.is_a, obj.metainfo.identifier, tags, heading_lev_anchor_tag, _txt, - ((_xml_type == "epub" && obj.metainfo.heading_lev_markup == 0) ? 1 - : obj.metainfo.heading_lev_markup), + _heading_element_level(obj, _xml_type), ); } else { o ~= format(q"┃%s @@ -946,14 +957,12 @@ string tail(M)(M doc_matters) { ┃", _horizontal_rule, - ((_xml_type == "epub" && obj.metainfo.heading_lev_markup == 0) ? 1 - : obj.metainfo.heading_lev_markup), + _heading_element_level(obj, _xml_type), obj.metainfo.is_a, tags, heading_lev_anchor_tag, _txt, - ((_xml_type == "epub" && obj.metainfo.heading_lev_markup == 0) ? 1 - : obj.metainfo.heading_lev_markup), + _heading_element_level(obj, _xml_type), ); } return o; @@ -1316,6 +1325,17 @@ string tail(M)(M doc_matters) { ); return u; } + /+ ↓ column widths as a , not a width attribute on every cell +/ + string _table_colgroup(O)(const O obj) { + if (obj.table.column_widths.length == 0) { return ""; } + string _cols; + foreach(w; obj.table.column_widths) { + _cols ~= (w > 0) + ? "" + : ""; + } + return "" ~ _cols ~ ""; + } Tuple!(string, string) tablarize(O)( string _txt, const O obj, @@ -1324,27 +1344,42 @@ string tail(M)(M doc_matters) { string[] _table_cols; string _table; string _tablenote; + bool _in_head = false; + bool _in_body = false; foreach(row_idx, row; _table_rows) { _table_cols = row.split(rgx.table_delimiter_col); + if ((_table_cols.length == 1) + && (_table_rows.length <= row_idx+2)) { + _tablenote ~= _table_cols[0]; + continue; + } + /+ ↓ a heading row goes in , the rest in +/ + if (row_idx == 0 && obj.table.heading) { + _table ~= ""; + _in_head = true; + } else if (!_in_body) { + if (_in_head) { _table ~= ""; _in_head = false; } + _table ~= ""; + _in_body = true; + } _table ~= ""; foreach(col_idx, cell; _table_cols) { - if ((_table_cols.length == 1) - && (_table_rows.length <= row_idx+2)) { - _tablenote ~= cell; - } else { - string _col_is = (row_idx == 0 && obj.table.heading) ? "th" : "td"; - string _align = ("style=\"text-align:" - ~ ((obj.table.column_aligns[col_idx] == "l") - ? "left\"" : "right\"")); - _table ~= "<" ~ _col_is ~ " width=\"" ~ obj.table.column_widths[col_idx].to!string ~ "%\" " ~ _align ~ ">"; - _table ~= cell; - _table ~= ""; - } + bool _is_th = (row_idx == 0 && obj.table.heading); + string _col_is = _is_th ? "th" : "td"; + string _class = (col_idx < obj.table.column_aligns.length + && obj.table.column_aligns[col_idx] == "l") ? "left" : "right"; + _table ~= "<" ~ _col_is + ~ (_is_th ? " scope=\"col\"" : "") + ~ " class=\"" ~ _class ~ "\">"; + _table ~= cell; + _table ~= ""; } _table ~= ""; } + if (_in_head) { _table ~= ""; } + else if (_in_body) { _table ~= ""; } Tuple!(string, string) t = tuple( - _table, + (_table_colgroup(obj) ~ _table), _tablenote, ); return t; @@ -1366,12 +1401,12 @@ string tail(M)(M doc_matters) { string o; o = format(q"┃
-

%s - +
%s +
%s
%s -

+
┃", obj.metainfo.object_number, (doc_matters.opt.action.ocn_off) ? "" : ((obj.metainfo.object_number.empty) ? "" : obj.metainfo.identifier), @@ -1379,7 +1414,7 @@ string tail(M)(M doc_matters) { obj.metainfo.object_number, tags, _txt, - _note + (_note.strip.empty) ? "" : ("

" ~ _note.strip ~ "

") ); return o; } -- cgit v1.2.3