diff options
Diffstat (limited to 'src/doc_reform/io_in')
-rw-r--r-- | src/doc_reform/io_in/read_source_files.d | 64 |
1 files changed, 39 insertions, 25 deletions
diff --git a/src/doc_reform/io_in/read_source_files.d b/src/doc_reform/io_in/read_source_files.d index bf8702b..ba3e145 100644 --- a/src/doc_reform/io_in/read_source_files.d +++ b/src/doc_reform/io_in/read_source_files.d @@ -15,7 +15,7 @@ static template spineRawMarkupContent() { mixin spineRgxInit; static auto rgx = Rgx(); string[] _images=[]; - auto _extract_images(S)(S content_block) @safe { + string[] _extract_images(S)(S content_block) @safe { string[] images_; string _content_block = content_block.to!string; if (auto m = _content_block.matchAll(rgx.image)) { @@ -24,6 +24,17 @@ static template spineRawMarkupContent() { return images_; } auto rawsrc = RawMarkupContent(); + alias ContentsInsertsImages = Tuple!( + char[][], "contents", + string[], "insert_files", + string[], "images" + ); + alias HeaderContentInsertsImages = Tuple!( + char[], "header", + char[][], "src_txt", + string[], "insert_files", + string[], "images" + ); auto spineRawMarkupContent(O,Fn)(O _opt_action, Fn fn_src) @safe { auto _0_header_1_body_content_2_insert_filelist_tuple = rawsrc.sourceContentSplitIntoHeaderAndBody(_opt_action, rawsrc.sourceContent(fn_src), fn_src); @@ -32,7 +43,7 @@ static template spineRawMarkupContent() { struct RawMarkupContent { final sourceContent(in string fn_src) { auto raw = MarkupRawUnit(); - auto source_txt_str + string source_txt_str = raw.markupSourceReadIn(fn_src); return source_txt_str; } @@ -44,22 +55,22 @@ static template spineRawMarkupContent() { auto raw = MarkupRawUnit(); string[] insert_file_list; string[] images_list; - Tuple!(char[], char[][], string[], string[]) t + HeaderContentInsertsImages t = raw.markupSourceHeaderContentRawLineTupleArray(source_txt_str); - auto header_raw = t[0]; - auto sourcefile_body_content = t[1]; + char[] header_raw = t.header; + char[][] sourcefile_body_content = t.src_txt; if (fn_src.match(rgx.src_fn_master)) { // filename with path needed if master file (.ssm) not otherwise auto ins = Inserts(); - Tuple!(char[][], string[], string[]) tu + ContentsInsertsImages tu = ins.scan_master_src_for_insert_files_and_import_content(_opt_action, sourcefile_body_content, fn_src); - sourcefile_body_content = tu[0]; - insert_file_list = tu[1].dup; - images_list = tu[2].dup; + sourcefile_body_content = tu.contents; + insert_file_list = tu.insert_files.dup; + images_list = tu.images.dup; } else if (_opt_action.source || _opt_action.pod) { auto ins = Inserts(); - Tuple!(char[][], string[], string[]) tu + ContentsInsertsImages tu = ins.scan_master_src_for_insert_files_and_import_content(_opt_action, sourcefile_body_content, fn_src); - images_list = tu[2].dup; + images_list = tu.images.dup; } string header_type = ""; t = tuple( @@ -68,7 +79,6 @@ static template spineRawMarkupContent() { insert_file_list, images_list ); - static assert(t.length==4); return t; } } @@ -115,24 +125,24 @@ static template spineRawMarkupContent() { = (cast(char[]) src_text).split(rgx.newline_eol_strip_preceding); return source_line_arr; } - auto markupSourceReadIn(in string fn_src) { + string markupSourceReadIn(in string fn_src) { static auto rgx = Rgx(); enforce( fn_src.match(rgx.src_pth_sst_or_ssm), "not a dr markup filename: «" ~ fn_src ~ "»" ); - auto source_txt_str = readInMarkupSource(fn_src); + string source_txt_str = readInMarkupSource(fn_src); return source_txt_str; } - Tuple!(char[], char[][], string[], string[]) markupSourceHeaderContentRawLineTupleArray(in string source_txt_str) @safe { + HeaderContentInsertsImages markupSourceHeaderContentRawLineTupleArray(in string source_txt_str) @safe { string[] file_insert_list = []; string[] images_list = []; char[][] hc = header0Content1(source_txt_str); char[] header = hc[0]; char[] source_txt = hc[1]; char[][] source_line_arr = markupSourceLineArray(source_txt); - Tuple!(char[], char[][], string[], string[]) t = tuple( + HeaderContentInsertsImages t = tuple( header, source_line_arr, file_insert_list, @@ -155,7 +165,11 @@ static template spineRawMarkupContent() { } } struct Inserts { - auto scan_subdoc_source(O)( + alias ContentsAndImages = Tuple!( + char[][], "insert_contents", + string[], "images" + ); + ContentsAndImages scan_subdoc_source(O)( O _opt_action, char[][] markup_sourcefile_insert_content, string fn_src @@ -227,20 +241,20 @@ static template spineRawMarkupContent() { type1["header_meta"] = 0; contents_insert ~= line; // images to extract for image list? if (_opt_action.source || _opt_action.pod) { - auto _image_linelist = _extract_images(line); + string[] _image_linelist = _extract_images(line); if (_image_linelist.length > 0) { _images ~= _image_linelist; } } } } // end src subdoc (inserts) loop - Tuple!(char[][], string[]) t = tuple( + ContentsAndImages t = tuple( contents_insert, _images ); return t; } - Tuple!(char[][], string[], string[]) scan_master_src_for_insert_files_and_import_content(O)( + ContentsInsertsImages scan_master_src_for_insert_files_and_import_content(O)( O _opt_action, char[][] sourcefile_body_content, string fn_src @@ -290,14 +304,14 @@ static template spineRawMarkupContent() { ); } auto ins = Inserts(); - auto contents_insert_tu = ins.scan_subdoc_source( + ContentsAndImages contents_insert_tu = ins.scan_subdoc_source( _opt_action, markup_sourcefile_insert_content, fn_src_insert.to!string ); - contents ~= contents_insert_tu[0]; // images to extract for image list? + contents ~= contents_insert_tu.insert_contents; if (_opt_action.source || _opt_action.pod) { - auto _image_linelist = _extract_images(contents_insert_tu[0]); + string[] _image_linelist = _extract_images(contents_insert_tu.images); if (_image_linelist.length > 0) { _images ~= _image_linelist; } @@ -315,7 +329,7 @@ static template spineRawMarkupContent() { } else { contents ~= line; if (_opt_action.source || _opt_action.pod) { - auto _image_linelist = _extract_images(line); + string[] _image_linelist = _extract_images(line); if (_image_linelist.length > 0) { _images ~= _image_linelist; } @@ -330,7 +344,7 @@ static template spineRawMarkupContent() { writeln(__LINE__); writeln(contents.length); } - Tuple!(char[][], string[], string[]) t = tuple( + ContentsInsertsImages t = tuple( contents, insert_file_list, images |