Skip to content

Commit 1868264

Browse files
authored
Deployed 47ac5d5 with MkDocs version: 1.6.0
1 parent ef14936 commit 1868264

13 files changed

Lines changed: 103 additions & 28 deletions

File tree

404.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@
454454

455455

456456
<span class="md-ellipsis">
457-
Using jinja2
457+
Use jinja2 for automation
458458
</span>
459459

460460

assets/tables/markdown_table/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@
454454

455455

456456
<span class="md-ellipsis">
457-
Using jinja2
457+
Use jinja2 for automation
458458
</span>
459459

460460

howto/alternatives/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@
468468

469469

470470
<span class="md-ellipsis">
471-
Using jinja2
471+
Use jinja2 for automation
472472
</span>
473473

474474

howto/customize_tables/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@
544544

545545

546546
<span class="md-ellipsis">
547-
Using jinja2
547+
Use jinja2 for automation
548548
</span>
549549

550550

howto/docker/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@
468468

469469

470470
<span class="md-ellipsis">
471-
Using jinja2
471+
Use jinja2 for automation
472472
</span>
473473

474474

howto/preprocess_tables/index.html

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@
526526

527527

528528
<span class="md-ellipsis">
529-
Using jinja2
529+
Use jinja2 for automation
530530
</span>
531531

532532

@@ -735,6 +735,10 @@ <h2 id="combine-a-directory-of-tables-into-a-single-larger-table">Combine a dire
735735
</div>
736736
</div>
737737
</div>
738+
<div class="admonition note">
739+
<p class="admonition-title">Alternative: use jinja</p>
740+
<p>You can also use jinja2 to display a list of tables. See how to <a href="../use_jinja2/">use jinja2 for automation</a>.</p>
741+
</div>
738742
<h2 id="download-a-table-from-an-api">Download a table from an API</h2>
739743
<div class="tabbed-set tabbed-alternate" data-tabs="2:4"><input checked="checked" id="__tabbed_2_1" name="__tabbed_2" type="radio" /><input id="__tabbed_2_2" name="__tabbed_2" type="radio" /><input id="__tabbed_2_3" name="__tabbed_2" type="radio" /><input id="__tabbed_2_4" name="__tabbed_2" type="radio" /><div class="tabbed-labels"><label for="__tabbed_2_1">hooks.py</label><label for="__tabbed_2_2">index.md</label><label for="__tabbed_2_3">mkdocs.yml</label><label for="__tabbed_2_4">Project structure</label></div>
740744
<div class="tabbed-content">
@@ -794,7 +798,7 @@ <h2 id="download-a-table-from-an-api">Download a table from an API</h2>
794798
<span class="md-icon" title="Last update">
795799
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1-2.1-2M12.5 7v5.2l4 2.4-1 1L11 13V7h1.5M11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2v1.8Z"/></svg>
796800
</span>
797-
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-timeago"><span class="timeago" datetime="2023-01-30T14:01:40+01:00" locale="en"></span></span><span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-iso_date">2023-01-30</span>
801+
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-timeago"><span class="timeago" datetime="2024-08-26T16:20:18+02:00" locale="en"></span></span><span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-iso_date">2024-08-26</span>
798802
</span>
799803

800804

@@ -805,12 +809,13 @@ <h2 id="download-a-table-from-an-api">Download a table from an API</h2>
805809
<span class="md-source-file__fact">
806810
<span class="md-icon" title="Contributors">
807811

808-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 4a4 4 0 0 1 4 4 4 4 0 0 1-4 4 4 4 0 0 1-4-4 4 4 0 0 1 4-4m0 10c4.42 0 8 1.79 8 4v2H4v-2c0-2.21 3.58-4 8-4Z"/></svg>
812+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 5.5A3.5 3.5 0 0 1 15.5 9a3.5 3.5 0 0 1-3.5 3.5A3.5 3.5 0 0 1 8.5 9 3.5 3.5 0 0 1 12 5.5M5 8c.56 0 1.08.15 1.53.42-.15 1.43.27 2.85 1.13 3.96C7.16 13.34 6.16 14 5 14a3 3 0 0 1-3-3 3 3 0 0 1 3-3m14 0a3 3 0 0 1 3 3 3 3 0 0 1-3 3c-1.16 0-2.16-.66-2.66-1.62a5.536 5.536 0 0 0 1.13-3.96c.45-.27.97-.42 1.53-.42M5.5 18.25c0-2.07 2.91-3.75 6.5-3.75s6.5 1.68 6.5 3.75V20h-13v-1.75M0 20v-1.5c0-1.39 1.89-2.56 4.45-2.9-.59.68-.95 1.62-.95 2.65V20H0m24 0h-3.5v-1.75c0-1.03-.36-1.97-.95-2.65 2.56.34 4.45 1.51 4.45 2.9V20Z"/></svg>
809813

810814
</span>
811815
<nav>
812816

813-
<a href="mailto:tim.vink@allianzdirect.nl">Tim Vink</a>
817+
<a href="mailto:tim.vink@allianzdirect.nl">Tim Vink</a>,
818+
<a href="mailto:vinktim@gmail.com">Tim Vink</a>
814819
</nav>
815820
</span>
816821

@@ -827,7 +832,7 @@ <h2 id="download-a-table-from-an-api">Download a table from an API</h2>
827832

828833
<div class="md-source-date">
829834
<small>
830-
Authors: <span class='git-page-authors git-authors'><a href='mailto:tim.vink@allianzdirect.nl'>Tim Vink</a></span>
835+
Authors: <span class='git-page-authors git-authors'><a href='mailto:tim.vink@allianzdirect.nl'>Tim Vink</a>, <a href='mailto:vinktim@gmail.com'>Tim Vink</a></span>
831836
</small>
832837
</div>
833838

howto/project_structure/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@
468468

469469

470470
<span class="md-ellipsis">
471-
Using jinja2
471+
Use jinja2 for automation
472472
</span>
473473

474474

howto/use_jinja2/index.html

Lines changed: 83 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323

2424

25-
<title>Using jinja2 - mkdocs-table-reader-plugin</title>
25+
<title>Use jinja2 for automation - mkdocs-table-reader-plugin</title>
2626

2727

2828

@@ -76,7 +76,7 @@
7676
<div data-md-component="skip">
7777

7878

79-
<a href="#using-jinja2" class="md-skip">
79+
<a href="#use-jinja2-for-automation" class="md-skip">
8080
Skip to content
8181
</a>
8282

@@ -112,7 +112,7 @@
112112
<div class="md-header__topic" data-md-component="header-topic">
113113
<span class="md-ellipsis">
114114

115-
Using jinja2
115+
Use jinja2 for automation
116116

117117
</span>
118118
</div>
@@ -477,7 +477,7 @@
477477

478478

479479
<span class="md-ellipsis">
480-
Using jinja2
480+
Use jinja2 for automation
481481
</span>
482482

483483

@@ -488,7 +488,7 @@
488488

489489

490490
<span class="md-ellipsis">
491-
Using jinja2
491+
Use jinja2 for automation
492492
</span>
493493

494494

@@ -510,9 +510,27 @@
510510
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
511511

512512
<li class="md-nav__item">
513-
<a href="#indented-content-like-content-tabs" class="md-nav__link">
513+
<a href="#dynamically-load-a-list-of-tables" class="md-nav__link">
514514
<span class="md-ellipsis">
515-
Indented content like content tabs
515+
Dynamically load a list of tables
516+
</span>
517+
</a>
518+
519+
</li>
520+
521+
<li class="md-nav__item">
522+
<a href="#insert-tables-into-content-tabs" class="md-nav__link">
523+
<span class="md-ellipsis">
524+
Insert tables into content tabs
525+
</span>
526+
</a>
527+
528+
</li>
529+
530+
<li class="md-nav__item">
531+
<a href="#recursively-insert-an-entire-directory-of-tables" class="md-nav__link">
532+
<span class="md-ellipsis">
533+
Recursively insert an entire directory of tables
516534
</span>
517535
</a>
518536

@@ -644,9 +662,27 @@
644662
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
645663

646664
<li class="md-nav__item">
647-
<a href="#indented-content-like-content-tabs" class="md-nav__link">
665+
<a href="#dynamically-load-a-list-of-tables" class="md-nav__link">
666+
<span class="md-ellipsis">
667+
Dynamically load a list of tables
668+
</span>
669+
</a>
670+
671+
</li>
672+
673+
<li class="md-nav__item">
674+
<a href="#insert-tables-into-content-tabs" class="md-nav__link">
648675
<span class="md-ellipsis">
649-
Indented content like content tabs
676+
Insert tables into content tabs
677+
</span>
678+
</a>
679+
680+
</li>
681+
682+
<li class="md-nav__item">
683+
<a href="#recursively-insert-an-entire-directory-of-tables" class="md-nav__link">
684+
<span class="md-ellipsis">
685+
Recursively insert an entire directory of tables
650686
</span>
651687
</a>
652688

@@ -668,14 +704,15 @@
668704

669705

670706

671-
<h1 id="using-jinja2">Using jinja2</h1>
707+
<h1 id="use-jinja2-for-automation">Use jinja2 for automation</h1>
672708
<p><code>table-reader</code> supports <a href="https://mkdocs-macros-plugin.readthedocs.io/en/latest/"><code>mkdocs-macros-plugin</code></a>, which enables you to use jinja2 syntax inside markdown files (among other things).</p>
673709
<p>To enable <code>macros</code>, specify the plugin <em>before</em> <code>table-reader</code> in your <code>mkdocs.yml</code> file:</p>
674710
<div class="highlight"><pre><span></span><code><span class="nt">plugins</span><span class="p">:</span>
675711
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">macros</span>
676712
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">table-reader</span>
677713
</code></pre></div>
678-
<p>Now you can do cool things like dynamically load a list of tables:</p>
714+
<p>Now you can do cool things like:</p>
715+
<h2 id="dynamically-load-a-list-of-tables">Dynamically load a list of tables</h2>
679716
<div class="highlight"><pre><span></span><code><span class="gh"># index.md</span>
680717

681718
{% set table_names = [&quot;basic_table.csv&quot;,&quot;basic_table2.csv&quot;] %}
@@ -685,7 +722,7 @@ <h1 id="using-jinja2">Using jinja2</h1>
685722

686723
{% endfor %}
687724
</code></pre></div>
688-
<h2 id="indented-content-like-content-tabs">Indented content like content tabs</h2>
725+
<h2 id="insert-tables-into-content-tabs">Insert tables into content tabs</h2>
689726
<p>If you inserted content has multiple lines, then indentation will be not be retained beyond the first line. This means things like <a href="https://squidfunk.github.io/mkdocs-material/reference/content-tabs/#usage">content tabs</a> will not work as expected.</p>
690727
<p>To fix that, you can use the custom <em>filter</em> <code>add_indendation</code> (a filter add to <code>macros</code> by <code>table-reader</code> plugin). For example:</p>
691728
<div class="tabbed-set tabbed-alternate" data-tabs="1:2"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><input id="__tabbed_1_2" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">index.md</label><label for="__tabbed_1_2">mkdocs.yml</label></div>
@@ -726,6 +763,39 @@ <h2 id="indented-content-like-content-tabs">Indented content like content tabs</
726763
<p>To avoid the tables being inserted into the code example, we replaced <code>{{</code> with <code>{ {</code>.
727764
If you copy this example, make sure to fix.</p>
728765
</div>
766+
<h2 id="recursively-insert-an-entire-directory-of-tables">Recursively insert an entire directory of tables</h2>
767+
<p><a href="https://mkdocs-macros-plugin.readthedocs.io/en/latest/"><code>mkdocs-macros-plugin</code></a> enables you to define additional functions (called <em>macros</em>) that you will be able to use within your markdown files.
768+
See their documentation on how to set this up. Here's an example with some functions to interact with the filesystem:</p>
769+
<div class="highlight"><pre><span></span><code><span class="k">def</span> <span class="nf">define_env</span><span class="p">(</span><span class="n">env</span><span class="p">):</span>
770+
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
771+
<span class="sd"> Register additional mkdocs-macros-plugin functions that can be used as macros in markdown files.</span>
772+
<span class="sd"> &quot;&quot;&quot;</span>
773+
<span class="nd">@env</span><span class="o">.</span><span class="n">macro</span>
774+
<span class="k">def</span> <span class="nf">listdir</span><span class="p">(</span><span class="n">path</span><span class="p">):</span>
775+
<span class="k">return</span> <span class="n">os</span><span class="o">.</span><span class="n">listdir</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
776+
777+
<span class="nd">@env</span><span class="o">.</span><span class="n">macro</span>
778+
<span class="k">def</span> <span class="nf">path_exists</span><span class="p">(</span><span class="n">path</span><span class="p">):</span>
779+
<span class="k">return</span> <span class="n">Path</span><span class="p">(</span><span class="n">path</span><span class="p">)</span><span class="o">.</span><span class="n">exists</span><span class="p">()</span>
780+
781+
<span class="nd">@env</span><span class="o">.</span><span class="n">macro</span>
782+
<span class="k">def</span> <span class="nf">is_file</span><span class="p">(</span><span class="n">path</span><span class="p">):</span>
783+
<span class="k">return</span> <span class="n">Path</span><span class="p">(</span><span class="n">path</span><span class="p">)</span><span class="o">.</span><span class="n">is_file</span><span class="p">()</span>
784+
</code></pre></div>
785+
<p>Now you could do something like:</p>
786+
<div class="highlight"><pre><span></span><code><span class="gh"># index.md</span>
787+
788+
{% for table_name in listdir(&#39;docs/assets/my_tables&quot;) %}
789+
790+
{ { read_csv(table_name) }}
791+
792+
{% endfor %}
793+
</code></pre></div>
794+
<div class="admonition note">
795+
<p class="admonition-title">Note the space in { {</p>
796+
<p>To avoid the tables being inserted into the code example, we replaced <code>{{</code> with <code>{ {</code>.
797+
If you copy this example, make sure to fix.</p>
798+
</div>
729799

730800

731801

@@ -746,7 +816,7 @@ <h2 id="indented-content-like-content-tabs">Indented content like content tabs</
746816
<span class="md-icon" title="Last update">
747817
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1-2.1-2M12.5 7v5.2l4 2.4-1 1L11 13V7h1.5M11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2v1.8Z"/></svg>
748818
</span>
749-
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-timeago"><span class="timeago" datetime="2024-08-15T15:49:57+02:00" locale="en"></span></span><span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-iso_date">2024-08-15</span>
819+
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-timeago"><span class="timeago" datetime="2024-08-26T16:20:18+02:00" locale="en"></span></span><span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-iso_date">2024-08-26</span>
750820
</span>
751821

752822

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@
532532

533533

534534
<span class="md-ellipsis">
535-
Using jinja2
535+
Use jinja2 for automation
536536
</span>
537537

538538

options/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@
465465

466466

467467
<span class="md-ellipsis">
468-
Using jinja2
468+
Use jinja2 for automation
469469
</span>
470470

471471

0 commit comments

Comments
 (0)