<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -87,6 +87,7 @@ file_put_contents(&quot;{$smarty-&gt;template_dir}/.posts$path/$file.date&quot;,
 list($title, $tags, $body) = preg_split(&quot;!\r?\n\r?\n!&quot;,
 	file_get_contents($arg), 3);
 $tags = preg_split('!\s+!', $tags);
+$body = input_footnoterize($body, end($parts));
 blog_publish_smarty($path, $file, $timestamp, $title, $tags, $body,
 	$comments);
 echo &quot;[publish] created the post's Smarty template\n&quot;;</diff>
      <filename>bin/publish</filename>
    </modified>
    <modified>
      <diff>@@ -45,6 +45,7 @@ $timestamp = strtotime(file_get_contents(
 list($title, $tags, $body) = preg_split(&quot;!\r?\n\r?\n!&quot;,
 	file_get_contents($arg), 3);
 $tags = preg_split('!\s+!', $tags);
+$body = input_footnoterize($body, end($parts));
 blog_publish_smarty($path, $file, $timestamp, $title, $tags, $body,
 	$comments);
 echo &quot;[republish] recreated the post's Smarty template\n&quot;;</diff>
      <filename>bin/republish</filename>
    </modified>
    <modified>
      <diff>@@ -33,7 +33,7 @@ function input_htmlize($text, $begin = '') {
 				htmlentities(strip_tags($text)));
 			foreach ($paragraphs as $j =&gt; $text) {
 				$paragraphs[$j] = implode(&quot;\n$begin&lt;br /&gt;&quot;,
-					preg_split(&quot;!(?:\r?\n)!&quot;, $text));
+					preg_split(&quot;!\r?\n!&quot;, $text));
 			}
 			$sections[$i] = &quot;$begin&lt;p&gt;&quot; . implode(&quot;&lt;/p&gt;\n$begin&lt;p&gt;&quot;,
 				$paragraphs) . &quot;&lt;/p&gt;\n&quot;;
@@ -41,15 +41,19 @@ function input_htmlize($text, $begin = '') {
 
 	}
 
-	# Turn URLs to links
+	return input_htmlize_links(implode('', $sections));
+}
+
+# Turn URLs to links
+function input_htmlize_links($text) {
 	return trim(preg_replace(
 		'!(&lt;a( [^&gt;]+?&gt;|&gt;))&lt;a [^&gt;]+?&gt;([^&gt;]+?)&lt;/a&gt;&lt;/a&gt;!i', '$1$3&lt;/a&gt;',
 		preg_replace_callback(
 		'#(?&lt;=[\s&gt;])(\()?([\w]+?://(?:[\w\\x80-\\xff\#$%&amp;~/\-=?@\[\](+]|[.,;:](?![\s&lt;])|(?(1)\)(?![\s&lt;])|\)))*)#is',
-		'_input_htmlize_link', implode('', $sections))));
+		'_input_htmlize_links', &quot; $text&quot;)));
 
 }
-function _input_htmlize_link($matches) {
+function _input_htmlize_links($matches) {
 	$url = _input_htmlize_cleanurl($matches[2]);
 	if(empty($url)) { return $matches[0]; }
 	else { return &quot;{$matches[1]}&lt;a href=\&quot;$url\&quot;&gt;$url&lt;/a&gt;&quot;; }
@@ -65,3 +69,27 @@ function _input_htmlize_cleanurl($url) {
 	return str_replace(&quot;'&quot;, '&amp;#039;',
 		preg_replace('|&amp;([^#])(?![a-z]{2,8};)|', '&amp;#038;$1', $url));
 }
+
+# Turn IEEE-style footnote links into links with links from the footnotes
+# back into the document
+function input_footnoterize($text, $slug) {
+	$parts = preg_split('!\[\d+\s+([^\]]+)\]!', $text, -1,
+		PREG_SPLIT_DELIM_CAPTURE);
+	$index = 0;
+	$footnotes = array();
+	$ii = sizeof($parts);
+	for ($i = 1; $i &lt; $ii; $i += 2) {
+		++$index;
+		$footnotes[] = &quot;\t&lt;li id=\&quot;f-$slug-$index\&quot;&gt;&quot; .
+			input_htmlize_links($parts[$i]) .
+			&quot; &lt;a href=\&quot;#f-$slug-$index-src\&quot; &quot; .
+			&quot;class=\&quot;footnote-src\&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/li&gt;\n&quot;;
+		$parts[$i] = &quot;&lt;a id=\&quot;f-$slug-$index-src\&quot; &quot; .
+			&quot;href=\&quot;#f-$slug-$index\&quot; class=\&quot;footnote\&quot;&gt;[$index]&lt;/a&gt;&quot;;
+	}
+	if (sizeof($footnotes)) {
+		$footnotes = &quot;\n\n&lt;ol class=\&quot;footnote\&quot;&gt;\n&quot; .
+			implode('', $footnotes) . &quot;&lt;/ol&gt;\n&quot;;
+	} else { $footnotes = ''; }
+	return implode('', $parts) . $footnotes;
+}</diff>
      <filename>include/lib_input.php</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>562199ac06b2cf028f989832474a4e9b80d83ced</id>
    </parent>
  </parents>
  <author>
    <name>Richard Crowley</name>
    <email>r@rcrowley.org</email>
  </author>
  <url>http://github.com/rcrowley/bashpress/commit/71544c0ec6cd07acddfd9288cae224fdea05b235</url>
  <id>71544c0ec6cd07acddfd9288cae224fdea05b235</id>
  <committed-date>2009-03-03T21:47:59-08:00</committed-date>
  <authored-date>2009-03-03T21:47:59-08:00</authored-date>
  <message>Automatically footnoterize IEEE-style links in posts.</message>
  <tree>9e50445444391e35aa809f4ee406f364cc6e1f36</tree>
  <committer>
    <name>Richard Crowley</name>
    <email>r@rcrowley.org</email>
  </committer>
</commit>
