Skip to content

Instantly share code, notes, and snippets.

@ddbeck
Last active June 11, 2019 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ddbeck/39d348b2561593955be4051fb8a1b72a to your computer and use it in GitHub Desktop.
Save ddbeck/39d348b2561593955be4051fb8a1b72a to your computer and use it in GitHub Desktop.
Multiple examples in Markdown
---
type: static
---
<!--
This is the raw Markdown as you would write it for an example. Note the flags in the info string of each code block.
-->
Suppose you want to list the winners of a competition:
```html example-body show-codeblock
<ul>
<li><span class="name">Henrietta Boffin</span> - 1st place</li>
<li><span class="name">Jerry Cruncher</span> - 2nd place</li>
</ul>
```
```css example-style
body {
border: 1px solid #3f87a6;
max-width: calc(100% - 40px - 6px);
padding: 20px;
width: calc(100% - 40px - 6px);
border-width: 1px 1px 1px 5px;
}
```
This works fine as long as the names are LTR, but when you insert an RTL name, then the `-1`, which consists of characters with neutral or weak directionality, will adopt the directionality of the RTL text, and the result will be garbled:
```html example-body show-codeblock
<ul>
<li><span class="name">اَلأَعْشَى</span> - 1st place</li>
<li><span class="name">Jerry Cruncher</span> - 2nd place</li>
</ul>
```
```css example-style
body {
border: 1px solid #3f87a6;
max-width: calc(100% - 40px - 6px);
padding: 20px;
width: calc(100% - 40px - 6px);
border-width: 1px 1px 1px 5px;
}
```
You can use `<bdi>` to instruct the browser to treat the name in isolation from its embedding context:
```html example-body show-codeblock
<ul>
<li><bdi class="name">اَلأَعْشَى</bdi> - 1st place</li>
<li><bdi class="name">Jerry Cruncher</bdi> - 2nd place</li>
</ul>
```
```css example-style
body {
border: 1px solid #3f87a6;
max-width: calc(100% - 40px - 6px);
padding: 20px;
width: calc(100% - 40px - 6px);
border-width: 1px 1px 1px 5px;
}
```
type
static

This is the preview of the same Markdown as you'd see it on GitHub.

Suppose you want to list the winners of a competition:

<ul>
 <li><span class="name">Henrietta Boffin</span> - 1st place</li>
 <li><span class="name">Jerry Cruncher</span> - 2nd place</li>
</ul>
body {
  border: 1px solid #3f87a6;
  max-width: calc(100% - 40px - 6px);
  padding: 20px;
  width: calc(100% - 40px - 6px);
  border-width: 1px 1px 1px 5px;
}

This works fine as long as the names are LTR, but when you insert an RTL name, then the -1, which consists of characters with neutral or weak directionality, will adopt the directionality of the RTL text, and the result will be garbled:

<ul>
 <li><span class="name">اَلأَعْشَى</span> - 1st place</li>
 <li><span class="name">Jerry Cruncher</span> - 2nd place</li>
</ul>
body {
  border: 1px solid #3f87a6;
  max-width: calc(100% - 40px - 6px);
  padding: 20px;
  width: calc(100% - 40px - 6px);
  border-width: 1px 1px 1px 5px;
}

You can use <bdi> to instruct the browser to treat the name in isolation from its embedding context:

<ul>
 <li><bdi class="name">اَلأَعْشَى</bdi> - 1st place</li>
 <li><bdi class="name">Jerry Cruncher</bdi> - 2nd place</li>
</ul>
body {
  border: 1px solid #3f87a6;
  max-width: calc(100% - 40px - 6px);
  padding: 20px;
  width: calc(100% - 40px - 6px);
  border-width: 1px 1px 1px 5px;
}
<!DOCTYPE html>
<body>
<h2 id="type-static">type: static</h2>
<p><strong>This is the preview of the same Markdown as you'd see it on GitHub.</strong></p>
<p>Suppose you want to list the winners of a competition:</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode html"><code class="sourceCode html"><a class="sourceLine" id="cb1-1" title="1"><span class="kw">&lt;ul&gt;</span></a>
<a class="sourceLine" id="cb1-2" title="2"> <span class="kw">&lt;li&gt;&lt;span</span><span class="ot"> class=</span><span class="st">&quot;name&quot;</span><span class="kw">&gt;</span>Henrietta Boffin<span class="kw">&lt;/span&gt;</span> - 1st place<span class="kw">&lt;/li&gt;</span></a>
<a class="sourceLine" id="cb1-3" title="3"> <span class="kw">&lt;li&gt;&lt;span</span><span class="ot"> class=</span><span class="st">&quot;name&quot;</span><span class="kw">&gt;</span>Jerry Cruncher<span class="kw">&lt;/span&gt;</span> - 2nd place<span class="kw">&lt;/li&gt;</span></a>
<a class="sourceLine" id="cb1-4" title="4"><span class="kw">&lt;/ul&gt;</span></a></code></pre></div>
<iframe src="data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+DQoNCjxoZWFkPg0KICAgIDxzdHlsZT4NCiAgICAgICAgYm9keSB7DQogICAgICAgICAgICBib3JkZXI6IDFweCBzb2xpZCAjM2Y4N2E2Ow0KICAgICAgICAgICAgbWF4LXdpZHRoOiBjYWxjKDEwMCUgLSA0MHB4IC0gNnB4KTsNCiAgICAgICAgICAgIHBhZGRpbmc6IDIwcHg7DQogICAgICAgICAgICB3aWR0aDogY2FsYygxMDAlIC0gNDBweCAtIDZweCk7DQogICAgICAgICAgICBib3JkZXItd2lkdGg6IDFweCAxcHggMXB4IDVweDsNCiAgICAgICAgfQ0KICAgIDwvc3R5bGU+DQo8L2hlYWQ+DQoNCjxib2R5Pg0KICAgIDx1bD4NCiAgICAgICAgPGxpPjxzcGFuIGNsYXNzPSJuYW1lIj5IZW5yaWV0dGEgQm9mZmluPC9zcGFuPiAtIDFzdCBwbGFjZTwvbGk+DQogICAgICAgIDxsaT48c3BhbiBjbGFzcz0ibmFtZSI+SmVycnkgQ3J1bmNoZXI8L3NwYW4+IC0gMm5kIHBsYWNlPC9saT4NCiAgICA8L3VsPg0KPC9ib2R5Pg==" height="120" frameborder="0"></iframe>
<p>This works fine as long as the names are LTR, but when you insert an RTL name, then the <code>-1</code>, which consists of characters with neutral or weak directionality, will adopt the directionality of the RTL text, and the result will be garbled:</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode html"><code class="sourceCode html"><a class="sourceLine" id="cb3-1" title="1"><span class="kw">&lt;ul&gt;</span></a>
<a class="sourceLine" id="cb3-2" title="2"> <span class="kw">&lt;li&gt;&lt;span</span><span class="ot"> class=</span><span class="st">&quot;name&quot;</span><span class="kw">&gt;</span>اَلأَعْشَى<span class="kw">&lt;/span&gt;</span> - 1st place<span class="kw">&lt;/li&gt;</span></a>
<a class="sourceLine" id="cb3-3" title="3"> <span class="kw">&lt;li&gt;&lt;span</span><span class="ot"> class=</span><span class="st">&quot;name&quot;</span><span class="kw">&gt;</span>Jerry Cruncher<span class="kw">&lt;/span&gt;</span> - 2nd place<span class="kw">&lt;/li&gt;</span></a>
<a class="sourceLine" id="cb3-4" title="4"><span class="kw">&lt;/ul&gt;</span></a></code></pre></div>
<iframe src="data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+DQoNCjxoZWFkPg0KICAgIDxzdHlsZT4NCiAgICAgICAgYm9keSB7DQogICAgICAgICAgICBib3JkZXI6IDFweCBzb2xpZCAjM2Y4N2E2Ow0KICAgICAgICAgICAgbWF4LXdpZHRoOiBjYWxjKDEwMCUgLSA0MHB4IC0gNnB4KTsNCiAgICAgICAgICAgIHBhZGRpbmc6IDIwcHg7DQogICAgICAgICAgICB3aWR0aDogY2FsYygxMDAlIC0gNDBweCAtIDZweCk7DQogICAgICAgICAgICBib3JkZXItd2lkdGg6IDFweCAxcHggMXB4IDVweDsNCiAgICAgICAgfQ0KICAgIDwvc3R5bGU+DQo8L2hlYWQ+DQoNCjxib2R5Pg0KICAgIDx1bD4NCiAgICAgICAgPGxpPjxzcGFuIGNsYXNzPSJuYW1lIj7Yp9mO2YTYo9mO2LnZkti02Y7ZiTwvc3Bhbj4gLSAxc3QgcGxhY2U8L2xpPg0KICAgICAgICA8bGk+PHNwYW4gY2xhc3M9Im5hbWUiPkplcnJ5IENydW5jaGVyPC9zcGFuPiAtIDJuZCBwbGFjZTwvbGk+DQogICAgPC91bD4NCjwvYm9keT4=" height="120" frameborder="0"></iframe>
<p>You can use <code>&lt;bdi&gt;</code> to instruct the browser to treat the name in isolation from its embedding context:</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode html"><code class="sourceCode html"><a class="sourceLine" id="cb5-1" title="1"><span class="kw">&lt;ul&gt;</span></a>
<a class="sourceLine" id="cb5-2" title="2"> <span class="kw">&lt;li&gt;&lt;bdi</span><span class="ot"> class=</span><span class="st">&quot;name&quot;</span><span class="kw">&gt;</span>اَلأَعْشَى<span class="kw">&lt;/bdi&gt;</span> - 1st place<span class="kw">&lt;/li&gt;</span></a>
<a class="sourceLine" id="cb5-3" title="3"> <span class="kw">&lt;li&gt;&lt;bdi</span><span class="ot"> class=</span><span class="st">&quot;name&quot;</span><span class="kw">&gt;</span>Jerry Cruncher<span class="kw">&lt;/bdi&gt;</span> - 2nd place<span class="kw">&lt;/li&gt;</span></a>
<a class="sourceLine" id="cb5-4" title="4"><span class="kw">&lt;/ul&gt;</span></a></code></pre></div>
<iframe src="data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+DQoNCjxoZWFkPg0KICAgIDxzdHlsZT4NCiAgICAgICAgYm9keSB7DQogICAgICAgICAgICBib3JkZXI6IDFweCBzb2xpZCAjM2Y4N2E2Ow0KICAgICAgICAgICAgbWF4LXdpZHRoOiBjYWxjKDEwMCUgLSA0MHB4IC0gNnB4KTsNCiAgICAgICAgICAgIHBhZGRpbmc6IDIwcHg7DQogICAgICAgICAgICB3aWR0aDogY2FsYygxMDAlIC0gNDBweCAtIDZweCk7DQogICAgICAgICAgICBib3JkZXItd2lkdGg6IDFweCAxcHggMXB4IDVweDsNCiAgICAgICAgfQ0KICAgIDwvc3R5bGU+DQo8L2hlYWQ+DQoNCjxib2R5Pg0KICAgIDx1bD4NCiAgICAgICAgPGxpPjxiZGkgY2xhc3M9Im5hbWUiPtin2Y7ZhNij2Y7YudmS2LTZjtmJPC9iZGk+IC0gMXN0IHBsYWNlPC9saT4NCiAgICAgICAgPGxpPjxiZGkgY2xhc3M9Im5hbWUiPkplcnJ5IENydW5jaGVyPC9iZGk+IC0gMm5kIHBsYWNlPC9saT4NCiAgICA8L3VsPg0KPC9ib2R5Pg==" height="120" frameborder="0"></iframe>
</body>
<!DOCTYPE html>
<head>
<style>
body {
border: 1px solid #3f87a6;
max-width: calc(100% - 40px - 6px);
padding: 20px;
width: calc(100% - 40px - 6px);
border-width: 1px 1px 1px 5px;
}
</style>
</head>
<body>
<ul>
<li><span class="name">Henrietta Boffin</span> - 1st place</li>
<li><span class="name">Jerry Cruncher</span> - 2nd place</li>
</ul>
</body>
<!DOCTYPE html>
<head>
<style>
body {
border: 1px solid #3f87a6;
max-width: calc(100% - 40px - 6px);
padding: 20px;
width: calc(100% - 40px - 6px);
border-width: 1px 1px 1px 5px;
}
</style>
</head>
<body>
<ul>
<li><span class="name">اَلأَعْشَى</span> - 1st place</li>
<li><span class="name">Jerry Cruncher</span> - 2nd place</li>
</ul>
</body>
<!DOCTYPE html>
<head>
<style>
body {
border: 1px solid #3f87a6;
max-width: calc(100% - 40px - 6px);
padding: 20px;
width: calc(100% - 40px - 6px);
border-width: 1px 1px 1px 5px;
}
</style>
</head>
<body>
<ul>
<li><bdi class="name">اَلأَعْشَى</bdi> - 1st place</li>
<li><bdi class="name">Jerry Cruncher</bdi> - 2nd place</li>
</ul>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment