diff --git a/.gitignore b/.gitignore index d793de9..cdf363a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ #test result -result/* +tests/result* +tests/result* #vim session files *.vims diff --git a/ASCIIsite.py b/ASCIIsite.py index 9860f1d..f0978b5 100755 --- a/ASCIIsite.py +++ b/ASCIIsite.py @@ -11,6 +11,7 @@ def parse_arguments(): parser=argparse.ArgumentParser(description='create a website directory structure by converting .adoc files in a directory strucutre to .html files.') parser.add_argument('inputDir', type=Path, help='The directory of adoc files to be copied and converted.') parser.add_argument('-o', '--output', type=Path, help='What to name the generated directory or tar file') + parser.add_argument('--stylesheet', type=Path, help='A custom CSS file to be applied to the output.') parser.add_argument('--exclude-file', type=Path, help='A text file containing glob patterns to exclude, 1 per line.') parser.add_argument('--exclude', nargs='+', help='A list of glob patterns to ignore. Remember to quote them so your shell doesnt escape them!') parser.add_argument('-z', '--compress', action='store_true', help='whether to compress the resulting directory to a tar.gz file. can be usefull for scripting to transfer the site to a remote server.') @@ -63,7 +64,12 @@ def parse_arguments(): print(f'Inputdir {args.inputDir.resolve()} does not exist!') exit() - return args.inputDir.resolve(), outFile, compress, exclude + stylesheet=None + if args.stylesheet != None: + stylesheet =args.stylesheet.resolve() + logging.info(f'using stylesheet {stylesheet}') + + return args.inputDir.resolve(), outFile, stylesheet, compress, exclude #Doing it in a tmpDir first, as some distrubutions put temp files on a ramdisk. this should speed up the operation sigificantly. class TmpDir: @@ -102,21 +108,18 @@ def find_relative_file_depth (subfile, parentDir): return len(subfile.parts)-len(parentDir.parts)-1 #simple wrapper around the asciidoctor cli. -def convert_file(inDir, outDir, inFile): +def convert_file(inDir: Path, outDir: Path, inFile: Path, stylesheet: Path): #in order for the stylesdir and imagesdir to be linked to correctly, we need to know the relative depth between the two directories. depth=find_relative_file_depth(inFile, inDir) logging.info(f'converting {Path(inFile).resolve()}') - logging.debug(f'converting {inFile} from directory {inDir} to directory {outDir} with a relative depth of {depth}') + logging.debug(f'converting {inFile=}, {outDir=}, {inDir=}, {stylesheet=}') depthstring= '../'*depth - try: - #the destdir can be used instead of destfile in order to preserve the directory structure relative to the base dir. really useful. - subprocess.run(['asciidoctor', + arguments=['asciidoctor', #makes the stylesheet linked, but still includes it in the output. '--attribute=linkcss', - '--attribute=copycss', f'--attribute=stylesdir={depthstring}css', #set imagesdir f'--attribute=imagesdir={depthstring}images', @@ -124,21 +127,29 @@ def convert_file(inDir, outDir, inFile): f'--source-dir={inDir}', #Destination dir. It takes the file from the subtree --source-dir and puts it in the equivilant location in the subtree --destination-dir. (talking about filesystem subtrees). f'--destination-dir={outDir}', - inFile], - check=True) + inFile] + + if stylesheet != None: + arguments.insert(1, f'--attribute=copycss={stylesheet}') + arguments.insert(1, f'--attribute=stylesheet={stylesheet.name}') + else: + arguments.insert(1, f'--attribute=copycss') + logging.debug(f'{arguments=}') + try: + #the destdir can be used instead of destfile in order to preserve the directory structure relative to the base dir. really useful. + subprocess.run(arguments, check=True) except Exception as e: logging.error(f'could not convert {inFile}!') - logging.error(f'stdErr was {e.stderr}') - logging.error(f'stdOut was {e.stdout}') + logging.error(f'{e}') if __name__ == '__main__': - inFile, outFile, compress, exclude=parse_arguments() + inFile, outFile, stylesheet, compress, exclude=parse_arguments() os.chdir(inFile) tmpDir=TmpDir('./', exclude) pathsToConvert=find_paths_to_convert('*.adoc') for i in pathsToConvert: - convert_file('./', tmpDir.path, i) + convert_file(inDir='./', outDir=tmpDir.path, inFile=i, stylesheet=stylesheet) if compress: tmpDir.compress_and_copy_self_to(outFile) diff --git a/tests/control/css/asciidoctor.css b/tests/control/css/asciidoctor.css index d6d02fb..98f27c4 100644 --- a/tests/control/css/asciidoctor.css +++ b/tests/control/css/asciidoctor.css @@ -183,7 +183,8 @@ body.toc2.toc-right{padding-left:0;padding-right:20em}} #content h1>a.link:hover,h2>a.link:hover,h3>a.link:hover,#toctitle>a.link:hover,.sidebarblock>.content>.title>a.link:hover,h4>a.link:hover,h5>a.link:hover,h6>a.link:hover{color:#a53221} details,.audioblock,.imageblock,.literalblock,.listingblock,.stemblock,.videoblock{margin-bottom:1.25em} details{margin-left:1.25rem} -details>summary{cursor:pointer;display:block;position:relative;line-height:1.6;margin-bottom:.625rem;-webkit-tap-highlight-color:transparent} +details>summary{cursor:pointer;display:block;position:relative;line-height:1.6;margin-bottom:.625rem;outline:none;-webkit-tap-highlight-color:transparent} +details>summary::-webkit-details-marker{display:none} details>summary::before{content:"";border:solid transparent;border-left:solid;border-width:.3em 0 .3em .5em;position:absolute;top:.5em;left:-1.25rem;transform:translateX(15%)} details[open]>summary::before{border:solid transparent;border-top:solid;border-width:.5em .3em 0;transform:translateY(15%)} details>summary::after{content:"";width:1.25rem;height:1em;position:absolute;top:.3em;left:-1.25rem} @@ -225,9 +226,8 @@ pre.prettyprint li:not(:first-child) code[data-lang]::before{display:none} table.linenotable{border-collapse:separate;border:0;margin-bottom:0;background:none} table.linenotable td[class]{color:inherit;vertical-align:top;padding:0;line-height:inherit;white-space:normal} table.linenotable td.code{padding-left:.75em} -table.linenotable td.linenos{border-right:1px solid;opacity:.35;padding-right:.5em} -pre.pygments .lineno{border-right:1px solid;opacity:.35;display:inline-block;margin-right:.75em} -pre.pygments .lineno::before{content:"";margin-right:-.125em} +table.linenotable td.linenos,pre.pygments .linenos{border-right:1px solid;opacity:.35;padding-right:.5em;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none} +pre.pygments span.linenos{display:inline-block;margin-right:.75em} .quoteblock{margin:0 1em 1.25em 1.5em;display:table} .quoteblock:not(.excerpt)>.title{margin-left:-1.5em;margin-bottom:.75em} .quoteblock blockquote,.quoteblock p{color:rgba(0,0,0,.85);font-size:1.15rem;line-height:1.75;word-spacing:.1em;letter-spacing:0;font-style:italic;text-align:justify} @@ -264,7 +264,7 @@ table.frame-none>colgroup+*>:first-child>*,table.frame-sides>colgroup+*>:first-c table.frame-none>:last-child>:last-child>*,table.frame-sides>:last-child>:last-child>*{border-bottom-width:0} table.frame-none>*>tr>:first-child,table.frame-ends>*>tr>:first-child{border-left-width:0} table.frame-none>*>tr>:last-child,table.frame-ends>*>tr>:last-child{border-right-width:0} -table.stripes-all tr,table.stripes-odd tr:nth-of-type(odd),table.stripes-even tr:nth-of-type(even),table.stripes-hover tr:hover{background:#f8f8f7} +table.stripes-all>*>tr,table.stripes-odd>*>tr:nth-of-type(odd),table.stripes-even>*>tr:nth-of-type(even),table.stripes-hover>*>tr:hover{background:#f8f8f7} th.halign-left,td.halign-left{text-align:left} th.halign-right,td.halign-right{text-align:right} th.halign-center,td.halign-center{text-align:center} @@ -280,10 +280,11 @@ ol{margin-left:1.75em} ul li ol{margin-left:1.5em} dl dd{margin-left:1.125em} dl dd:last-child,dl dd:last-child>:last-child{margin-bottom:0} -ol>li p,ul>li p,ul dd,ol dd,.olist .olist,.ulist .ulist,.ulist .olist,.olist .ulist{margin-bottom:.625em} +li p,ul dd,ol dd,.olist .olist,.ulist .ulist,.ulist .olist,.olist .ulist{margin-bottom:.625em} ul.checklist,ul.none,ol.none,ul.no-bullet,ol.no-bullet,ol.unnumbered,ul.unstyled,ol.unstyled{list-style-type:none} ul.no-bullet,ol.no-bullet,ol.unnumbered{margin-left:.625em} ul.unstyled,ol.unstyled{margin-left:0} +li>p:empty:only-child::before{content:"";display:inline-block} ul.checklist>li>p:first-child{margin-left:-1em} ul.checklist>li>p:first-child>.fa-square-o:first-child,ul.checklist>li>p:first-child>.fa-check-square-o:first-child{width:1.25em;font-size:.8em;position:relative;bottom:.125em} ul.checklist>li>p:first-child>input[type=checkbox]:first-child{margin-right:.25em} @@ -326,8 +327,6 @@ sup.footnote a:active,sup.footnoteref a:active{text-decoration:underline} #footnotes .footnote a:first-of-type{font-weight:bold;text-decoration:none;margin-left:-1.05em} #footnotes .footnote:last-of-type{margin-bottom:0} #content #footnotes{margin-top:-.625em;margin-bottom:0;padding:.75em 0} -.gist .file-data>table{border:0;background:#fff;width:100%;margin-bottom:0} -.gist .file-data>table td.line-data{width:99%} div.unbreakable{page-break-inside:avoid} .big{font-size:larger} .small{font-size:smaller} diff --git a/tests/control/dir/subdir/linked.html b/tests/control/dir/subdir/linked.html index cf08c73..b15754c 100644 --- a/tests/control/dir/subdir/linked.html +++ b/tests/control/dir/subdir/linked.html @@ -4,7 +4,7 @@ - +