Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Markdown: Wrap tables by div

Started by Muut Archive 10 years ago · 5 replies · 2077 views
10 years ago

Hi,

My Grav template has special CSS classes to show tables in different styles.

In my page, I have many tables, look like this:

TXT
#### Table 1

Col 1 | Col 2 | Col 3
Sample | Sample | Sample
Sample | Sample | Sample

#### Table 2

Col 1 | Col 2 | Col 3
Sample | Sample | Sample
Sample | Sample | Sample

#### Table 3

Col 1 | Col 2 | Col 3
Sample | Sample | Sample
Sample | Sample | Sample
-```

In order to show the tables in a specific style, I need to put it inside a <div>, the HTML should look like this:

<div class="table-style-1">
<table>
</table>
</div>

<div class="table-style-2">
<table>
</table>
</div>

TXT

In my page, I can't add HTML, this is not working:

Table 1

<div class="table-style-1">
Col 1 | Col 2 | Col 3
Sample | Sample | Sample
Sample | Sample | Sample
</div>

TXT


My only solution for now is leaving my page empty. I hard-code the tables's HTML code in my html.twig file, but this gives end-users no ability to modify the tables's content because they do this via admin plugin, they only can modify pages, not theme.

Do you have any solution for my issue? Thank you!
10 years ago

Enable Parsedown Extra in the page header, and add markdown="1" to the wrapping div:

YAML
markdown:
    extra: true
HTML

#### Table 1

<div class="table-style-1" markdown="1">
| Tables        | Are           | Cool  |
| ------------- |:-------------:| -----:|
| col 3 is      | right-aligned | $1600 |
| col 2 is      | centered      |   $12 |
| zebra stripes | are neat      |    $1 |
</div>

10 years ago

Thank you for your replies! Can't believe that I forgot to to check the docs this time.

10 years ago

I have HTML code in my table to show list of items

HTML
| Sample | <ul><li>Item 1</li><li>Item 2</li><li>Item 3</li><li>Item 3</li></ul> |

If I enable Markdown Extra, the list is not displayed and the page is broken. Is there any way to have <ul> in table? I searched but only found the HTML solution which I currently use.

10 years ago

I think its just better to write the entire thing in HTML. HTML outside and inside is kinda making the markdown bits redundant :)

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1361 9 years ago
Archive · by Muut Archive, 9 years ago
2 939 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2958 9 years ago
Archive · by Muut Archive, 9 years ago
3 1123 9 years ago