Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add footnote styles #1616

Merged
merged 10 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gold-games-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/css": minor
---

Adding footnote styles to markdown-body.
31 changes: 31 additions & 0 deletions docs/content/components/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,25 @@ bundle: markdown

<p><img src="http://placekitten.com/g/1200/800/"></p>

<p>
Here's a simple footnote,<sup><a href="#user-content-fn-1-12345" id="user-content-fnref-1-12345" data-footnote-ref="" aria-describedby="footnote-label">1</a></sup> and here's a longer one.<sup><a href="#user-content-fn-bignote-12345" id="user-content-fnref-bignote-12345" data-footnote-ref="" aria-describedby="footnote-label">2</a></sup>
</p>

<section data-footnotes="" class="footnotes">
<h2 id="footnote-label" class="sr-only">Footnotes</h2>
<ol>
<li id="user-content-fn-1-12345">
<p>This is the first footnote. <a href="#user-content-fnref-1-12345" data-footnote-backref="" class="data-footnote-backref" aria-label="Back to content"><g-emoji class="g-emoji" alias="leftwards_arrow_with_hook" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/21a9.png">↩</g-emoji></a></p>
</li>
<li id="user-content-fn-bignote-12345">
<p>Here's one with multiple paragraphs and code.</p>
<p>Indent paragraphs to include them in the footnote.</p>
<p><code>{ my code }</code></p>
<p>Add as many paragraphs as you like. <a href="#user-content-fnref-bignote-12345" data-footnote-backref="" class="data-footnote-backref" aria-label="Back to content"><g-emoji class="g-emoji" alias="leftwards_arrow_with_hook" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/21a9.png">↩</g-emoji></a></p>
</li>
</ol>
</section>

<pre><code>This is the final element on the page and there should be no margin below this.</code></pre>
</div>
```
Expand Down Expand Up @@ -447,6 +466,18 @@ Large images should always scale down and fit in the content container.

![](http://placekitten.com/g/1200/800/)

Here's a simple footnote,[^1] and here's a longer one.[^bignote]

[^1]: This is the first footnote.

[^bignote]: Here's one with multiple paragraphs and code.

Indent paragraphs to include them in the footnote.

`{ my code }`

Add as many paragraphs as you like.

```
This is the final element on the page and there should be no margin below this.
```
Expand Down
37 changes: 37 additions & 0 deletions src/markdown/footnotes.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// stylelint-disable selector-max-type
// stylelint-disable selector-max-compound-selectors

.markdown-body .footnotes {
font-size: $h6-size;
color: var(--color-fg-muted);
border-top: $border;

ol {
padding-left: $spacer-3;
}

li {
position: relative;
}

li:target::before {
position: absolute;
top: -$spacer-2;
right: -$spacer-2;
bottom: -$spacer-2;
left: -$spacer-4;
pointer-events: none;
content: "";
// stylelint-disable-next-line primer/borders
border: 2px $border-style var(--color-accent-emphasis);
border-radius: $border-radius;
}

li:target {
color: var(--color-fg-default);
}

.data-footnote-backref g-emoji {
font-family: monospace;
}
}
1 change: 1 addition & 0 deletions src/markdown/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
@import "./images.scss";
@import "./code.scss";
@import "./blob-csv.scss";
@import "./footnotes.scss";
8 changes: 8 additions & 0 deletions src/markdown/markdown-body.scss
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,12 @@
margin-bottom: 0;
}
}

sup > a::before {
content: "[";
}

sup > a::after {
content: "]";
}
Comment on lines +97 to +103
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a chance that a user would want to add a link inside a <sup> and not get it wrapped with []? It seems we currently use the data-footnote-ref attribute. So if we wanted to scope this a bit more, we might can instead use:

Suggested change
sup > a::before {
content: "[";
}
sup > a::after {
content: "]";
}
[data-footnote-ref]::before {
content: "[";
}
[data-footnote-ref]::after {
content: "]";
}

Not sure if data-footnote-ref will be part of, I think we use a "common mark" library and safe to use? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm...That's a good question.

Yeah, data-footnote-ref is safe to use (I added it to the library 😄 ).

I think it's a pretty low chance that a user would want that behavior.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, we can keep it "as is" and in case we hear reports from users, switch to using [data-footnote-ref].

}