Mercurial > repos > saskia-hiltemann > ireport
diff createHTML.sh @ 4:a4813532bbc6 draft
Added MarkDown support
author | saskia-hiltemann |
---|---|
date | Tue, 07 Oct 2014 08:41:30 -0400 |
parents | 440f4aa3db97 |
children | 42076db43d42 |
line wrap: on
line diff
--- a/createHTML.sh Tue Sep 30 09:56:12 2014 -0400 +++ b/createHTML.sh Tue Oct 07 08:41:30 2014 -0400 @@ -1,3 +1,6 @@ +## +## Create Cover Page +## function makeIntroPage ( ){ echo "Creating Intro Page" title="$1" @@ -11,7 +14,6 @@ <head> </head> <body> - <!-- dummy intro page, since first page will not have any javascript/css features enabled unless specified in universe_wsgi.ini file, but subsequent pages will --> <br/> <br/> <center> @@ -27,76 +29,138 @@ } - +## +## Create HTML content for the tabs specified by user +## function makeTabContent ( ){ - tab=$1 #name of current tab - itemslist=$2 #list of all items - contentline="<br/>" - imgcount=0 - #echo -e "\n Creating items. itemslist: $itemslist" + tab=$1 # name of current tab + itemslist=$2 # list of all items + contentline="" # HTML code for tab + imgcount=0 # keep track of the number of images on the current tab for item in $itemslist do - #echo -e "\n -> item : $item" + ## Parse items lists item=${item/::/:emptycol:} declare -a myarr=(`echo $item |sed 's/:/ /g'`) - #echo "break: ${myarr[3]}" + + ## Create the tab contents HTML code if [ ${myarr[0]} == $tab ] then - ## add contents of text field to page#### + ## + ## Text Field + ## if [ ${myarr[1]} == "text" ] then text=${myarr[2]} - ## allow some html formatting tags - text=${text//==lt==strong==gt==/<strong>} # search for strong tags - text=${text//==lt====slash==strong==gt==/<\/strong>} # search for strong tags - text=${text//==lt==em==gt==/<em>} # search for strong tags - text=${text//==lt====slash==em==gt==/<\/em>} # search for strong tags + md=${myarr[4]} - text=${text//==lt==b==gt==/<strong>} # search for strong tags - text=${text//==lt====slash==b==gt==/<\/strong>} # search for strong tags - text=${text//==lt==i==gt==/<em>} # search for strong tags - text=${text//==lt====slash==i==gt==/<\/em>} # search for strong tags + # if markdown, convert to html + if [ $md == "Y" ] + then + ## resubstitute sanitized charachters + text=${text//==space==/ } + text=${text//==colon==/:} + text=${text//==comma==/,} + text=${text//==slash==/\/} + text=${text//==lt==/<} + text=${text//==gt==/>} + text=${text//==apos==/\'} + text=${text//==quote==/\"} + text=${text//==backtick==/\`} + text=${text//==dollar==/$} + text=${text//==bar==/|} + text=${text//&&/&} + text=${text//\\n/\\n} + text=${text//\\t/\\t} + text=${text//\&r\&n/\\n} + text=${text//\&r/\\n} + text=${text//\&n/\\n} + text=${text//\&c/:} + + + ## convert markdown in textfield to html + echo -e "$text" > mytext.md + + if [ -z `type -p pandoc` ] + then + # pandoc missing + ${repositorypath}/Markdown/markdown2.py mytext.md > mytext.html + + else + # pandoc exists + echo "pandoc exists" + pandoc -o mytext.html mytext.md + pandoc -o standalone.html -s mytext.md + + #get css generated by pandoc and add as scoped attribute (HTML5) + pandocstyle=`sed -n '/<style/,/style>/p' standalone.html` + fi + + markdowntext=$(cat mytext.html) + contentline="${contentline}\n<div class=\"markdown-body\">${pandocstyle} ${markdowntext}</div>\n" + + else # If not markdown, print verbatim (with exception of few html tags) - text=${text//==lt==br==gt==/<br\/>} # search for strong tags - text=${text//==lt====br==slash==gt==/<br\/>} # search for strong tags - text=${text//==lt==h1==gt==/<h1>} # search for h1-h6 tags - text=${text//==lt==h2==gt==/<h2>} # search for h1-h6 tags - text=${text//==lt==h3==gt==/<h3>} # search for h1-h6 tags - text=${text//==lt==h4==gt==/<h4>} # search for h1-h6 tags - text=${text//==lt==h5==gt==/<h5>} # search for h1-h6 tags - text=${text//==lt==h6==gt==/<h6>} # search for h1-h6 tags - text=${text//==lt====slash==h1==gt==/<\/h1>} # search for h1-h6 closing tags - text=${text//==lt====slash==h2==gt==/<\/h2>} # search for h1-h6 closing tags - text=${text//==lt====slash==h3==gt==/<\/h3>} # search for h1-h6 closing tags - text=${text//==lt====slash==h4==gt==/<\/h4>} # search for h1-h6 closing tags - text=${text//==lt====slash==h5==gt==/<\/h5>} # search for h1-h6 closing tags - text=${text//==lt====slaxh==h6==gt==/<\/h6>} # search for h1-h6 closing tags + ## allow some html formatting tags + text=${text//==lt==strong==gt==/<strong>} # search for strong tags + text=${text//==lt====slash==strong==gt==/<\/strong>} # search for strong tags + text=${text//==lt==em==gt==/<em>} # search for strong tags + text=${text//==lt====slash==em==gt==/<\/em>} # search for strong tags + + text=${text//==lt==b==gt==/<strong>} # search for strong tags + text=${text//==lt====slash==b==gt==/<\/strong>} # search for strong tags + text=${text//==lt==i==gt==/<em>} # search for strong tags + text=${text//==lt====slash==i==gt==/<\/em>} # search for strong tags + + text=${text//==lt==br==gt==/<br\/>} # search for strong tags + text=${text//==lt====br==slash==gt==/<br\/>} # search for strong tags + text=${text//==lt==h1==gt==/<h1>} # search for h1-h6 tags + text=${text//==lt==h2==gt==/<h2>} # search for h1-h6 tags + text=${text//==lt==h3==gt==/<h3>} # search for h1-h6 tags + text=${text//==lt==h4==gt==/<h4>} # search for h1-h6 tags + text=${text//==lt==h5==gt==/<h5>} # search for h1-h6 tags + text=${text//==lt==h6==gt==/<h6>} # search for h1-h6 tags + text=${text//==lt====slash==h1==gt==/<\/h1>} # search for h1-h6 closing tags + text=${text//==lt====slash==h2==gt==/<\/h2>} # search for h1-h6 closing tags + text=${text//==lt====slash==h3==gt==/<\/h3>} # search for h1-h6 closing tags + text=${text//==lt====slash==h4==gt==/<\/h4>} # search for h1-h6 closing tags + text=${text//==lt====slash==h5==gt==/<\/h5>} # search for h1-h6 closing tags + text=${text//==lt====slaxh==h6==gt==/<\/h6>} # search for h1-h6 closing tags + + ## display everything else verbatim + text=${text//==space==/ } + text=${text//==colon==/:} + text=${text//==comma==/,} + text=${text//==slash==/\/} + text=${text//==lt==/<} + text=${text//==gt==/>} + text=${text//==apos==/'} + text=${text//==quote==/"} + text=${text//&&/&} + text=${text//\\n/<br/>} + text=${text//\\t/ } + text=${text//\&r\&n/<br/>} + text=${text//\&r/<br/>} + text=${text//\&n/<br/>} + text=${text//\&c/:} + text=${text//==backtick==/`} + text=${text//==dollar==/$} + text=${text//==bar==/|} + contentline="${contentline}\n${text}\n" + fi - ## display everything else verbatim - text=${text//==space==/ } - text=${text//==colon==/:} - text=${text//==comma==/,} - text=${text//==slash==/\/} - text=${text//==lt==/<} - text=${text//==gt==/>} - text=${text//==apos==/'} - text=${text//==quote==/"} - text=${text//&&/&} - text=${text//\\n/<br/>} - text=${text//\\t/ } - text=${text//\&r\&n/<br/>} - text=${text//\&r/<br/>} - text=${text//\&n/<br/>} - text=${text//\&c/:} - contentline="${contentline}${text}" + fi - ## add contents of a text file to page + ## + ## Text File + ## if [ ${myarr[1]} == "textfile" ] then tfile=${myarr[2]} + md=${myarr[4]} fname=`basename ${tfile}` fname=${fname%.*} fname="${fname}.txt" @@ -106,11 +170,37 @@ numlines=`wc -l ${tfile} | cut -d" " -f1` minheight=$[$numlines*17] - contentline="${contentline}<iframe class=\"invisibleframe\" src=\"${fname}\" width=\"100%\" height=\"$minheight\"> </iframe>" + # if markdown, convert to html + if [ $md == "Y" ] + then + + if [ -z `type -p pandoc` ] + then + # pandoc missing + ${repositorypath}/Markdown/markdown2.py ${tfile} > mytext.html + + else + # pandoc exists + pandoc -o mytext.html ${tfile} + pandoc -o standalone.html -s ${tfile} + + # get css generated by pandoc and add as scoped attribute (HTML5) + pandocstyle=`sed -n '/<style/,/style>/p' standalone.html` + + fi + + markdowntext=$(cat mytext.html) + contentline="${contentline}\n<div class=\"markdown-body\">${pandocstyle} ${markdowntext}</div>\n" + else + contentline="${contentline}\n<iframe class=\"invisibleframe\" src=\"${fname}\" width=\"100%\" height=\"$minheight\"> </iframe>\n" + fi fi - ## add image file to page + ## + ## Image + ## if [ ${myarr[1]} == "image" ] + then imgcount=$[$imgcount+1] #restore file suffix for html @@ -165,6 +255,10 @@ fi fi + + ## + ## Table + ## if [ ${myarr[1]} == "table" ] then maxlines=50000 @@ -223,8 +317,7 @@ print $0 } }END{}' ${tsvfile} > ${tsvfile}2 - #echo "converted file: " - #cat ${tsvfile}2 + else cp ${tsvfile} ${tsvfile}2 fi @@ -232,14 +325,10 @@ if [ $fancy == "Y" ] then perl ${repositorypath}/tsv2html.pl < ${tsvfile}2 > ${galaxypath}/htmltable_${fname}.html - #contentline="${contentline}\n<div class=\"resizable\" id=\"iframe${iframecount}\"><iframe src=\"htmltable_${fname}.html\" style=\"max-width: 100%;vertical-align: top;\" onload=\"resizeIframe(this)\"></iframe></div>" - #contentline="${contentline}\n<iframe class=\"resizable\" id=\"iframe${iframecount}\" src=\"htmltable_${fname}.html\" style=\"max-width: 100%;vertical-align: top;\" onload=\"resizeIframe(this)\"></iframe>" - contentline="${contentline}\n<iframe class=\"invisibleframe fancyiframe\" src=\"htmltable_${fname}.html\" width=\"100%\" style=\"min-height: 300px; overflow-y: hidden; overflow-x: scroll\" ></iframe>" - + contentline="${contentline}\n<iframe class=\"invisibleframe fancyiframe\" src=\"htmltable_${fname}.html\" width=\"100%\" style=\"min-height: 525px; overflow-y: hidden; overflow-x: scroll\" ></iframe>" iframecount=$[$iframecount+1] else perl ${repositorypath}/tsv2html_simple.pl < ${tsvfile}2 > ${galaxypath}/htmltable_${fname}.html - #contentline="${contentline}\n<iframe class=\"invisibleframe\" id=\"iframe${iframecount}\" style=\"max-width: 100%; vertical-align: top;\" src=\"htmltable_${fname}.html\" onload=\"resizeIframe(this)\"></iframe>" contentline="${contentline}\n<iframe class=\"unfancyiframe invisibleframe\" src=\"htmltable_${fname}.html\" scrolling=\"no\" style=\"max-width: 100%; vertical-align: top;\" onload=\"resizeIframe(this)\"></iframe>" iframecount=$[$iframecount+1] fi @@ -252,6 +341,9 @@ fi fi + ## + ## PDF + ## if [[ ${myarr[1]} == "pdf" ]] then pdffile=${myarr[2]} @@ -262,14 +354,31 @@ width=1000 height=800 - #contentline="${contentline}<object data=\"${fname}\" type=\"application/pdf\" width=\"1000\" height=\"1000\"><p>It appears you have no PDF plugin for your browser. No biggie... you can <a href=\"${fname}\">click here to download the PDF file.</a></p></object>" echo -e "<html><body><object data=\"${pdfname}\" type=\"application/pdf\" width=\"$width\" height=\"$height\"><embed src=\"${pdfname}\" type=\"application/pdf\" /><p>It appears you have no PDF plugin for your browser. No biggie... you can <a href=\"${pdfname}\">click here to download the PDF file.</a></p></object></body></html>" > "${galaxypath}/${fname}.html" width=$[$width+10] height=$[$height+10] - contentline="${contentline}<iframe src=\"${fname}.html\" width=\"${width}\" height=\"${height}\"></iframe>\n" + contentline="${contentline}\n<iframe src=\"${fname}.html\" width=\"${width}\" height=\"${height}\"></iframe>\n" fi - ## link to a location on the web, open in new window + + ## + ## HTML + ## + if [[ ${myarr[1]} == "htmlfile" ]] + then + htmlfile=${myarr[2]} + height=${myarr[4]} + fname=`basename ${htmlfile}` + fname=${fname%.dat} + htmlname="${fname}.html" + cp ${htmlfile} "${galaxypath}/${htmlname}" + + contentline="${contentline}\n<iframe class=\"invisibleframe\" src=\"${htmlname}\" width=\"100%\" height=\"${height}px\"></iframe>\n" + fi + + ## + ## Web Link + ## if [ ${myarr[1]} == "weblink" ] then url=${myarr[2]} @@ -280,7 +389,9 @@ contentline="${contentline}<a href=\"${url}\" target=\"_blank\">${linktext}</a>" fi - ## link to a file in the history + ## + ## Link to Dataset + ## if [ ${myarr[1]} == "link" ] then linkfile=${myarr[2]} @@ -324,7 +435,9 @@ contentline="${contentline}<a href=\"${linkfilename}\">${linktext}</a>" fi - ## link to files in an archive in the history item + ## + ## Links to Archive Contents + ## if [[ ${myarr[1]} == "links" ]] then #echo "making links:" @@ -421,7 +534,7 @@ if [[ ${myarr[3]} == "Y" ]] then - contentline="${contentline}<br/>" + contentline="${contentline}<br/>\n" fi fi done @@ -429,13 +542,15 @@ echo "${contentline}" } - +## +## Create HTML content for iReport +## createMainPage (){ page=$1 - tabtitles=$2 #comma-separated list of tab titles - tabitems=$3 - iframecount=1 - minwidth=$4 + tabtitles=$2 # comma-separated list of tab titles + tabitems=$3 # colon-sparated list of tabs specifications + iframecount=1 # keep track of number of iFrames so that they can be referenced by ID + minwidth=$4 # width of page echo "createMainPage: tabitems: $tabitems. tabtitles: $tabtitles" # create correct number of tabs @@ -445,15 +560,15 @@ tabtitles=${tabtitles//==colon==/:} tabslist="<ul>\n" mytabs="" + for title in $tabtitles do - #create list of tabs - + # Create list of tabs count=$[count+1] title2=${title//_s_/ } tabslist="${tabslist} <li><a href=\"#tabs-${count}\">${title2}</a></li>\n" - #create tabs with content + # Create tabs with content tabcontent=$(makeTabContent $title "$tabitems") mytabs="${mytabs}\n<div id=\"tabs-${count}\">\n" mytabs="${mytabs}${tabcontent}" @@ -461,99 +576,27 @@ done tabslist="${tabslist}</ul>" - #output the webpage + ## Output the webpage echo -e "<!doctype html> -<head> + <head> <meta charset=\"utf-8\"> - <title>jQuery UI Tabs - Default functionality</title> - - - <link rel=\"stylesheet\" href=\"jquery-ui.css\"> - <script src=\"jquery-1.10.2.js\"></script> - <script src=\"jquery-ui.js\"></script> + <title>iReport</title> + <link rel=\"stylesheet\" href=\"jquery-ui.css\"> + <link rel=\"stylesheet\" href=\"ireport_css.css\"> + <link rel=\"stylesheet\" href=\"md.css\"> + <script type=\"text/javascript\" src=\"jquery-1.10.2.js\"></script> + <script type=\"text/javascript\" src=\"jquery-ui.js\"></script> <script type=\"text/javascript\" src=\"iframe-resizer/src/iframeResizer.js\"></script> <script type=\"text/javascript\" src=\"jquery.zoom.js\"></script> - - <script> - \$(function() { - \$( \"#tabs\" ).tabs(); - }); - - \$(function() { - \$( \".resizable\" ).resizable(); - }); - - \$(document).ready(function(){ - \$('.zoomme').zoom(); - \$('#ex2').zoom({ on:'grab' }); - \$('#ex3').zoom({ on:'click' }); - \$('#ex4').zoom({ on:'toggle' }); - \$('.fancyiframe').iFrameResize({ - heightCalculationMethod: 'max', - minHeight: 250, - scrolling: true, - checkOrigin: false, - bodyMargin: 15 - }); - \$('.unfancyiframe').iFrameResize({ - heightCalculationMethod: 'max', - scrolling: false, - checkOrigin: false - }); - }); - - </script> - + <script type=\"text/javascript\" src=\"ireport_jquery.js\"></script> + <script type=\"text/javascript\" src=\"ireport_javascript.js\"></script> + </head> + <body> + <div id=\"tabs\" style=\"display:inline-block; min-height:100%; min-width:${minwidth}px\"> + $tabslist - <script language=\"javascript\" type=\"text/javascript\"> - function resizeIframe(obj) { - oldheight=obj.style.height - oldwidth=obj.style.width - obj.style.height = obj.contentWindow.document.body.scrollHeight + 4 + 'px'; - obj.style.width = obj.contentWindow.document.body.scrollWidth + 4 + 'px'; - - if(obj.style.height < 50){ - obj.style.height=oldheight - } - } - </script> -<style type=\"text/css\"> - body { - min-width: ${minwidth}px; - width: ${minwidth}px; - min-height: 100%; - } - .invisibleframe{ - border: 0px; - overflow: hidden - } - .mylinks{ - color: blue !important; - } - .mylinks:visited { - color: #551A8B !important; - } -</style> - <style > - .zoomme { - display: inline-block; - } -</style> - - -</head> -<body> - -<div id=\"tabs\" style=\"display:inline-block; min-height:100%; min-width:${minwidth}px\"> -$tabslist - -$mytabs -</div> - - -</body> + $mytabs + </div> + </body> </html>" > $page - - - } \ No newline at end of file