-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start implementing new superfences notation
- Loading branch information
Showing
5 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from pymdownx.superfences import _escape | ||
from pymdownx.superfences import SuperFencesException | ||
|
||
from mkdocs.exceptions import PluginError | ||
from mkdocs_table_reader_plugin.readers import READERS | ||
|
||
def fence_tablereader(source, language, class_name, options, md, **kwargs): | ||
""" | ||
Inspired by https://github.com/facelessuser/pymdown-extensions/blob/8ee5b5caec8f9373e025f50064585fb9d9b71f86/pymdownx/superfences.py#L146 | ||
""" # noqa | ||
# if not some_validation_function(source): | ||
# raise SuperFencesException from PluginError(f"Your vegalite syntax is not valid JSON. Fix:\n\n{source}") | ||
|
||
classes = kwargs["classes"] | ||
id_value = kwargs["id_value"] | ||
attrs = kwargs["attrs"] | ||
|
||
txt_input = str(_escape(source)) | ||
lines = txt_input.split('\n') | ||
user_input = {} | ||
|
||
for line in lines: | ||
key, value = line.split(':', 1) | ||
key = key.strip() | ||
value = value.strip() | ||
user_input[key] = value | ||
|
||
breakpoint() | ||
return READERS[user_input['reader']](user_input['filepath']) | ||
|
||
|
||
# The problem is that this function returns markdown instead of HTML. | ||
# A possible solution might to to use pandas .to_html() instead of .to_markdown() | ||
# this requires adapting our READERS functions though. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"a","b" | ||
40,73 | ||
50,52 | ||
531456,80 | ||
"name","table1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# site title | ||
|
||
|
||
{{ read_csv('assets/tables/basic_table.csv') }} | ||
|
||
```tablereader | ||
filepath: /workspaces/mkdocs-table-reader-plugin/tests/fixtures/superfence/assets/tables/basic_table.csv | ||
reader: read_csv | ||
``` | ||
|
||
This one should fail (typo in reader value) | ||
|
||
<!-- ```tablereader | ||
filepath: assets/tables/basic_table.csv | ||
reader: read_cvs | ||
``` --> | ||
|
||
This one should fail (typo in path) | ||
|
||
<!-- ```tablereader | ||
filepath: table.csv | ||
reader: read_csv | ||
``` --> | ||
|
||
## An HTML table | ||
|
||
<table border="1" class="dataframe"> | ||
<thead> | ||
<tr style="text-align: right;"> | ||
<th></th> | ||
<th>col1</th> | ||
<th>col2</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<th>0</th> | ||
<td>1</td> | ||
<td>4</td> | ||
</tr> | ||
<tr> | ||
<th>1</th> | ||
<td>2</td> | ||
<td>3</td> | ||
</tr> | ||
</tbody> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
site_name: test git_table_reader site | ||
use_directory_urls: false | ||
|
||
plugins: | ||
- search | ||
- table-reader | ||
|
||
markdown_extensions: | ||
- pymdownx.superfences: | ||
custom_fences: | ||
- name: tablereader | ||
class: tablereader | ||
format: !!python/name:mkdocs_table_reader_plugin.fences.fence_tablereader |