<!DOCTYPE html>
<html lang='en'>
<head>
<title>ikiwiki-upstream - Unnamed repository; edit this file to name it for gitweb.</title>
<meta name='generator' content='cgit v1.2.3'/>
<meta name='robots' content='index, nofollow'/>
<link rel='stylesheet' type='text/css' href='/cgit-css/cgit.css'/>
<link rel='stylesheet' type='text/css' href='/cgit-local/local.css'/>
<script type='text/javascript' src='/cgit.js'></script>
<link rel='shortcut icon' href='/favicon.ico'/>
<link rel='alternate' title='Atom feed' href='https://source.jones.dk/ikiwiki-upstream/atom/doc/freesoftware?h=master' type='application/atom+xml'/>
<link rel='vcs-git' href='https://source.jones.dk/ikiwiki-upstream' title='ikiwiki-upstream Git repository'/>
<link rel='vcs-git' href='user@source.jones.dk:ikiwiki-upstream' title='ikiwiki-upstream Git repository'/>
</head>
<body>
<div id='cgit'><table id='header'>
<tr>
<td class='logo' rowspan='2'><a href='/'><img src='/cgit-css/cgit.png' alt='cgit logo'/></a></td>
<td class='main'><a href='/'>index</a> : <a href='/ikiwiki-upstream/'>ikiwiki-upstream</a></td><td class='form'><form method='get'>
<input type='hidden' name='id' value='65077372fab1e6fa30c3d143e4c68123557d8441'/><select name='h' onchange='this.form.submit();'>
<option value='layoutgala'>layoutgala</option>
<option value='master' selected='selected'>master</option>
</select> <input type='submit' value='switch'/></form></td></tr>
<tr><td class='sub'>Unnamed repository; edit this file to name it for gitweb.</td><td class='sub right'>Jonas Smedegaard</td></tr></table>
<table class='tabs'><tr><td>
<a href='/ikiwiki-upstream/'>summary</a><a href='/ikiwiki-upstream/refs/?id=65077372fab1e6fa30c3d143e4c68123557d8441'>refs</a><a class='active' href='/ikiwiki-upstream/log/doc/freesoftware'>log</a><a href='/ikiwiki-upstream/tree/doc/freesoftware?id=65077372fab1e6fa30c3d143e4c68123557d8441'>tree</a><a href='/ikiwiki-upstream/commit/doc/freesoftware?id=65077372fab1e6fa30c3d143e4c68123557d8441'>commit</a><a href='/ikiwiki-upstream/diff/doc/freesoftware?id=65077372fab1e6fa30c3d143e4c68123557d8441'>diff</a></td><td class='form'><form class='right' method='get' action='/ikiwiki-upstream/log/doc/freesoftware'>
<input type='hidden' name='id' value='65077372fab1e6fa30c3d143e4c68123557d8441'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/ikiwiki-upstream/log/?id=65077372fab1e6fa30c3d143e4c68123557d8441'>root</a>/<a href='/ikiwiki-upstream/log/doc?id=65077372fab1e6fa30c3d143e4c68123557d8441'>doc</a>/<a href='/ikiwiki-upstream/log/doc/freesoftware?id=65077372fab1e6fa30c3d143e4c68123557d8441'>freesoftware</a></div><div class='content'><table class='list nowrap'><tr class='nohover'><th class='left'>Age</th><th class='left'>Commit message (<a href='/ikiwiki-upstream/log/doc/freesoftware?id=65077372fab1e6fa30c3d143e4c68123557d8441&amp;showmsg=1'>Expand</a>)</th><th class='left'>Author</th></tr>
ki-upstream/plain/IkiWiki/Plugin/table.pm?id=4cce29259353223b1091a83e03748ae4b34b0796'>plain</a>)
<table summary='blob content' class='blob'>
<tr>
<td class='lines'><pre><code><ol class="hl">
<li id="n_1" class="hl"><span class="hl kwa">package&nbsp;</span>IkiWiki<span class="hl opt">::</span>Plugin<span class="hl opt">::</span>table<span class="hl opt">;</span></li>
<li id="n_2" class="hl"><span class="hl slc"># by Victor Moral &lt;victor&#64;taquiones.net&gt;</span></li>
<li id="n_3" class="hl"></li>
<li id="n_4" class="hl"><span class="hl kwa">use </span>warnings<span class="hl opt">;</span></li>
<li id="n_5" class="hl"><span class="hl kwa">use </span>strict<span class="hl opt">;</span></li>
<li id="n_6" class="hl"><span class="hl kwa">use </span>Encode<span class="hl opt">;</span></li>
<li id="n_7" class="hl"><span class="hl kwa">use </span>IkiWiki <span class="hl num">3.00</span><span class="hl opt">;</span></li>
<li id="n_8" class="hl"></li>
<li id="n_9" class="hl"><span class="hl kwa">sub </span>import <span class="hl opt">{</span></li>
<li id="n_10" class="hl">    hook<span class="hl opt">(</span>type <span class="hl opt">=&gt; </span><span class="hl sng">&quot;getsetup&quot;</span><span class="hl opt">, </span>id <span class="hl opt">=&gt; </span><span class="hl sng">&quot;table&quot;</span><span class="hl opt">, </span>call <span class="hl opt">=&gt; </span>\<span class="hl opt">&amp;</span>getsetup<span class="hl opt">);</span></li>
<li id="n_11" class="hl">    hook<span class="hl opt">(</span>type <span class="hl opt">=&gt; </span><span class="hl sng">&quot;preprocess&quot;</span><span class="hl opt">, </span>id <span class="hl opt">=&gt; </span><span class="hl sng">&quot;table&quot;</span><span class="hl opt">, </span>call <span class="hl opt">=&gt; </span>\<span class="hl opt">&amp;</span>preprocess<span class="hl opt">, </span>scan <span class="hl opt">=&gt; </span><span class="hl num">1</span><span class="hl opt">);</span></li>
<li id="n_12" class="hl"><span class="hl opt">}</span></li>
<li id="n_13" class="hl"></li>
<li id="n_14" class="hl"><span class="hl kwa">sub </span>getsetup <span class="hl opt">() {</span></li>
<li id="n_15" class="hl">    <span class="hl kwa">return</span></li>
<li id="n_16" class="hl">        plugin <span class="hl opt">=&gt; {</span></li>
<li id="n_17" class="hl">            safe <span class="hl opt">=&gt; </span><span class="hl num">1</span><span class="hl opt">,</span></li>
<li id="n_18" class="hl">            rebuild <span class="hl opt">=&gt; </span><span class="hl kwc">undef</span><span class="hl opt">,</span></li>
<li id="n_19" class="hl">        <span class="hl opt">},</span></li>
<li id="n_20" class="hl"><span class="hl opt">}</span></li>
<li id="n_21" class="hl"></li>
<li id="n_22" class="hl"><span class="hl kwa">sub </span>preprocess <span class="hl opt">(&#64;) {</span></li>
<li id="n_23" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">%params </span><span class="hl opt">=(</span></li>
<li id="n_24" class="hl">        format  <span class="hl opt">=&gt; </span><span class="hl sng">&#39;auto&#39;</span><span class="hl opt">,</span></li>
<li id="n_25" class="hl">        header  <span class="hl opt">=&gt; </span><span class="hl sng">&#39;row&#39;</span><span class="hl opt">,</span></li>
<li id="n_26" class="hl">        <span class="hl kwb">&#64;_</span></li>
<li id="n_27" class="hl">    <span class="hl opt">);</span></li>
<li id="n_28" class="hl"></li>
<li id="n_29" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwc">exists </span><span class="hl kwb">$params</span><span class="hl opt">{</span>file<span class="hl opt">}) {</span></li>
<li id="n_30" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(! </span><span class="hl kwc">exists </span><span class="hl kwb">$pagesources</span><span class="hl opt">{</span><span class="hl kwb">$params</span><span class="hl opt">{</span>file<span class="hl opt">}}) {</span></li>
<li id="n_31" class="hl">            error gettext<span class="hl opt">(</span><span class="hl sng">&quot;cannot find file&quot;</span><span class="hl opt">);</span></li>
<li id="n_32" class="hl">        <span class="hl opt">}</span></li>
<li id="n_33" class="hl">        <span class="hl kwb">$params</span><span class="hl opt">{</span>data<span class="hl opt">} = </span>readfile<span class="hl opt">(</span>srcfile<span class="hl opt">(</span><span class="hl kwb">$params</span><span class="hl opt">{</span>file<span class="hl opt">}));</span></li>
<li id="n_34" class="hl">        add_depends<span class="hl opt">(</span><span class="hl kwb">$params</span><span class="hl opt">{</span>page<span class="hl opt">}, </span><span class="hl kwb">$params</span><span class="hl opt">{</span>file<span class="hl opt">});</span></li>
<li id="n_35" class="hl">    <span class="hl opt">}</span></li>
<li id="n_36" class="hl"></li>
<li id="n_37" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(! </span><span class="hl kwc">defined wantarray</span><span class="hl opt">) {</span></li>
<li id="n_38" class="hl">        <span class="hl slc"># scan mode --  if the table uses an external file, need to</span></li>
<li id="n_39" class="hl">        <span class="hl slc"># scan that file too.</span></li>
<li id="n_40" class="hl">        <span class="hl kwa">return unless </span><span class="hl kwc">exists </span><span class="hl kwb">$params</span><span class="hl opt">{</span>file<span class="hl opt">};</span></li>
<li id="n_41" class="hl"></li>
<li id="n_42" class="hl">        IkiWiki<span class="hl opt">::</span>run_hooks<span class="hl opt">(</span>scan <span class="hl opt">=&gt; </span><span class="hl kwa">sub </span><span class="hl opt">{</span></li>
<li id="n_43" class="hl">            shift-<span class="hl opt">&gt;(</span></li>
<li id="n_44" class="hl">                page <span class="hl opt">=&gt; </span><span class="hl kwb">$params</span><span class="hl opt">{</span>page<span class="hl opt">},</span></li>
<li id="n_45" class="hl">                content <span class="hl opt">=&gt; </span><span class="hl kwb">$params</span><span class="hl opt">{</span>data<span class="hl opt">},</span></li>
<li id="n_46" class="hl">            <span class="hl opt">);</span></li>
<li id="n_47" class="hl">        <span class="hl opt">});</span></li>
<li id="n_48" class="hl"></li>
<li id="n_49" class="hl">        <span class="hl slc"># Preprocess in scan-only mode.</span></li>
<li id="n_50" class="hl">        IkiWiki<span class="hl opt">::</span>preprocess<span class="hl opt">(</span><span class="hl kwb">$params</span><span class="hl opt">{</span>page<span class="hl opt">}, </span><span class="hl kwb">$params</span><span class="hl opt">{</span>page<span class="hl opt">}, </span><span class="hl kwb">$params</span><span class="hl opt">{</span>data<span class="hl opt">}, </span><span class="hl num">1</span><span class="hl opt">);</span></li>
<li id="n_51" class="hl"></li>
<li id="n_52" class="hl">        <span class="hl kwa">return</span><span class="hl opt">;</span></li>
<li id="n_53" class="hl">    <span class="hl opt">}</span></li>
<li id="n_54" class="hl"></li>
<li id="n_55" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwc">lc </span><span class="hl kwb">$params</span><span class="hl opt">{</span>format<span class="hl opt">} </span><span class="hl kwc">eq </span><span class="hl sng">&#39;auto&#39;</span><span class="hl opt">) {</span></li>
<li id="n_56" class="hl">        <span class="hl slc"># first try the more simple format</span></li>
<li id="n_57" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span>is_dsv_data<span class="hl opt">(</span><span class="hl kwb">$params</span><span class="hl opt">{</span>data<span class="hl opt">})) {</span></li>
<li id="n_58" class="hl">            <span class="hl kwb">$params</span><span class="hl opt">{</span>format<span class="hl opt">} = </span><span class="hl sng">&#39;dsv&#39;</span><span class="hl opt">;</span></li>
<li id="n_59" class="hl">        <span class="hl opt">}</span></li>
<li id="n_60" class="hl">        <span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_61" class="hl">            <span class="hl kwb">$params</span><span class="hl opt">{</span>format<span class="hl opt">} = </span><span class="hl sng">&#39;csv&#39;</span><span class="hl opt">;</span></li>
<li id="n_62" class="hl">        <span class="hl opt">}</span></li>
<li id="n_63" class="hl">    <span class="hl opt">}</span></li>
<li id="n_64" class="hl"></li>
<li id="n_65" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">&#64;data</span><span class="hl opt">;</span></li>
<li id="n_66" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwc">lc </span><span class="hl kwb">$params</span><span class="hl opt">{</span>format<span class="hl opt">} </span><span class="hl kwc">eq </span><span class="hl sng">&#39;csv&#39;</span><span class="hl opt">) {</span></li>
<li id="n_67" class="hl">        <span class="hl kwb">&#64;data</span><span class="hl opt">=</span>split_csv<span class="hl opt">(</span><span class="hl kwb">$params</span><span class="hl opt">{</span>data<span class="hl opt">},</span></li>
<li id="n_68" class="hl">            <span class="hl kwc">defined </span><span class="hl kwb">$params</span><span class="hl opt">{</span>delimiter<span class="hl opt">} ? </span><span class="hl kwb">$params</span><span class="hl opt">{</span>delimiter<span class="hl opt">} : </span><span class="hl sng">&quot;,&quot;</span><span class="hl opt">,);</span></li>
<li id="n_69" class="hl">        <span class="hl slc"># linkify after parsing since html link quoting can</span></li>
<li id="n_70" class="hl">        <span class="hl slc"># confuse CSV parsing</span></li>
<li id="n_71" class="hl">        <span class="hl kwb">&#64;data</span><span class="hl opt">=</span><span class="hl kwc">map </span><span class="hl opt">{</span></li>
<li id="n_72" class="hl">            <span class="hl opt">[ </span><span class="hl kwc">map </span><span class="hl opt">{</span></li>
<li id="n_73" class="hl">                IkiWiki<span class="hl opt">::</span>linkify<span class="hl opt">(</span><span class="hl kwb">$params</span><span class="hl opt">{</span>page<span class="hl opt">},</span></li>
<li id="n_74" class="hl">                    <span class="hl kwb">$params</span><span class="hl opt">{</span>destpage<span class="hl opt">}, </span><span class="hl kwb">$_</span><span class="hl opt">);</span></li>
<li id="n_75" class="hl">            <span class="hl opt">} </span><span class="hl kwb">&#64;$_ </span><span class="hl opt">]</span></li>
<li id="n_76" class="hl">        <span class="hl opt">} </span><span class="hl kwb">&#64;data</span><span class="hl opt">;</span></li>
<li id="n_77" class="hl">    <span class="hl opt">}</span></li>
<li id="n_78" class="hl">    <span class="hl kwa">elsif </span><span class="hl opt">(</span><span class="hl kwc">lc </span><span class="hl kwb">$params</span><span class="hl opt">{</span>format<span class="hl opt">} </span><span class="hl kwc">eq </span><span class="hl sng">&#39;dsv&#39;</span><span class="hl opt">) {</span></li>
<li id="n_79" class="hl">        <span class="hl slc"># linkify before parsing since wikilinks can contain the</span></li>
<li id="n_80" class="hl">        <span class="hl slc"># delimiter</span></li>
<li id="n_81" class="hl">        <span class="hl kwb">$params</span><span class="hl opt">{</span>data<span class="hl opt">} = </span>IkiWiki<span class="hl opt">::</span>linkify<span class="hl opt">(</span><span class="hl kwb">$params</span><span class="hl opt">{</span>page<span class="hl opt">},</span></li>
<li id="n_82" class="hl">            <span class="hl kwb">$params</span><span class="hl opt">{</span>destpage<span class="hl opt">}, </span><span class="hl kwb">$params</span><span class="hl opt">{</span>data<span class="hl opt">});</span></li>
<li id="n_83" class="hl">        <span class="hl kwb">&#64;data</span><span class="hl opt">=</span>split_dsv<span class="hl opt">(</span><span class="hl kwb">$params</span><span class="hl opt">{</span>data<span class="hl opt">},</span></li>
<li id="n_84" class="hl">            <span class="hl kwc">defined </span><span class="hl kwb">$params</span><span class="hl opt">{</span>delimiter<span class="hl opt">} ? </span><span class="hl kwb">$params</span><span class="hl opt">{</span>delimiter<span class="hl opt">} : </span><span class="hl sng">&quot;|&quot;</span><span class="hl opt">,);</span></li>
<li id="n_85" class="hl">    <span class="hl opt">}</span></li>
<li id="n_86" class="hl">    <span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_87" class="hl">        error gettext<span class="hl opt">(</span><span class="hl sng">&quot;unknown data format&quot;</span><span class="hl opt">);</span></li>
<li id="n_88" class="hl">    <span class="hl opt">}</span></li>
<li id="n_89" class="hl"></li>
<li id="n_90" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$header</span><span class="hl opt">;</span></li>
<li id="n_91" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwc">lc</span><span class="hl opt">(</span><span class="hl kwb">$params</span><span class="hl opt">{</span>header<span class="hl opt">}) </span><span class="hl kwc">eq </span><span class="hl sng">&quot;row&quot;</span> <span class="hl opt">|| </span>IkiWiki<span class="hl opt">::</span>yesno<span class="hl opt">(</span><span class="hl kwb">$params</span><span class="hl opt">{</span>header<span class="hl opt">})) {</span></li>
<li id="n_92" class="hl">        <span class="hl kwb">$header</span><span class="hl opt">=</span><span class="hl kwc">shift </span><span class="hl kwb">&#64;data</span><span class="hl opt">;</span></li>
<li id="n_93" class="hl">    <span class="hl opt">}</span></li>
<li id="n_94" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(! </span><span class="hl kwb">&#64;data</span><span class="hl opt">) {</span></li>
<li id="n_95" class="hl">        error gettext<span class="hl opt">(</span><span class="hl sng">&quot;empty data&quot;</span><span class="hl opt">);</span></li>
<li id="n_96" class="hl">    <span class="hl opt">}</span></li>
<li id="n_97" class="hl"></li>
<li id="n_98" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">&#64;lines</span><span class="hl opt">;</span></li>
<li id="n_99" class="hl">    <span class="hl kwc">push </span><span class="hl kwb">&#64;lines</span><span class="hl opt">, </span><span class="hl kwc">defined </span><span class="hl kwb">$params</span><span class="hl opt">{</span><span class="hl kwa">class</span><span class="hl opt">}</span></li>
<li id="n_100" class="hl">            <span class="hl opt">? </span><span class="hl sng">&quot;&lt;table class=</span><span class="hl esc">\&quot;</span><span class="hl sng">&quot;</span><span class="hl opt">.</span><span class="hl kwb">$params</span><span class="hl opt">{</span><span class="hl kwa">class</span><span class="hl opt">}.</span><span class="hl sng">&#39;&quot;&gt;&#39;</span></li>
<li id="n_101" class="hl">            <span class="hl opt">: </span><span class="hl sng">&#39;&lt;table&gt;&#39;</span><span class="hl opt">;</span></li>
<li id="n_102" class="hl">    <span class="hl kwc">push </span><span class="hl kwb">&#64;lines</span><span class="hl opt">, </span><span class="hl sng">&quot;</span><span class="hl esc">\t</span><span class="hl sng">&lt;thead&gt;&quot;</span><span class="hl opt">,</span></li>
<li id="n_103" class="hl">        genrow<span class="hl opt">(</span>\<span class="hl kwb">%params</span><span class="hl opt">, </span><span class="hl sng">&quot;th&quot;</span><span class="hl opt">, </span><span class="hl kwb">&#64;$header</span><span class="hl opt">),</span></li>
<li id="n_104" class="hl">            <span class="hl sng">&quot;</span><span class="hl esc">\t</span><span class="hl sng">&lt;/thead&gt;&quot;</span> <span class="hl kwa">if </span><span class="hl kwc">defined </span><span class="hl kwb">$header</span><span class="hl opt">;</span></li>
<li id="n_105" class="hl">    <span class="hl kwc">push </span><span class="hl kwb">&#64;lines</span><span class="hl opt">, </span><span class="hl sng">&quot;</span><span class="hl esc">\t</span><span class="hl sng">&lt;tbody&gt;&quot;</span> <span class="hl kwa">if </span><span class="hl kwc">defined </span><span class="hl kwb">$header</span><span class="hl opt">;</span></li>
<li id="n_106" class="hl">    <span class="hl kwc">push </span><span class="hl kwb">&#64;lines</span><span class="hl opt">, </span>genrow<span class="hl opt">(</span>\<span class="hl kwb">%params</span><span class="hl opt">, </span><span class="hl sng">&quot;td&quot;</span><span class="hl opt">, </span><span class="hl kwb">&#64;$_</span><span class="hl opt">) </span><span class="hl kwa">foreach </span><span class="hl kwb">&#64;data</span><span class="hl opt">;</span></li>
<li id="n_107" class="hl">    <span class="hl kwc">push </span><span class="hl kwb">&#64;lines</span><span class="hl opt">, </span><span class="hl sng">&quot;</span><span class="hl esc">\t</span><span class="hl sng">&lt;/tbody&gt;&quot;</span> <span class="hl kwa">if </span><span class="hl kwc">defined </span><span class="hl kwb">$header</span><span class="hl opt">;</span></li>
<li id="n_108" class="hl">    <span class="hl kwc">push </span><span class="hl kwb">&#64;lines</span><span class="hl opt">, </span><span class="hl sng">&#39;&lt;/table&gt;&#39;</span><span class="hl opt">;</span></li>
<li id="n_109" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$html </span><span class="hl opt">= </span><span class="hl kwc">join</span><span class="hl opt">(</span><span class="hl sng">&quot;</span><span class="hl esc">\n</span><span class="hl sng">&quot;</span><span class="hl opt">, </span><span class="hl kwb">&#64;lines</span><span class="hl opt">);</span></li>
<li id="n_110" class="hl"></li>
<li id="n_111" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwc">exists </span><span class="hl kwb">$params</span><span class="hl opt">{</span>file<span class="hl opt">}) {</span></li>
<li id="n_112" class="hl">        <span class="hl kwa">return </span><span class="hl kwb">$html</span><span class="hl opt">.</span><span class="hl sng">&quot;</span><span class="hl esc">\n\n</span><span class="hl sng">&quot;</span><span class="hl opt">.</span></li>
<li id="n_113" class="hl">            htmllink<span class="hl opt">(</span><span class="hl kwb">$params</span><span class="hl opt">{</span>page<span class="hl opt">}, </span><span class="hl kwb">$params</span><span class="hl opt">{</span>destpage<span class="hl opt">}, </span><span class="hl kwb">$params</span><span class="hl opt">{</span>file<span class="hl opt">},</span></li>
<li id="n_114" class="hl">                linktext <span class="hl opt">=&gt; </span>gettext<span class="hl opt">(</span><span class="hl sng">&#39;Direct data download&#39;</span><span class="hl opt">));</span></li>
<li id="n_115" class="hl">    <span class="hl opt">}</span></li>
<li id="n_116" class="hl">    <span class="hl kwa">else </span><span class="hl opt">{  </span></li>
<li id="n_117" class="hl">        <span class="hl kwa">return </span><span class="hl kwb">$html</span><span class="hl opt">;</span></li>
<li id="n_118" class="hl">    <span class="hl opt">}            </span></li>
<li id="n_119" class="hl"><span class="hl opt">}</span></li>
<li id="n_120" class="hl"></li>
<li id="n_121" class="hl"><span class="hl kwa">sub </span>is_dsv_data <span class="hl opt">($) {</span></li>
<li id="n_122" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$text </span><span class="hl opt">= </span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_123" class="hl"></li>
<li id="n_124" class="hl">    <span class="hl kwc">my </span><span class="hl opt">(</span><span class="hl kwb">$line</span><span class="hl opt">) = </span><span class="hl kwc">split</span><span class="hl opt">(</span><span class="hl kwd">/\n/</span><span class="hl opt">, </span><span class="hl kwb">$text</span><span class="hl opt">);</span></li>
<li id="n_125" class="hl">    <span class="hl kwa">return </span><span class="hl kwb">$line </span><span class="hl opt">=~ </span><span class="hl kwd">m{.+\|}</span><span class="hl opt">;</span></li>
<li id="n_126" class="hl"><span class="hl opt">}</span></li>
<li id="n_127" class="hl"></li>
<li id="n_128" class="hl"><span class="hl kwa">sub </span>split_csv <span class="hl opt">(</span><span class="hl kwb">$$</span><span class="hl opt">) {</span></li>
<li id="n_129" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">&#64;text_lines </span><span class="hl opt">= </span><span class="hl kwc">split</span><span class="hl opt">(</span><span class="hl kwd">/\n/</span><span class="hl opt">, </span><span class="hl kwc">shift</span><span class="hl opt">);</span></li>
<li id="n_130" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$delimiter </span><span class="hl opt">= </span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_131" class="hl"></li>
<li id="n_132" class="hl">    <span class="hl kwc">eval </span><span class="hl sng">q{use Text::CSV}</span><span class="hl opt">;</span></li>
<li id="n_133" class="hl">    error<span class="hl opt">(</span><span class="hl kwb">$&#64;</span><span class="hl opt">) </span><span class="hl kwa">if </span><span class="hl kwb">$&#64;</span><span class="hl opt">;</span></li>
<li id="n_134" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$csv </span><span class="hl opt">= </span>Text<span class="hl opt">::</span>CSV-<span class="hl opt">&gt;</span><span class="hl kwd">new</span><span class="hl opt">({ </span></li>
<li id="n_135" class="hl">        sep_char    <span class="hl opt">=&gt; </span><span class="hl kwb">$delimiter</span><span class="hl opt">,</span></li>
<li id="n_136" class="hl">        binary      <span class="hl opt">=&gt; </span><span class="hl num">1</span><span class="hl opt">,</span></li>
<li id="n_137" class="hl">        allow_loose_quotes <span class="hl opt">=&gt; </span><span class="hl num">1</span><span class="hl opt">,</span></li>
<li id="n_138" class="hl">    <span class="hl opt">}) || </span>error<span class="hl opt">(</span><span class="hl sng">&quot;could not create a Text::CSV object&quot;</span><span class="hl opt">);</span></li>
<li id="n_139" class="hl">    </li>
<li id="n_140" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$l</span><span class="hl opt">=</span><span class="hl num">0</span><span class="hl opt">;</span></li>
<li id="n_141" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">&#64;data</span><span class="hl opt">;</span></li>
<li id="n_142" class="hl">    <span class="hl kwa">foreach </span><span class="hl kwc">my </span><span class="hl kwb">$line </span><span class="hl opt">(</span><span class="hl kwb">&#64;text_lines</span><span class="hl opt">) {</span></li>
<li id="n_143" class="hl">        <span class="hl kwb">$l++</span><span class="hl opt">;</span></li>
<li id="n_144" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$csv</span><span class="hl opt">-&gt;</span><span class="hl kwd">parse</span><span class="hl opt">(</span><span class="hl kwb">$line</span><span class="hl opt">)) {</span></li>
<li id="n_145" class="hl">            <span class="hl kwc">push</span><span class="hl opt">(</span><span class="hl kwb">&#64;data</span><span class="hl opt">, [ </span><span class="hl kwc">map </span><span class="hl opt">{ </span>decode_utf8 <span class="hl kwb">$_ </span><span class="hl opt">} </span><span class="hl kwb">$csv</span><span class="hl opt">-&gt;</span><span class="hl kwd">fields</span><span class="hl opt">() ]);</span></li>
<li id="n_146" class="hl">        <span class="hl opt">}</span></li>
<li id="n_147" class="hl">        <span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_148" class="hl">            debug<span class="hl opt">(</span><span class="hl kwc">sprintf</span><span class="hl opt">(</span>gettext<span class="hl opt">(</span><span class="hl sng">&#39;parse fail at line </span><span class="hl ipl">%d</span><span class="hl sng">: </span><span class="hl ipl">%s</span><span class="hl sng">&#39;</span><span class="hl opt">), </span></li>
<li id="n_149" class="hl">                <span class="hl kwb">$l</span><span class="hl opt">, </span><span class="hl kwb">$csv</span><span class="hl opt">-&gt;</span><span class="hl kwd">error_input</span><span class="hl opt">()));</span></li>
<li id="n_150" class="hl">        <span class="hl opt">}</span></li>
<li id="n_151" class="hl">    <span class="hl opt">}</span></li>
<li id="n_152" class="hl"></li>
<li id="n_153" class="hl">    <span class="hl kwa">return </span><span class="hl kwb">&#64;data</span><span class="hl opt">;</span></li>
<li id="n_154" class="hl"><span class="hl opt">}</span></li>
<li id="n_155" class="hl"></li>
<li id="n_156" class="hl"><span class="hl kwa">sub </span>split_dsv <span class="hl opt">(</span><span class="hl kwb">$$</span><span class="hl opt">) {</span></li>
<li id="n_157" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">&#64;text_lines </span><span class="hl opt">= </span><span class="hl kwc">split</span><span class="hl opt">(</span><span class="hl kwd">/\n/</span><span class="hl opt">, </span><span class="hl kwc">shift</span><span class="hl opt">);</span></li>
<li id="n_158" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$delimiter </span><span class="hl opt">= </span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_159" class="hl">    <span class="hl kwb">$delimiter</span><span class="hl opt">=</span><span class="hl sng">&quot;|&quot;</span> <span class="hl kwa">unless </span><span class="hl kwc">defined </span><span class="hl kwb">$delimiter</span><span class="hl opt">;</span></li>
<li id="n_160" class="hl"></li>
<li id="n_161" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">&#64;data</span><span class="hl opt">;</span></li>
<li id="n_162" class="hl">    <span class="hl kwa">foreach </span><span class="hl kwc">my </span><span class="hl kwb">$line </span><span class="hl opt">(</span><span class="hl kwb">&#64;text_lines</span><span class="hl opt">) {</span></li>
<li id="n_163" class="hl">        <span class="hl kwc">push </span><span class="hl kwb">&#64;data</span><span class="hl opt">, [ </span><span class="hl kwc">split</span><span class="hl opt">(</span><span class="hl kwd">/\Q$delimiter\E/</span><span class="hl opt">, </span><span class="hl kwb">$line</span><span class="hl opt">, -</span><span class="hl num">1</span><span class="hl opt">) ];</span></li>
<li id="n_164" class="hl">    <span class="hl opt">}</span></li>
<li id="n_165" class="hl">    </li>
<li id="n_166" class="hl">    <span class="hl kwa">return </span><span class="hl kwb">&#64;data</span><span class="hl opt">;</span></li>
<li id="n_167" class="hl"><span class="hl opt">}</span></li>
<li id="n_168" class="hl"></li>
<li id="n_169" class="hl"><span class="hl kwa">sub </span>genrow <span class="hl opt">(</span><span class="hl kwb">$&#64;</span><span class="hl opt">) {</span></li>
<li id="n_170" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">%params</span><span class="hl opt">=%{</span><span class="hl kwc">shift</span><span class="hl opt">()};</span></li>
<li id="n_171" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$elt </span><span class="hl opt">= </span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_172" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">&#64;data </span><span class="hl opt">= </span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_173" class="hl"></li>
<li id="n_174" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$page</span><span class="hl opt">=</span><span class="hl kwb">$params</span><span class="hl opt">{</span>page<span class="hl opt">};</span></li>
<li id="n_175" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$destpage</span><span class="hl opt">=</span><span class="hl kwb">$params</span><span class="hl opt">{</span>destpage<span class="hl opt">};</span></li>
<li id="n_176" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$type</span><span class="hl opt">=</span>pagetype<span class="hl opt">(</span><span class="hl kwb">$pagesources</span><span class="hl opt">{</span><span class="hl kwb">$page</span><span class="hl opt">});</span></li>
<li id="n_177" class="hl"></li>
<li id="n_178" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">&#64;ret</span><span class="hl opt">;</span></li>
<li id="n_179" class="hl">    <span class="hl kwc">push </span><span class="hl kwb">&#64;ret</span><span class="hl opt">, </span><span class="hl sng">&quot;</span><span class="hl esc">\t\t</span><span class="hl sng">&lt;tr&gt;&quot;</span><span class="hl opt">;</span></li>
<li id="n_180" class="hl">    <span class="hl kwa">for </span><span class="hl opt">(</span><span class="hl kwc">my </span><span class="hl kwb">$x</span><span class="hl opt">=</span><span class="hl num">0</span><span class="hl opt">; </span><span class="hl kwb">$x </span><span class="hl opt">&lt; </span><span class="hl kwb">&#64;data</span><span class="hl opt">; </span><span class="hl kwb">$x++</span><span class="hl opt">) {</span></li>
<li id="n_181" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$cell</span><span class="hl opt">=</span>IkiWiki<span class="hl opt">::</span>htmlize<span class="hl opt">(</span><span class="hl kwb">$page</span><span class="hl opt">, </span><span class="hl kwb">$destpage</span><span class="hl opt">, </span><span class="hl kwb">$type</span><span class="hl opt">,</span></li>
<li id="n_182" class="hl">                 IkiWiki<span class="hl opt">::</span>preprocess<span class="hl opt">(</span><span class="hl kwb">$page</span><span class="hl opt">, </span><span class="hl kwb">$destpage</span><span class="hl opt">, </span><span class="hl kwb">$data</span><span class="hl opt">[</span><span class="hl kwb">$x</span><span class="hl opt">]));</span></li>
<li id="n_183" class="hl"></li>
<li id="n_184" class="hl">        <span class="hl slc"># automatic colspan for empty cells</span></li>
<li id="n_185" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$colspan</span><span class="hl opt">=</span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_186" class="hl">        <span class="hl kwa">while </span><span class="hl opt">(</span><span class="hl kwb">$x+1 </span><span class="hl opt">&lt; </span><span class="hl kwb">&#64;data </span><span class="hl opt">&amp;&amp; </span><span class="hl kwb">$data</span><span class="hl opt">[</span><span class="hl kwb">$x+1</span><span class="hl opt">] </span><span class="hl kwc">eq </span><span class="hl sng">&#39;&#39;</span><span class="hl opt">) {</span></li>
<li id="n_187" class="hl">            <span class="hl kwb">$x++</span><span class="hl opt">;</span></li>
<li id="n_188" class="hl">            <span class="hl kwb">$colspan++</span><span class="hl opt">;</span></li>
<li id="n_189" class="hl">        <span class="hl opt">}</span></li>
<li id="n_190" class="hl"></li>
<li id="n_191" class="hl">        <span class="hl slc"># check if the first column should be a header</span></li>
<li id="n_192" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$e</span><span class="hl opt">=</span><span class="hl kwb">$elt</span><span class="hl opt">;</span></li>
<li id="n_193" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$x </span><span class="hl opt">== </span><span class="hl num">0 </span><span class="hl opt">&amp;&amp; </span><span class="hl kwc">lc</span><span class="hl opt">(</span><span class="hl kwb">$params</span><span class="hl opt">{</span>header<span class="hl opt">}) </span><span class="hl kwc">eq </span><span class="hl sng">&quot;column&quot;</span><span class="hl opt">) {</span></li>
<li id="n_194" class="hl">            <span class="hl kwb">$e</span><span class="hl opt">=</span><span class="hl sng">&quot;th&quot;</span><span class="hl opt">;</span></li>
<li id="n_195" class="hl">        <span class="hl opt">}</span></li>
<li id="n_196" class="hl"></li>
<li id="n_197" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$colspan </span><span class="hl opt">&gt; </span><span class="hl num">1</span><span class="hl opt">) {</span></li>
<li id="n_198" class="hl">            <span class="hl kwc">push </span><span class="hl kwb">&#64;ret</span><span class="hl opt">, </span><span class="hl sng">&quot;</span><span class="hl esc">\t\t\t</span><span class="hl sng">&lt;</span><span class="hl ipl">$e </span><span class="hl sng">colspan=</span><span class="hl esc">\&quot;</span><span class="hl sng"></span><span class="hl ipl">$colspan</span><span class="hl sng"></span><span class="hl esc">\&quot;</span><span class="hl sng">&gt;</span><span class="hl ipl">$cell</span><span class="hl sng">&lt;/</span><span class="hl ipl">$e</span><span class="hl sng">&gt;&quot;</span></li>
<li id="n_199" class="hl">        <span class="hl opt">}</span></li>
<li id="n_200" class="hl">        <span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_201" class="hl">            <span class="hl kwc">push </span><span class="hl kwb">&#64;ret</span><span class="hl opt">, </span><span class="hl sng">&quot;</span><span class="hl esc">\t\t\t</span><span class="hl sng">&lt;</span><span class="hl ipl">$e</span><span class="hl sng">&gt;</span><span class="hl ipl">$cell</span><span class="hl sng">&lt;/</span><span class="hl ipl">$e</span><span class="hl sng">&gt;&quot;</span></li>
<li id="n_202" class="hl">        <span class="hl opt">}</span></li>
<li id="n_203" class="hl">    <span class="hl opt">}</span></li>
<li id="n_204" class="hl">    <span class="hl kwc">push </span><span class="hl kwb">&#64;ret</span><span class="hl opt">, </span><span class="hl sng">&quot;</span><span class="hl esc">\t\t</span><span class="hl sng">&lt;/tr&gt;&quot;</span><span class="hl opt">;</span></li>
<li id="n_205" class="hl"></li>
<li id="n_206" class="hl">    <span class="hl kwa">return </span><span class="hl kwb">&#64;ret</span><span class="hl opt">;</span></li>
<li id="n_207" class="hl"><span class="hl opt">}</span></li>
<li id="n_208" class="hl"></li>
<li id="n_209" class="hl"><span class="hl num">1</span></li>
</ol></code></pre></td></tr></table>
</div> <!-- class=content -->
<div class='footer'>generated by <a href='https://git.zx2c4.com/cgit/about/'>cgit v1.2.3</a> (<a href='https://git-scm.com/'>git 2.46.0</a>) at 2025-05-31 05:20:34 +0000</div>
</div> <!-- id=cgit -->
</body>
</html>
