diff options
Diffstat (limited to 'src/sisudoc/outputs/io_out/sqlite_collection_db.d')
| -rw-r--r-- | src/sisudoc/outputs/io_out/sqlite_collection_db.d | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/src/sisudoc/outputs/io_out/sqlite_collection_db.d b/src/sisudoc/outputs/io_out/sqlite_collection_db.d index f1556c4..2a7fcd7 100644 --- a/src/sisudoc/outputs/io_out/sqlite_collection_db.d +++ b/src/sisudoc/outputs/io_out/sqlite_collection_db.d @@ -487,14 +487,40 @@ template SQLiteFormatAndLoadObject() { _img_pth = "../../../image/"; } if (_txt.match(rgx.inline_image)) { - _txt = _txt.replaceAll( // TODO bug where image dimensions (w or h) not given & consequently set to 0; should not be used (calculate earlier, abstraction) - rgx.inline_image, - ("$1<img src=\"" - ~ _img_pth - ~ "$3\" width=\"$4\" height=\"$5\" /> $6")); + _txt = replaceAll!(m => + m["pre"].to!string + ~ _img_element(_img_pth ~ m["img"].to!string, m["width"].to!string, + m["height"].to!string, _image_alt(m["post"].to!string)) + ~ " " ~ _image_rest(m["post"].to!string) + )(_txt, rgx.inline_image); } return _txt; } + /+ ↓ the same treatment of an image as the html and epub writers give + it, because this is the html the cgi search renders: the markup's + description is the alt text, and dimensions that are not there are + not written as zeroes. + +/ + string _image_alt(string _post) { + if (auto m = _post.matchFirst(rgx.inline_image_alt)) { + return m["alt"].to!string; + } + return ""; + } + string _image_rest(string _post) { + if (auto m = _post.matchFirst(rgx.inline_image_alt)) { + return m.post.to!string; + } + return _post; + } + string _img_element(string _src, string _w, string _h, string _alt) { + string _dim = (_w == "0" && _h == "0") + ? "" + : " width=\"" ~ _w ~ "\" height=\"" ~ _h ~ "\""; + return "<img src=\"" ~ _src ~ "\"" + ~ " alt=\"" ~ html_special_characters(_alt) ~ "\"" + ~ _dim ~ " />"; + } string inline_links(M,O)( M doc_matters, const O obj, |
