Skip to content

Instantly share code, notes, and snippets.

@havenchyk
Created February 15, 2022 13:42
Show Gist options
  • Save havenchyk/559beeb456b2fe9078bd4294634e4f3b to your computer and use it in GitHub Desktop.
Save havenchyk/559beeb456b2fe9078bd4294634e4f3b to your computer and use it in GitHub Desktop.
GitHub markdown table with code formatting
filename example of code
client/.happo.js require('dotenv').config();
client/globalSetup.ts
require('dotenv').config({
  path: path.resolve(process.cwd(), 'client', '.env'),
});
@mr-mig
Copy link

mr-mig commented Feb 15, 2022

client/.happo.js

require('dotenv').config();

client/globalSetup.ts

require('dotenv').config({
  path: path.resolve(process.cwd(), 'client', '.env'),
});

The code:

<table>
<tr>
<td>

client/.happo.js

</td>
<td>

`require('dotenv').config();`

</td>
</tr>
<tr>
<td>

client/globalSetup.ts

</td>
<td>

```js
require('dotenv').config({
  path: path.resolve(process.cwd(), 'client', '.env'),
});
```
</td>
</tr>
</table>

@havenchyk
Copy link
Author

@mr-mig I just wanted to put block code to the table. If we have a clear and simple syntax for MD tables without using tr and td, we have a syntax for highlighting code, why can't we have some abstraction to use both together without HTML tags?

@mr-mig
Copy link

mr-mig commented Feb 15, 2022

@havenchyk this is the behavior by design per spec, see Section 4.10 (although it does not mention NOT supporting block-level elements inside MD tables). Also, here's a spec-compliant test-suite for that specific rule.

@mr-mig
Copy link

mr-mig commented Feb 15, 2022

If you want a coumn-like layout, you MUST use HTML tables for that.

There's a trick of rendering Markdown within HTML though.
The rule is like that: if you want to render markdown within a <table>-based layout, you need to include newlines before and after the MD block:

<td>

**This line** will be rendered as  _markdown_

</td>

Copy link

ghost commented Feb 15, 2022

@mr-mig

Markdown table & videos are tears:

| ios | android |
|---|---|
| https://user-images.githubusercontent.com/95620376/154093638-056f3bef-f56a-4f0d-a0e3-89f2fad52244.mp4 | https://user-images.githubusercontent.com/95620376/154093638-056f3bef-f56a-4f0d-a0e3-89f2fad52244.mp4 |
ios android
https://user-images.githubusercontent.com/95620376/154093638-056f3bef-f56a-4f0d-a0e3-89f2fad52244.mp4 https://user-images.githubusercontent.com/95620376/154093638-056f3bef-f56a-4f0d-a0e3-89f2fad52244.mp4

HTML variant

<table>
<tr>
<td>

ios

</td>
<td>

android

</td>
</tr>
<tr>
<td>

https://user-images.githubusercontent.com/95620376/154093638-056f3bef-f56a-4f0d-a0e3-89f2fad52244.mp4

</td>
<td>

https://user-images.githubusercontent.com/95620376/154093638-056f3bef-f56a-4f0d-a0e3-89f2fad52244.mp4

</td>
</tr>
</table>

ios

android

151585253-8b33b097-4bf6-460a-85ab-078816128071.mp4
151585253-8b33b097-4bf6-460a-85ab-078816128071.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment