add md+katex huge txt viewer

This commit is contained in:
James Feng Cao 2022-10-20 17:04:24 +08:00
parent 1ca754c378
commit 3cb1a66d80
11 changed files with 173 additions and 13 deletions

View File

@ -15,6 +15,7 @@
<description>This page is for uweb browser.
Click to install the following html5 apps:
Huge markdown file viewer
Huge markdown+katex file viewer (Tex formulas)
Huge markdeep file viewer (markdown, latex, diagram,graphviz etc.)
plyr video player
dplayer video player

View File

@ -50,6 +50,7 @@
<p>This page is for <a href="../index.html">uweb browser</a>.<br>
Click to install the following html5 apps:<br>
<a target="_self" href="i:0happ/txtview.html:../../zh/searchurl/txt/txtview.html">Huge markdown file viewer</a><br>
<a target="_self" href="i:0happ/mdkatex.html:../../zh/searchurl/txt/mdkatex.html">Huge markdown+katex file viewer (Tex formulas)</a><br>
<a target="_self" href="i:0happ/markdeep.html:../../zh/searchurl/txt/markdeep.html">Huge markdeep file viewer (markdown, latex, diagram,graphviz etc.)</a><br>
<a target="_self" href="i:0happ/plyr.html:../../zh/searchurl/txt/plyr.cfg">plyr video player</a><br>
<a target="_self" href="i:0happ/dplayer.html:../../zh/searchurl/txt/dplayer.html">dplayer video player</a><br>

View File

@ -15,6 +15,7 @@
<description>This page is for uweb browser.
Click to install the following html5 apps:
Huge markdown file viewer
Huge markdown+katex file viewer (Tex formulas)
Huge markdeep file viewer (markdown, latex, diagram,graphviz etc.)
plyr video player
dplayer video player
@ -184,12 +185,12 @@ htmlview:https://htmlview.glitch.me/?
htmlpreview:https://htmlpreview.github.io/?
webarchive:https://web.archive.org/web/*/
archive:https://archive.is/?run=1&amp;amp;url=
googlecache:http://webcache.googleusercontent.com/search?q=cache:
google by image:https://www.google.com/searchbyimage?image_url=
tinyeye:https://tineye.com/search?url=
Yandex image:https://yandex.com/images/search?text=
Yandex by image:https://yandex.com/images/search?family=yes&amp;amp;rpt=imageview&amp;amp;url=
ascii2d:https://ascii2d.net/search/url/
trace.moe:https://trace.moe/?url=</description>
ascii2d:https://ascii2d.net/search/url/</description>
</item>
<item>

View File

@ -80,12 +80,12 @@ htmlview:https://htmlview.glitch.me/?
htmlpreview:https://htmlpreview.github.io/?
webarchive:https://web.archive.org/web/*/
archive:https://archive.is/?run=1&amp;amp;url=
googlecache:http://webcache.googleusercontent.com/search?q=cache:
google by image:https://www.google.com/searchbyimage?image_url=
tinyeye:https://tineye.com/search?url=
Yandex image:https://yandex.com/images/search?text=
Yandex by image:https://yandex.com/images/search?family=yes&amp;amp;rpt=imageview&amp;amp;url=
ascii2d:https://ascii2d.net/search/url/
trace.moe:https://trace.moe/?url=</description>
ascii2d:https://ascii2d.net/search/url/</description>
</item>
<item>

View File

@ -70,6 +70,7 @@
<p><a href="i:01htmlpreview:https://htmlpreview.github.io/?">htmlpreview:https://htmlpreview.github.io/?</a></p>
<p><a href="i:01webarchive:https://web.archive.org/web/*/">webarchive:https://web.archive.org/web/*/</a></p>
<p><a href="i:01archive:https://archive.is/?run=1&url=">archive:https://archive.is/?run=1&amp;url=</a></p>
<p><a href="i:01googlecache:http://webcache.googleusercontent.com/search?q=cache:">googlecache:http://webcache.googleusercontent.com/search?q=cache:</a></p>
<p><a href="i:01google by image:https://www.google.com/searchbyimage?image_url=">google by image:https://www.google.com/searchbyimage?image_url=</a></p>
<p><a href="i:01tinyeye:https://tineye.com/search?url=">tinyeye:https://tineye.com/search?url=</a></p>
<p><a href="i:01Yandex image:https://yandex.com/images/search?text=">Yandex image:https://yandex.com/images/search?text=</a></p>
@ -96,13 +97,14 @@
<p><a href="i:01Send url(video):i:5ji:0mc16:">Send url(video):i:5ji:0mc16:</a></p>
<p><a href="i:01Send url(bookmark site fullscreen):i:5ji:52../home5:i:0mi:5f:">Send url(bookmark site fullscreen):i:5ji:52../home5:i:0mi:5f:</a></p>
<p>The following needs corresponding <a href="../html5/index.html">html5 application</a> to be installed:</p>
<p><a href="i:01txtview:file:///data/data/info.torapp.uweb/files/app/txtview.html?url=">txtview:file:///data/data/info.torapp.uweb/files/app/txtview.html?url=</a></p>
<p><a href="i:01markdeep:file:///data/data/info.torapp.uweb/files/app/markdeep.html?url=">markdeep:file:///data/data/info.torapp.uweb/files/app/markdeep.html?url=</a></p>
<p><a href="i:01plyr:file:///data/data/info.torapp.uweb/files/app/plyr.html?u=">plyr:file:///data/data/info.torapp.uweb/files/app/plyr.html?u=</a></p>
<p><a href="i:01dplayer:file:///data/data/info.torapp.uweb/files/app/dplayer.html?u=">dplayer:file:///data/data/info.torapp.uweb/files/app/dplayer.html?u=</a></p>
<p><a href="i:01pdf:file:///data/data/info.torapp.uweb/files/app/pdfviewer.html?file=">pdf:file:///data/data/info.torapp.uweb/files/app/pdfviewer.html?file=</a></p>
<p><a href="i:01epub:file:///data/data/info.torapp.uweb/files/app/epub.html?u=">epub:file:///data/data/info.torapp.uweb/files/app/epub.html?u=</a></p>
<p><a href="i:01djvu:file:///data/data/info.torapp.uweb/files/app/djvu.html?url=">djvu:file:///data/data/info.torapp.uweb/files/app/djvu.html?url=</a></p>
<p><a href="i:01txtview:file:///data/user/0/info.torapp.uweb/files/app/txtview.html?url=">txtview:file:///data/user/0/info.torapp.uweb/files/app/txtview.html?url=</a></p>
<p><a href="i:01mdkatex:file:///data/user/0/info.torapp.uweb/files/app/mdkatex.html?url=">mdkatex:file:///data/user/0/info.torapp.uweb/files/app/mdkatex.html?url=</a></p>
<p><a href="i:01markdeep:file:///data/user/0/info.torapp.uweb/files/app/markdeep.html?url=">markdeep:file:///data/user/0/info.torapp.uweb/files/app/markdeep.html?url=</a></p>
<p><a href="i:01plyr:file:///data/user/0/info.torapp.uweb/files/app/plyr.html?u=">plyr:file:///data/user/0/info.torapp.uweb/files/app/plyr.html?u=</a></p>
<p><a href="i:01dplayer:file:///data/user/0/info.torapp.uweb/files/app/dplayer.html?u=">dplayer:file:///data/user/0/info.torapp.uweb/files/app/dplayer.html?u=</a></p>
<p><a href="i:01pdf:file:///data/user/0/info.torapp.uweb/files/app/pdfviewer.html?file=">pdf:file:///data/user/0/info.torapp.uweb/files/app/pdfviewer.html?file=</a></p>
<p><a href="i:01epub:file:///data/user/0/info.torapp.uweb/files/app/epub.html?u=">epub:file:///data/user/0/info.torapp.uweb/files/app/epub.html?u=</a></p>
<p><a href="i:01djvu:file:///data/user/0/info.torapp.uweb/files/app/djvu.html?url=">djvu:file:///data/user/0/info.torapp.uweb/files/app/djvu.html?url=</a></p>
</div>

View File

@ -122,6 +122,7 @@ Android TV可利用顺序搜索使用箭头按钮切换频道。顺序搜索引
<guid>/zh/bookmark/</guid>
<description>所有书签都可通过&amp;quot;长按链接-&amp;gt;命令-&amp;gt;书签&amp;quot;保存链接为书签。书签菜单可至特色服务网页安装。
Personal use, not for public
Personal use 2
Wait for url from other devices
gamezop
分类书签模板 点击以下链接可安装模板至分类书签目录。保存至“小说”类别的网站会自动使用阅读模式。

View File

@ -49,6 +49,7 @@
</ul>
<p>所有书签都可通过&quot;长按链接-&gt;命令-&gt;书签&quot;保存链接为书签。书签菜单可至<a href="../urls/index.html">特色服务网页</a>安装。<br>
<a href="https://s1.asytech.cn/s/JoNbk7N8K74HHNW">Personal use, not for public</a><br>
<a href="https://www.123pan.com/s/cKA9-HFUCA">Personal use 2</a><br>
<a href="i:1c">Wait for url from other devices</a><br>
<a href="https://www.gamezop.com">gamezop</a></p>
<h3 id="分类书签模板">分类书签模板</h3>

View File

@ -301,6 +301,7 @@ Android TV可利用顺序搜索使用箭头按钮切换频道。顺序搜索引
<guid>/zh/bookmark/</guid>
<description>所有书签都可通过&amp;quot;长按链接-&amp;gt;命令-&amp;gt;书签&amp;quot;保存链接为书签。书签菜单可至特色服务网页安装。
Personal use, not for public
Personal use 2
Wait for url from other devices
gamezop
分类书签模板 点击以下链接可安装模板至分类书签目录。保存至“小说”类别的网站会自动使用阅读模式。

View File

@ -2,5 +2,5 @@ pdf:uweb:echo file:///sdcard/uweb/app/pdfviewer.html?file=%u#page=1
djvu:uweb:echo file:///sdcard/uweb/app/djvu.html?url=%u#page=1
epub:uweb:echo file:///sdcard/uweb/app/epub.html?u=%u
txt:uweb:echo file:///sdcard/uweb/app/txtview.html?url=%u#page=1
md.html:uweb:echo file:///sdcard/uweb/app/markdeep.html?url=%u#page=1
md:uweb:echo file:///sdcard/uweb/app/txtview.html?url=%u#page=1
py:termux/*:python %f;exit -1

View File

@ -22,7 +22,7 @@
}
var file;
var blocksize = 1024;
var blocksize = 20480;
function loadSlice(){
function render(u8array){
document.body.innerHTML = window.markdeep.format(new TextDecoder().decode(u8array),true);

View File

@ -0,0 +1,152 @@
<head>
<base>
<script src="https://fastly.jsdelivr.net/npm/marked@3.0.7/marked.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/katex@0.13.11/dist/katex.min.js" crossorigin="anonymous"></script>
<script>
const renderer = new marked.Renderer();
var options = {
renderer: renderer,
pedantic: false,
gfm: true,
breaks: false,
sanitize: false,
smartLists: true,
smartypants: false,
xhtml: false
};
marked.setOptions(options);
function htmldecode(text){
var temp = document.createElement("div");
temp.innerHTML = text;
var output = temp.innerText || temp.textContent;
temp = null;
return output;
}
function mathsExpression(expr) {
if (expr.match(/^\$\$[\s\S]*\$\$$/)) {
expr = expr.substr(2, expr.length - 4);
return katex.renderToString(expr, { displayMode: true });
} else if (expr.match(/^\$[\s\S]*\$$/)) {
expr = htmldecode(expr); // temp solution
expr = expr.substr(1, expr.length - 2);
return katex.renderToString(expr, { displayMode: false });
}
}
const unchanged = new marked.Renderer()
renderer.code = function(code, lang, escaped) {
if (!lang) {
const math = mathsExpression(code);
if (math) {
return math;
}
}
return unchanged.code(code, lang, escaped);
};
renderer.codespan = function(text) {
const math = mathsExpression(text);
if (math) {
return math;
}
return unchanged.codespan(text);
};
function markedWithKatex(text) {
return marked(text, options);
}
function absFile(url) {
this.name=url;
this.slice = async(offset, length) =>{
const headers = new Headers();
headers.append('range', 'bytes=' + offset + '-' + ( offset + length -1).toString());
const opts = {
credentials: 'include',
headers : headers
};
const resp = await fetch( this.name, opts );
return await resp.arrayBuffer();
//alert(JSON.stringify(resp.headers));
//return await resp.text();
}
}
var file;
var blocksize = 20480;
function loadSlice(){
function render(u8array){
document.body.innerHTML = markedWithKatex(new TextDecoder().decode(u8array));
scroll(0,0);
}
function setPageUrl(pageurl){
let a = document.createElement('a');
a.href = "i:5c"+pageurl;
a.click();
}
var page = 1;
var extrasize = blocksize; //extrasize should <= blocksize
let lhash = location.hash;
if(lhash){
if("p"!==lhash.charAt(1)){//#offset=&[len]
let iAmpersand = lhash.indexOf('&',8);
let offset = parseInt(lhash.substring(8,iAmpersand));
let len = parseInt(lhash.substring(iAmpersand+1));
{//update urlInc() url
let href = location.href;
let iHash = href.indexOf('#');
href=href.substring(0,iHash)+"#page="+Math.floor((offset+len)/blocksize);
setPageUrl(href);
}
file.slice(offset,len).then((buffer)=>{
let u8 = new Uint8Array(buffer);
render(u8);
});
return;
}
//#page=
page = parseInt(lhash.substring(6));
}else
setPageUrl(location.href+"#page=1");
file.slice(blocksize*(page-1),blocksize+extrasize).then((buffer)=>{
let u8 = new Uint8Array(buffer);
let u8len = u8.length;
let iStart = 0;
let limit = Math.min(u8len,extrasize);
if(1!=page){
for(let i=1;i<limit;i=i+2){
if(10==u8[i] && 10==u8[i-1]) {
iStart = i+1;
break;
}
}
}
let iEnd = Math.min(u8len,blocksize);
limit = Math.min(u8len,blocksize+extrasize);
for(let i=blocksize+1;i<limit;i=i+2){
if(10==u8[i] && 10==u8[i-1]) {
iEnd = i+1;
break;
}
}
render(u8.slice(iStart,iEnd));
});
}
//?url=#offset=&[len]&page=
{
let url = location.search.substring(5);
file = new absFile(url);
document.getElementsByTagName('base')[0].href=url;
}
window.addEventListener('hashchange',loadSlice);
</script>
</head>
<body>
<script>loadSlice();</script>
</body>