Rename directory to better suit the moving time.

Kind of also fix the apache conf, but not quite.
This commit is contained in:
2016-08-20 22:39:56 +02:00
parent 95bc653f50
commit ffcf9fefd5
438 changed files with 2 additions and 2 deletions

289
old-projects/totxt/.page.php Executable file
View File

@@ -0,0 +1,289 @@
<?php die(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta name='description' content='metanohi is the personal website of Niels Serup.' />
<meta name='keywords' content='nqpz, metanohi, web apps, web experiments, php experiments, javascript experiments, javascript games' />
<meta http-equiv='content-language' content='en' />
<meta http-equiv='content-type' content='text/html; charset=utf-8' />
<title>metanohi :: totxt</title>
<link href='../../site/style.css' type='text/css' rel='stylesheet' />
<script type='text/javascript' src='../../lib/httpobj.js'></script>
<script type='text/javascript' src='../../site/script.js'></script>
<script type='text/javascript' src='totxt.js'></script>
<script type='text/javascript'>
function extra() {
load_totxt_generator()
}
</script>
<style type='text/css'>
pre.totxt.dynamic0:hover {
background-color: #ff0000;
cursor: pointer;
}
</style>
</head>
<body>
<div id='menu'>
<ul id='links'>
<li><a href='../../'>Start</a></li>
<li class='current'><a href='../../projects/'>Projects</a></li>
<li><a href='../../writings/'>Writings</a></li>
<li><a href='../../about/'>About metanohi</a></li>
<li><a href='../../aboutme/'>About me</a></li>
<li class='last'><a href='#' id='searchlink' class=''>Search</a></li>
</ul>
</div>
<form method='get' action='../../search/' id='searchform'>
<p>
<input id='searchfield' type='text' name='q' value='' />
<input type='submit' value='Search' />
</p>
</form>
<div id='logo'></div>
<div id='content'>
<div id='leftcolumn'>
<div id='text'>
<h1 style="font-family: &quot;dejavu sans mono&quot; monospace courier; font-size: 50px;">totxt</h1>
<h1 class="totxt">What is totxt?</h1>
<h2>totxt is a futuristic program</h2>
<p>
totxt is a JavaScript program that transforms text with regular HTML formatting into text that looks like what you're reading right now. The file <a href="totxt.js">totxt.js</a> contains the function <span class="code">load_totxt_generator</span>, which, when run, finds text in HTML elements and converts that text into this. Before reading on, have a look at the following examples to see how it works:<br/><br/>
<a href="example1.php">Example 1</a><br/>
<a href="example2.php">Example 2</a><br/>
<a href="example3.php">Example 3</a><br/>
<br/>
You might also want to take a look at how the examples look without the use of totxt:<br/><br/>
<a href="example1.php?n">Example 1 without totxt</a><br/>
<a href="example2.php?n">Example 2 without totxt</a><br/>
<a href="example3.php?n">Example 3 without totxt</a><br/>
</p>
<p>&nbsp;</p>
<p>totxt is free software; you can redistribute it and/or modify it under the terms of the <a href="http://www.gnu.org/licenses/gpl.html" rel="license">GNU General Public License</a> as published by the Free Software Foundation; either version 3 of the License, or (at your option)
any later version.</p>
<p>&nbsp;</p>
<p>
totxt accepts two ways of ignoring default values: a global way, which has an effect on all totxt elements, and a local way, which only has an effect on a particular totxt element. <span class="b">An example:</span><br/>
Before running the <span class="code">load_totxt_generator</span> function, define this inside a script tag:<br/>
totxt_DYNAMIC = 0<br/>
This will make all totxt elements dynamic, i.e. it will be possible to open and close totxt boxes. When closed, only the header is displayed, while in its open state, both the header, the subheader (if any) and the text will be visible. The 0 value means that all totxt elements first appear in their closed forms. Assigning a value of 1 will make all elements start out as open. Any other value than 0 or 1 will not work. Note that, by default, being dynamic also means that an element opens and closes in a sliding motion and that an element is opened by clicking on it and closed by doubleclicking on it.<br/>
Another way to defy normal values is to locally define changes. Applying 'dynamic0' as a class to a totxt element, such that it will look something like:<br/>
&lt;h1 class='totxt dynamic0'&gt;A header&lt;/h1&gt;<br/>
will have the same effect as defining it the global way, except this will only affect the current element, and not all elements.
</p>
<p><br/>Below is a table describing the values of totxt.</p>
<table class="border space">
<thead><tr>
<th>Global variable</th>
<th>Local definition</th>
<th>Description</th>
<th>Default value</th>
</tr>&nbsp;</thead>
<tbody>
<tr>
<td>totxt_WIDTH</td>
<td>widthX</td>
<td>Line width</td>
<td>80</td>
</tr>
<tr>
<td>totxt_DYNAMIC</td>
<td>dynamicX</td>
<td>Dynamic, open or closed?</td>
<td>-1 (not dynamic)</td>
</tr>
<tr>
<td>totxt_DYNAMIC_SPEED</td>
<td>speedX</td>
<td>Speed of line removal/appending when sliding (in ms)</td>
<td>50</td>
</tr>
<tr>
<td>totxt_DYNAMIC_LINES</td>
<td>linesX</td>
<td>Amount of line(s) to (dis)appear per function call</td>
<td>1</td>
</tr>
<tr>
<td>totxt_QUICK_DYNAMIC</td>
<td>quick_dynamic</td>
<td>Open/close boxes instantly. Do not slide.</td>
<td>false</td>
</tr>
<tr>
<td>totxt_DEL_XWS</td>
<td>del_excess_whitespace</td>
<td>Delete excess whitespace</td>
<td>false</td>
</tr>
<tr>
<td>totxt_HEADER_ALIGN</td>
<td>halignX</td>
<td>Alignment of header (0 = left, 1 = center, 2 = right)</td>
<td>1 (center)</td>
</tr>
<tr>
<td>totxt_SUBHEADER_ALIGN</td>
<td>shalignX</td>
<td>Alignment of subheader</td>
<td>0 (left)</td>
</tr>
<tr>
<td>totxt_TEXT_ALIGN</td>
<td>talignX</td>
<td>Alignment of text</td>
<td>0 (left)</td>
</tr>
</tbody>
</table>
<br/>
<p class="n">Furthermore, there are some global variables that can be used to modify the what classes to look for.</p>
<table class="border space">
<thead><tr>
<th>Global variable</th>
<th>Description</th>
<th>Default value</th>
</tr>&nbsp;</thead>
<tbody>
<tr>
<td>totxt_CLASSNAME</td>
<td>Main class to look for. Only elements with this classname has a chance of becoming totxt elements.</td>
<td>totxt</td>
</tr>
<tr>
<td>totxt_DYNAMIC_CLASSNAME</td>
<td>&nbsp;</td>
<td>dynamic</td>
</tr>
<tr>
<td>totxt_DYNSPEED_CLASSNAME</td>
<td>&nbsp;</td>
<td>speed</td>
</tr>
<tr>
<td>totxt_DYNLINES_CLASSNAME</td>
<td>&nbsp;</td>
<td>lines</td>
</tr>
<tr>
<td>totxt_HALIGN_CLASSNAME</td>
<td>&nbsp;</td>
<td>halign</td>
</tr>
<tr>
<td>totxt_SHALIGN_CLASSNAME</td>
<td>&nbsp;</td>
<td>shalign</td>
</tr>
<tr>
<td>totxt_TALIGN_CLASSNAME</td>
<td>&nbsp;</td>
<td>talign</td>
</tr>
<tr>
<td>totxt_WIDTH_CLASSNAME</td>
<td>&nbsp;</td>
<td>width</td>
</tr>
<tr>
<td>totxt_DELXWS_CLASSNAME</td>
<td>&nbsp;</td>
<td>del_excess_whitespace</td>
</tr>
<tr>
<td>totxt_QUICK_CLASSNAME</td>
<td>&nbsp;</td>
<td>quick_dynamic</td>
</tr>
<tr>
<td>totxt_HEADER_ELEMENT</td>
<td>Element type containing header text and totxt information in form of classes</td>
<td>H1</td>
</tr>
<tr>
<td>totxt_SUBHEADER_ELEMENT</td>
<td>Element type containing subheader text. Any information in classes will be ignored.</td>
<td>H2</td>
</tr>
<tr>
<td>totxt_TEXT_ELEMENT</td>
<td>Element type containing text. Any information in classes will be ignored.</td>
<td>P</td>
</tr>
</tbody>
</table>
<br/>
<p>To use totxt, simply save it in a directory, then import it using a script tag. Something like this:</p>
<pre>
&lt;html&gt;
&lt;head&gt;
&lt;script type='text/javascript' src='totxt.js'&gt;&lt;/script&gt;
&lt;script type='text/javascript'&gt;
window.onload = load_totxt_generator
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
...
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Note that this will run when the page importing it has loaded. It is of course also possible to execute totxt code on other actions.</p>
<p><span class="code">load_totxt_generator</span> can be run more than once, without any problems arising.</p>
<br/>
<h1 class="totxt dynamic" style="color: #002244">Important information (click to open)</h1>
<h2>Look no further!</h2>
<p>
totxt elements inherit all classes, any eventual id, and style if present, but only from the header element. When looking for text, totxt searches for subheader elements and text elements below the header element. If any other element than those appears, the search will halt. <span class="b">An example:</span><br/><br/>
&lt;h1 class='totxt'&gt;Header&lt;/h1&gt;<br/>
&lt;p&gt;This will be used.&lt;/p&gt;<br/>
&lt;p&gt;This will also be used.&lt;/p&gt;<br/>
&lt;blockquote&gt;<br/>
I fell asleep reading a dull book, and I dreamt that I was reading on, so I woke up from sheer boredom.<br/>
&lt;/blockquote&gt;<br/>
&lt;p&gt;This will <span class="b">not</span> be used.&lt;/p&gt;
</p>
<div id='lastupdated'>Last updated: 7 Aug 2009</div></div>
</div>
<div id='rightcolumn'>
<div id='headerbackground'>&nbsp;</div>
<div id='rightcontent'>
$RIGHT$
</div>
</div>
</div>
<div id='footer'>
<p><a href='../../browse/#projects/totxt/content.xml'>View source code</a><a href='../../about/' class='last'>Copyleft &copy; Niels Serup 2009, 2010. Text is released under CC-BY-SA 3.0.</a></p>
</div>
</body>
</html>

View File

@@ -0,0 +1 @@
<?php $date = 1249682415; ?>

50
old-projects/totxt/example1.php Executable file
View File

@@ -0,0 +1,50 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>totxt example (1)</title>
<meta http-equiv='content-type' content='text/html; charset=utf-8' />
<style type='text/css'>
* {
margin: 0;
padding: 0;
}
pre.totxt {
margin: 5px;
}
</style>
<?php if (!$_SERVER['QUERY_STRING']) { ?>
<script type='text/javascript' src='totxt.js'></script>
<script type='text/javascript'>
window.onload = load_totxt_generator
</script>
<?php } ?>
</head>
<body>
<h1 class='totxt'>Fish</h1>
<h2>What is a fish?</h2>
<p>A fish is any aquatic vertebrate animal that is typically ectothermic (or cold-blooded), covered with scales, and equipped with two sets of paired fins and several unpaired fins. Fish are abundant in the sea and in fresh water, with species being known from mountain streams (e.g., char and gudgeon) as well as in the deepest depths of the ocean (e.g., gulpers and anglerfish).</p>
<p></p>
<p>Food prepared from fish is also called fish, and it is an important food source for humans. They are harvested either from wild fisheries (see fishing) or farmed in much the same way as cattle or chickens (see aquaculture). They are also exploited by recreational fishers and fishkeepers, and are exhibited in public aquaria. Fish have had a role in many cultures through the ages, ranging from deities and religious symbols to the subjects of books and popular movies.</p>
<p><br />From <a href='http://en.wikipedia.org/wiki/Fish'>http://en.wikipedia.org/wiki/Fish</a>. Licensed under CC-BY-SA 3.0.</p>
<h1 class='totxt'>Plain text</h1>
<p>In computing, plain text is a term used for an ordinary "unformatted" sequential file readable as textual material without much processing.</p>
<p></p>
<p>The encoding has traditionally been either ASCII, one of its many derivatives such as ISO/IEC 646 etc., or sometimes EBCDIC. No other encodings are used in plain text files which neither contain any (character-based) structural tags such as heading marks, nor any typographic markers like bold face, italics, etc.</p>
<p></p>
<p>Unicode is today gradually replacing the older ASCII derivatives limited to 7 or 8 bit codes. It will probably serve much the same purposes, but this time permitting almost any human language as well as important punctuation and symbols such as mathematical relations (≠ ≤ ≥ ≈), multiplication (× •), etc, which are not included in the more restricted ASCII set.</p>
<p><br />From <a href='http://en.wikipedia.org/wiki/Plain_text'>http://en.wikipedia.org/wiki/Plain_text</a>. Licensed under CC-BY-SA 3.0.</p>
<h1 class='totxt'>Lojban</h1>
<h2>A logical language</h2>
<p>Lojban (pronounced [ˈloʒban]) is a constructed, syntactically unambiguous human language based on predicate logic. Its predecessor is Loglan, the original logical language by James Cooke Brown.</p>
<p></p>
<p>Development of the language began in 1987 by The Logical Language Group (LLG), who intended to realize Loglan's purposes as well as further complement the language by making it more usable, and freely available (as indicated by its official full English name "Lojban: a realization of Loglan"). After a long initial period of debating and testing, the baseline was completed in 1998 with the publication of The Complete Lojban Language. The name "Lojban" is a combination of loj and ban, which are short forms of logji (logic) and bangu (language), respectively.</p>
<p></p>
<p>The principal sources of its basic vocabulary were the six (at the time) most widely spoken languages: Mandarin, English, Hindi, Spanish, Russian, and Arabic, chosen to reduce the unfamiliarity or strangeness of the root words to people of diverse linguistic backgrounds. The language has drawn on other constructed languages' components, a notable instance of which is Láadan's set of indicators[1].</p>
<p><br />From <a href='http://en.wikipedia.org/wiki/Lojban'>http://en.wikipedia.org/wiki/Lojban</a>. Licensed under CC-BY-SA 3.0.</p>
</body>
</html>

62
old-projects/totxt/example2.php Executable file
View File

@@ -0,0 +1,62 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>totxt example (2)</title>
<meta http-equiv='content-type' content='text/html; charset=utf-8' />
<style type='text/css'>
* {
margin: 0;
padding: 0;
}
pre.totxt {
margin: 5px;
float: left;
clear: left;
}
pre.totxt.dynamic0 {
cursor: pointer;
}
pre.totxt.dynamic0:hover {
background-color: #eee;
}
</style>
<?php if (!$_SERVER['QUERY_STRING']) { ?>
<script type='text/javascript' src='totxt.js'></script>
<script type='text/javascript'>
totxt_DYNAMIC = 0 // Boxes are dynamic and closed
window.onload = load_totxt_generator
</script>
<?php } ?>
</head>
<body>
<p style='margin: 5px; font-family: "dejavu sans"'>Click to open, doubleclick to close</p>
<h1 class='totxt'>Fish</h1>
<h2>What is a fish?</h2>
<p>A fish is any aquatic vertebrate animal that is typically ectothermic (or cold-blooded), covered with scales, and equipped with two sets of paired fins and several unpaired fins. Fish are abundant in the sea and in fresh water, with species being known from mountain streams (e.g., char and gudgeon) as well as in the deepest depths of the ocean (e.g., gulpers and anglerfish).</p>
<p></p>
<p>Food prepared from fish is also called fish, and it is an important food source for humans. They are harvested either from wild fisheries (see fishing) or farmed in much the same way as cattle or chickens (see aquaculture). They are also exploited by recreational fishers and fishkeepers, and are exhibited in public aquaria. Fish have had a role in many cultures through the ages, ranging from deities and religious symbols to the subjects of books and popular movies.</p>
<p><br />From <a href='http://en.wikipedia.org/wiki/Fish'>http://en.wikipedia.org/wiki/Fish</a>. Licensed under CC-BY-SA 3.0.</p>
<h1 class='totxt'>Plain text</h1>
<p>In computing, plain text is a term used for an ordinary "unformatted" sequential file readable as textual material without much processing.</p>
<p></p>
<p>The encoding has traditionally been either ASCII, one of its many derivatives such as ISO/IEC 646 etc., or sometimes EBCDIC. No other encodings are used in plain text files which neither contain any (character-based) structural tags such as heading marks, nor any typographic markers like bold face, italics, etc.</p>
<p></p>
<p>Unicode is today gradually replacing the older ASCII derivatives limited to 7 or 8 bit codes. It will probably serve much the same purposes, but this time permitting almost any human language as well as important punctuation and symbols such as mathematical relations (≠ ≤ ≥ ≈), multiplication (× •), etc, which are not included in the more restricted ASCII set.</p>
<p><br />From <a href='http://en.wikipedia.org/wiki/Plain_text'>http://en.wikipedia.org/wiki/Plain_text</a>. Licensed under CC-BY-SA 3.0.</p>
<h1 class='totxt'>Lojban</h1>
<h2>A logical language</h2>
<p>Lojban (pronounced [ˈloʒban]) is a constructed, syntactically unambiguous human language based on predicate logic. Its predecessor is Loglan, the original logical language by James Cooke Brown.</p>
<p></p>
<p>Development of the language began in 1987 by The Logical Language Group (LLG), who intended to realize Loglan's purposes as well as further complement the language by making it more usable, and freely available (as indicated by its official full English name "Lojban: a realization of Loglan"). After a long initial period of debating and testing, the baseline was completed in 1998 with the publication of The Complete Lojban Language. The name "Lojban" is a combination of loj and ban, which are short forms of logji (logic) and bangu (language), respectively.</p>
<p></p>
<p>The principal sources of its basic vocabulary were the six (at the time) most widely spoken languages: Mandarin, English, Hindi, Spanish, Russian, and Arabic, chosen to reduce the unfamiliarity or strangeness of the root words to people of diverse linguistic backgrounds. The language has drawn on other constructed languages' components, a notable instance of which is Láadan's set of indicators[1].</p>
<p><br />From <a href='http://en.wikipedia.org/wiki/Lojban'>http://en.wikipedia.org/wiki/Lojban</a>. Licensed under CC-BY-SA 3.0.</p>
</body>
</html>

122
old-projects/totxt/example3.php Executable file
View File

@@ -0,0 +1,122 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>totxt example (3)</title>
<meta http-equiv='content-type' content='text/html; charset=utf-8' />
<style type='text/css'>
* {
margin: 0;
padding: 0;
}
pre.totxt {
float: left;
margin: 5px;
}
pre.totxt.dynamic {
cursor: default;
}
pre.totxt.dynamic0:hover {
background-color: #eee;
}
pre.totxt.quick_dynamic.dynamic1 {
background-color: #000;
color: #fff;
}
pre.totxt.quick_dynamic.dynamic1:hover {
background-color: #fff;
color: #000;
}
pre.gryxo {
background: #555 url(vortex-l2.png) center;
color: #ddd;
}
pre#first {
color: #a48008;
}
</style>
<?php if (!$_SERVER['QUERY_STRING']) { ?>
<script type='text/javascript' src='totxt.js'></script>
<script type='text/javascript'>
// The lines below decide various important stuff. Try experimenting.
totxt_WIDTH = 60 // Line width. Default is 80.
//totxt_DYNAMIC = 0 // Leaves articles closed, expands on mouseclick
//totxt_DYNAMIC_SPEED = 500 // Adding/removing lines (in milliseconds)
//totxt_DYNAMIC_LINES = 3 // The amount of lines to add/remove
//totxt_QUICK_DYNAMIC = true // Expand/collapse at once or gradually
//totxt_DEL_XWS = true // Always delete excessive whitespace
//totxt_HEADER_ALIGN = 0 // Left (normally center)
//totxt_SUBHEADER_ALIGN = 1 // Center (normally left)
//totxt_TEXT_ALIGN = 2 // Right (normally left)
//totxt_CLASSNAME = '2txt' // Classname to recognize
//totxt_DYNAMIC_CLASSNAME = 'dirasabc' // Classname to recognize
//totxt_DYNSPEED_CLASSNAME = 'spd' // Normally 'speed'
//totxt_DYNLINES_CLASSNAME = 'lin' // Normally 'lines'
//totxt_HALIGN_CLASSNAME = 'hal' // Default: 'halign'
//totxt_SHALIGN_CLASSNAME = 'shal' // Default: 'shalign'
//totxt_TALIGN_CLASSNAME = 'tal' // Default: 'talign'
//totxt_WIDTH_CLASSNAME = 'w' // Instead of 'width'
//totxt_DELXWS_CLASSNAME = 'delspaces' // std: 'del_excess_whitespace'
//totxt_QUICK_CLASSNAME = 'q' // Default:
//totxt_HEADER_ELEMENT = 'h3' // Normally h1
//totxt_SUBHEADER_ELEMENT = 'p' // Normally h2
//totxt_TEXT_ELEMENT = 'div' // Normally p
window.onload = load_totxt_generator
</script>
<?php } ?>
</head>
<body>
<!-- ARTICLE ONE START -->
<h1 class='totxt dynamic speed20' id='first'>Nonsense makes more sense</h1>
<h2>Not to be confused with fish</h2>
<p><b>4 August 2013</b> -- In a <span style='color: #00ff00'>surprising</span> move this morning, former ex-alien Mr. Umbago has now volunteered for freedom work at the speaker center in the middle of the bus driving from left to right on Wednesdays, right to left on Fridays, and all other directions whenever people feel like it. This has resulted in the loss of several server farms in the midst of the rainy midsommer, and within the monthly year of sun, it has now finally been decided that prices on <i>tickets</i> for sleep walking should not go up. On the contrary, people with doppelgangers should be allowed to walk across the ocean, as long as they remember to bring a bucket to travel to the lake south of the Earth with.</p>
<p>"This is unfortunate," current foreign affairs pencil adds.</p>
<!-- ARTICLE ONE END -->
<!-- ARTICLE TWO START -->
<h1 class='totxt width40 del_excess_whitespace' style='text-transform: uppercase'>Peach takes icecream shop to court</h1>
<p>
<b>3 August 2012</b> -- Peach, the company known throughout
the world for their iPears, yesterday declared war on a small
business. The reason? Trademark infringement. The small
icecream cafe known as "iCecreamy" had, unfortunately,
used a lowercase <i>i</i> and an uppercase <i>C</i> in
their name. This unlucky decision made Peach drag it to
court, saying that the name was patented by Peach. The
***cream owner has had no comments so far.<br />
See also: Peach aquired by aliens
</p>
<!-- ARTICLE TWO END -->
<!-- ARTICLE THREE START -->
<h1 class='totxt width22 dynamic1 quick_dynamic'>&lt; &frac34; = &frac14; &times; 3 &gt;</h1>
<p>&iquest;&plusmn; &iquest;&plusmn; &iquest;&plusmn; &iquest;&plusmn; &iquest;&plusmn; &iquest;&plusmn; &iquest;&plusmn; &iquest;&plusmn; &iquest;&plusmn; <i>&iquest;</i>&plusmn; &iquest;&plusmn; &iquest;&plusmn; &iquest;&plusmn; &iquest;&plusmn; &iquest;&plusmn; &iquest;&plusmn; &iquest;&plusmn; &iquest;&plusmn; &iquest;&plusmn; <b>&iquest;&plusmn; &iquest;&plusmn;</b> &iquest;&plusmn; &iquest;&plusmn; &iquest;&plusmn; &iquest;&plusmn; &iquest;&plusmn; &iquest;&plusmn; &iquest;&plusmn; &iquest;&plusmn; &iquest;&plusmn; &iquest;&plusmn; &iquest;&plusmn; &iquest;&plusmn; &iquest;&plusmn; &iquest;&plusmn; &iquest;&plusmn;</p>
<!-- ARTICLE THREE END -->
<!-- DEFY float: left -->
<div style='clear: both'></div>
<!-- ARTICLE FOUR START -->
<h1 class='totxt width90 halign0 shalign2 dynamic1 lines2 gryxo'>HTML codes</h1>
<h2>You can collapse and expand this window.</h2>
<p>
<b>The following is made to confuse:</b><br />
&lt;a&nbsp;href='http://example.org/'&gt;<a href='http://example.org/'>http://example.org/</a>&lt;/a&gt;<br />
&lt;span style='color: magenta'&gt;<span style='color: magenta'>Magenta-coloured text</span>&lt;/span&gt;
</p>
<!-- ARTICLE FOUR END -->
<!-- ARTICLE FIVE START -->
<h1 class='totxt width33 talign1'>aHA!</h1>
<p>2 + 2 = 2 &middot; 2</p>
<!-- ARTICLE FIVE END -->
</body>
</html>

3
old-projects/totxt/index.php Executable file
View File

@@ -0,0 +1,3 @@
<?php
header('Location: http://metanohi.name/projects/totxt/');
?>

725
old-projects/totxt/totxt.js Executable file
View File

@@ -0,0 +1,725 @@
/*
totxt: A program that transforms HTML elements to plain text
Copyright (C) 2009 Niels Serup
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
Version: 0.9
You can contact Niels at <ns@metanohi.name>.
Latest version is always available at <http://metanohi.org/projects/totxt/>,
along with documentation.
*/
/* To avoid overuse of global variables, all functions and actions have been
stuffed into the 'load_totxt_generator' function. */
function load_totxt_generator(action, var_a) {
/* Normally, this function will load a bunch of functions and then generate
PRE elements. This isn't the case if a special action is defined. */
function count(haystack, needle) {
// Counts needles in haystack
if (needle == undefined)
var needle = '\n'
var c, offset
offset = -1
c = 0
while (offset) {
offset = haystack.indexOf(needle, offset) + 1
c++
}
return c
}
if (action == 'show_or_hide') {
/* Used by dynamic boxes that utilize sliding functionality. To open an
article box, it is sufficient to click on it, but to close one, one
must doubleclick on it. This is partly why there are some
differences in what type of state the box is in. */
var obj = document.totxt_preElements[var_a]
if (obj.state) {
// If open, COLLAPSE
obj.state = 0
if (obj.quickdyn) {
// Don't slide
obj.innerHTML = obj.header
obj.className = obj.className.replace(obj.dynclass + '1', obj.dynclass + '0')
obj.onclick = function(){load_totxt_generator('show_or_hide', this.number)}
obj.ondblclick = undefined
}
else {
// Do slide
obj.onclick = undefined
obj.ondblclick = undefined
obj.slide_expand = 0
obj.line = undefined
load_totxt_generator('slide', var_a)
}
}
else {
// If closed, EXPAND
obj.state = 1
obj.className = obj.className.replace(obj.dynclass + '0', obj.dynclass + '1')
if (obj.quickdyn) {
// Don't slide
obj.innerHTML = obj.fulltext
obj.onclick = undefined
obj.ondblclick = function(){load_totxt_generator('show_or_hide', this.number)}
}
else {
// Do slide
obj.onclick = undefined
obj.ondblclick = undefined
obj.slide_expand = 1
obj.line = undefined
load_totxt_generator('slide', var_a)
}
}
return true
}
else if (action == 'slide') {
/* Using the setTimeout function, this action is used by 'show_or_hide'
actions to either expand or collapse a box slidingly. */
var obj, hh, th, obdl
obj = document.totxt_preElements[var_a]
hh = obj.headerheight
th = obj.fulltextheight
if (obj.line == undefined) {
if (obj.slide_expand)
obj.line = hh
else
obj.line = th
}
obj.innerHTML = obj.fulltext.split('\n', obj.line).join('\n')
// Add lines when expanding, remove lines when collapsing
if (obj.slide_expand) {
obdl = obj.line
if (obdl == th)
obdl++
else {
obdl = obj.line + obj.dynlines
if (obdl > th)
obdl = th
}
obj.line = obdl
}
else {
obdl = obj.line
if (obdl == hh)
obdl--
else {
obdl = obj.line - obj.dynlines
if (obdl < hh)
obdl = hh
}
obj.line = obdl
}
if (obj.line >= hh && obj.line <= th)
setTimeout('load_totxt_generator(\'slide\', ' + var_a + ')', obj.dynspeed)
else {
// End 'loop'
if (obj.slide_expand) {
obj.onclick = undefined
obj.ondblclick = function(){load_totxt_generator('show_or_hide', this.number)}
}
else {
obj.onclick = function(){load_totxt_generator('show_or_hide', this.number)}
obj.ondblclick = undefined
obj.className = obj.className.replace(obj.dynclass + '1', obj.dynclass + '0')
}
// Not necessary. Has no noticable effect.
delete document.slide_object
delete obj.slide_expand
delete obj.line
}
return true
}
/*
No more special actions exist. If none of the two above actions were
specified, code execution will begin here.
*/
// Various functions
function isin(ref, str, end, defau) {
// Checks for string str in array ref. If end is true, look for match in
// beginning of str and return the end of str
var x, c
for (x in ref) {
c = ref[x]
if (end) {
if (c.indexOf(str) == 0)
return c.substr(str.length)
}
else if (c == str)
return true
}
if (defau)
return defau
else
return false
}
function ctimes(cha, times) {
// <character> * times (a, 3 = aaa)
var t = ''
for (var i = 0; i < times; i++) {
t += cha
}
return t
}
function transform_text(str, w, align, del_xws) {
/* This function transforms text seen in ordinary HTML tags into text
that fits simple monospace character boxes. */
// Prepare text
str = str.replace(new RegExp('^\\s+'), '').replace(new RegExp('\\s+$'), '')
str = str.replace(/<br \/>/gi, '<br>').replace(/<br>\n/gi, '<br>')
//str = str.replace(/&nbsp;/g, ' ')
str = str.replace(/\n/g, ' ')
if (del_xws) {
// Delete excessive whitespace
str = str.replace(new RegExp('\\s+', 'g'), ' ')
}
str = str.replace(/<br>/gi, '\n')
if (del_xws) {
// Delete excessive whitespace caused by line break transformation
str = str.replace(/\n /g, '\n')
}
var tags, tlen, intag, start, i, c, x, sstr, ntxt, ctxt, txt, cw, clen
var entities, inentity, filter, tminus, l, spaces
// Store and remove HTML tags in text (will be readded in text later)
// Also look for HTML entities, such as &lt; (<)
tagent = [] // To store HTML tags and HTML entities
tlen = str.length
start = 0
intag = false
inentity = false
filter = ' <>!"\'\\/*-+,.:;'
ntxt = ''
for (i = 0; i < tlen; i++) {
c = str.substr(i, 1)
if (c == '<' && !intag) {
intag = true
start = i
}
else if (c == '>' && intag) {
intag = false
tagent[tagent.length] = ['tag', start, str.substr(start, i - start + 1)]
}
else if (!intag) {
if (c == '&' && !inentity) {
if (filter.indexOf(str.substr(i+1, 1)) == -1) {
inentity = true
start = i
}
ntxt += c
}
else if (c == ';' && inentity) {
inentity = false
tagent[tagent.length] = ['ent', start, str.substr(start, i - start + 1)]
}
else if (!inentity)
ntxt += c
}
}
str = ntxt
// Change line width of text. When inserting a hyphen and a newline, check
// if positions of HTML tags and HTML entities need to be changed.
sstr = str.split('\n')
ntxt = ''
for (ctxt in sstr) {
txt = sstr[ctxt]
while (txt) {
if (txt.length <= w) {
ntxt += txt
break
}
if (txt.substr(0, w).indexOf(' ') == -1) {
ntxt += txt.substr(0, w - 1) + '-\n'
txt = txt.substr(w - 1)
clen = ntxt.length
tminus = 0
for (x in tagent) {
if (tagent[x][1] - tminus > clen)
tagent[x][1] += 2
l = tagent[x][2].length
if (tagent[x][0] == 'ent')
l--
tminus += l
}
continue
}
cw = w
while (txt.substr(cw, 1) != ' ')
cw -= 1
ntxt += txt.substr(0, cw) + '\n'
txt = txt.substr(cw + 1)
// No need to readjust positions of HTML stuff here, as the
// new newline replaces a space character
}
ntxt += '\n'
}
while (ntxt.substr(ntxt.length - 1) == '\n')
ntxt = ntxt.substr(0, ntxt.length - 1)
str = ntxt
// Readd removed HTML tags and HTML entities
for (x in tagent) {
c = tagent[x]
if (c[0] == 'tag')
str = str.substr(0, c[1]) + c[2] + str.substr(c[1])
else if (c[0] == 'ent')
str = str.substr(0, c[1]) + c[2] + str.substr(c[1]+1)
}
// Align (0 = left, 1 = center, 2 = right)
if (align != 0 && align != 1 && align != 2)
align = 0
sstr = str.split('\n')
ntxt = ''
for (ctxt in sstr) {
txt = sstr[ctxt]
tlen = txt.length
clen = 0
intag = false
inentity = false
for (i = 0; i < tlen; i++) {
c = txt.substr(i, 1)
if (c == '<' && !intag)
intag = true
else if (c == '>' && intag)
intag = false
else if (c == '&' && !inentity) {
if (filter.indexOf(txt.substr(i+1, 1)) == -1)
inentity = true
clen++
}
else if (c == ';' && inentity)
inentity = false
else if (!intag && !inentity)
clen++
}
spaces = w - clen
ntxt += '\n'
if (align == 0) // Left
ntxt += txt + ctimes(' ', spaces)
else if (align == 2) // Right
ntxt += ctimes(' ', spaces) + txt
else if (align == 1) // Center
ntxt += ctimes(' ', Math.floor(spaces / 2)) + txt + ctimes(' ', Math.ceil(spaces / 2))
}
ntxt = ntxt.substr(1)
if (ntxt)
str = ntxt
return str
}
function add_borders(txt, border, padding) {
// Adds borders to boxes
if (border == undefined)
border = '|'
if (padding == undefined)
padding = ' '
var s, x, c, n
s = txt.split('\n')
n = ''
for (x in s) {
c = s[x]
n += '\n' + border + padding + c + padding + border
}
return n.substr(1)
}
function transform_text_in_list(arr, w, del_xws, borders, padding, align) {
// Transform, then join
var x, c, f, t
f = ''
for (x in arr) {
c = arr[x]
if (align == undefined)
align = 0 // Left
t = transform_text(c, w, align, del_xws)
if (borders)
t = add_borders(t, borders, padding)
f += '\n' + t
}
return f.substr(1)
}
// No more functions
// Begin load + search + generate
// Local variables
var h1s, x, z, y, ok, cur, classes, par, chs, cur_found, ccur,
header, subheaders, texts, elems, subheader, content,
stdclass, dynclass, widclass, xwsclass, quiclass, speclass, linclass,
stdwidth, width, stddynamic, dynamic, isdynamic, delxws,
dynspeed, c_speed, dynlines, c_lines, quickdyn, c_quidyn, alwdelxws,
stdhalign, stdshalign, stdtalign, halclass, shalclass, talclass,
c_halign, c_shalign, c_talign
var h_elmnm, sh_elmnm, txt_elmnm
var tmps, text, preElements, elmminus, prelms, plen, celm
var /*poss_classes, n_classes,*/ pid, tmp
// Default classnames for recognition purposes.
// Can be changed using global variables.
stdclass = 'totxt'
try {
stdclass = totxt_CLASSNAME ? totxt_CLASSNAME : stdclass
}
catch(e) {}
dynclass = 'dynamic'
try {
dynclass = totxt_DYNAMIC_CLASSNAME ? totxt_DYNAMIC_CLASSNAME : dynclass
}
catch(e) {}
widclass = 'width'
try {
widclass = totxt_WIDTH_CLASSNAME ? totxt_WIDTH_CLASSNAME : widclass
}
catch(e) {}
xwsclass = 'del_excess_whitespace'
try {
xwsclass = totxt_DELXWS_CLASSNAME ? totxt_DELXWS_CLASSNAME : xwsclass
}
catch(e) {}
speclass = 'speed'
try {
speclass = totxt_DYNSPEED_CLASSNAME ? totxt_DYNSPEED_CLASSNAME : speclass
}
catch(e) {}
linclass = 'lines'
try {
linclass = totxt_DYNLINES_CLASSNAME ? totxt_DYNLINES_CLASSNAME : linclass
}
catch(e) {}
quiclass = 'quick_dynamic'
try {
quiclass = totxt_QUICK_CLASSNAME ? totxt_QUICK_CLASSNAME : quiclass
}
catch(e) {}
halclass = 'halign'
try {
halclass = totxt_HALIGN_CLASSNAME ? totxt_HALIGN_CLASSNAME : halclass
}
catch(e) {}
shalclass = 'shalign'
try {
shalclass = totxt_SHALIGN_CLASSNAME ? totxt_SHALIGN_CLASSNAME : shalclass
}
catch(e) {}
talclass = 'talign'
try {
talclass = totxt_TALIGN_CLASSNAME ? totxt_TALIGN_CLASSNAME : talclass
}
catch(e) {}
h_elmnm = 'H1'
try {
h_elmnm = totxt_HEADER_ELEMENT ? totxt_HEADER_ELEMENT.toUpperCase() : h_elmnm
}
catch(e) {}
sh_elmnm = 'H2'
try {
sh_elmnm = totxt_SUBHEADER_ELEMENT ? totxt_SUBHEADER_ELEMENT.toUpperCase() : sh_elmnm
}
catch(e) {}
txt_elmnm = 'P'
try {
txt_elmnm = totxt_TEXT_ELEMENT ? totxt_TEXT_ELEMENT.toUpperCase() : txt_elmnm
}
catch(e) {}
h1s = document.getElementsByTagName(h_elmnm)
if (!h1s)
return false
// Default values
// Line width
stdwidth = 80
try {
stdwidth = totxt_WIDTH * 1 ? totxt_WIDTH : stdwidth
}
catch(e) {}
if (stdwidth < 10)
stdwidth = 10
// Should articles be allowed to collapse and expand with a mouseclick?
stddynamic = -1
try {
stddynamic = totxt_DYNAMIC
}
catch(e) {}
// Sliding speed
dynspeed = 50
try {
dynspeed = totxt_DYNAMIC_SPEED * 1
}
catch(e) {}
// Line(s) to (dis)appear per function call
dynlines = 1
try {
dynlines = totxt_DYNAMIC_LINES * 1 ? totxt_DYNAMIC_LINES * 1 : dynlines
}
catch(e) {}
// Don't slide?
quickdyn = false
try {
quickdyn = totxt_QUICK_DYNAMIC
}
catch(e) {}
// Delete excessive whitespace?
alwdelxws = false
try {
alwdelxws = totxt_DEL_XWS
}
catch(e) {}
// Header alignment
stdhalign = 1 // Center
try {
stdhalign = totxt_HEADER_ALIGN * 1
}
catch(e) {}
// Subheader alignment
stdshalign = 0 // Left
try {
stdshalign = totxt_SUBHEADER_ALIGN * 1
}
catch(e) {}
// Text alignment
stdtalign = 0 // Left
try {
stdtalign = totxt_TEXT_ALIGN * 1
}
catch(e) {}
// Checking for impossible alignments
if (stdhalign > 2) stdhalign = 2
else if (stdhalign < 0) stdhalign = 0
if (stdshalign > 2) stdshalign = 2
else if (stdshalign < 0) stdshalign = 0
if (stdtalign > 2) stdtalign = 2
else if (stdtalign < 0) stdtalign = 0
elems = [] // Elements that contain info to be used in final PRE elements.
prelms = [] // PRE elements
/*
// Special classes
poss_classes = [stdclass, dynclass, widclass, xwsclass, speclass, linclass, quiclass, halclass, shalclass, talclass]
*/
// document.totxt_preElements is the variable in which to store the PRE elements.
try {
/* document.totxt_preElements likely doesn't exist, which could result in an
error if not called inside a try statement. */
preElements = document.totxt_preElements
elmminus = preElements.length
}
catch(e) {
document.totxt_preElements = []
preElements = []
elmminus = 0
}
// Look up H1 elements
for (x in h1s) {
cur = h1s[x]
if (!cur || !cur.className)
continue
// Filters
classes = cur.className.split(' ')
if (!isin(classes, stdclass))
continue
par = cur.parentNode
if (!par)
continue
// Find H2 and P elements that are "below" the current H1 element
chs = par.childNodes
cur_found = 0
header = cur.innerHTML
subheaders = []
texts = []
elems[elems.length] = cur
for (z in chs) {
ccur = chs[z]
if (ccur == cur) {
cur_found = 1
continue
}
if (!cur_found || !ccur.tagName)
continue
if (ccur.tagName == sh_elmnm)
subheaders[subheaders.length] = ccur.innerHTML
else if (ccur.tagName == txt_elmnm)
texts[texts.length] = ccur.innerHTML
else
break
// If either H2 or P element, add object to elems var
elems[elems.length] = ccur
}
width = isin(classes, widclass, 1, stdwidth) * 1
if (width < 10)
width = stdwidth
dynamic = isin(classes, dynclass, 1, stddynamic) * 1
isdynamic = dynamic == 0 || dynamic == 1
delxws = isin(classes, xwsclass, 0, alwdelxws)
c_halign = isin(classes, halclass, 1, stdhalign) * 1
c_shalign = isin(classes, shalclass, 1, stdshalign) * 1
c_talign = isin(classes, talclass, 1, stdtalign) * 1
tmps = [' ' + ctimes('-', width - 2),
'|' + ctimes('_', width - 2) + '|',
'| ' + ctimes('~', width - 4) + ' |\n']
// Now generate the content
header = add_borders(transform_text(header, width - 4, c_halign, delxws), '|')
subheader = subheaders ? transform_text_in_list(subheaders, width - 4, delxws, '|', ' ', c_shalign) : ''
content = texts ? transform_text_in_list(texts, width - 4, delxws, '|', ' ', c_talign) : ''
header = tmps[0] + '\n' + header + '\n' + tmps[0]
text = header + '\n'
if (subheader)
text += subheader + '\n' + tmps[2]
if (content)
text += content + '\n'
text += tmps[1]
/*
// Check for special classes that have nothing to do with settings
n_classes = []
for (z in classes) {
for (y in poss_classes) {
ok = true
if (!classes[z].indexOf(poss_classes[y])) {
ok = false
break
}
}
if (ok)
n_classes[n_classes.length] = classes[z]
}
n_classes = n_classes.join(' ')
*/
// Find eventual id
pid = cur.id
delete cur.id // To avoid two elements with alike ids
plen = prelms.length
prelms[plen] = document.createElement('pre')
celm = prelms[plen]
celm.number = plen + elmminus // preElements may not be empty
celm.className = cur.className
/*
celm.className = stdclass
if (n_classes)
celm.className += ' ' + n_classes
*/
if (pid)
celm.id = pid
// Find and apply eventual styles
for (z in cur.style) {
c = cur.style[z]
if (c) {
try {
if (c.indexOf(':') != -1)
tmp = c.split(':')
celm.style.setProperty(tmp[0], tmp[1].replace(';', ''), '')
}
catch(e){}
}
}
celm.style.display = 'none'
celm.innerHTML = text
if (isdynamic) {
c_speed = isin(classes, speclass, 1, dynspeed) * 1
c_lines = isin(classes, linclass, 1, dynlines) * 1
if (!c_lines) c_lines = dynlines
c_quidyn = isin(classes, quiclass, 0, quickdyn)
celm.fulltext = text
celm.header = header
celm.headerheight = count(header)
celm.fulltextheight = count(text)
celm.state = dynamic
if (!isin(classes, dynclass))
celm.className += ' ' + dynclass
if (!isin(classes, dynclass + dynamic))
celm.className += ' ' + dynclass + dynamic
/*
if (c_quidyn)
celm.className += ' ' + quiclass
*/
celm.dynclass = dynclass
celm.dynspeed = c_speed
celm.dynlines = c_lines
celm.quickdyn = c_quidyn
if (dynamic == 0)
celm.onclick = function(){load_totxt_generator('show_or_hide', this.number)}
else
celm.ondblclick = function(){load_totxt_generator('show_or_hide', this.number)}
if (!dynamic)
celm.innerHTML = header
}
par.insertBefore(prelms[plen], cur)
}
// Remove used elements
for (x in elems) {
elems[x].parentNode.removeChild(elems[x])
}
// Show new elements
for (x in prelms) {
prelms[x].style.display = 'block'
}
for (x in prelms) {
preElements[preElements.length] = prelms[x]
}
document.totxt_preElements = preElements
return true
}

BIN
old-projects/totxt/vortex-l2.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB