Skip to content

Commit 61885e9

Browse files
hectorsectorheiskrPeter Bengtsson
authored
Annotations frontend (github#37724)
Co-authored-by: Kevin Heis <[email protected]> Co-authored-by: Peter Bengtsson <[email protected]>
1 parent 5fc846c commit 61885e9

3 files changed

Lines changed: 90 additions & 3 deletions

File tree

lib/render-content/plugins/annotate.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { visit } from 'unist-util-visit'
3535
import { h } from 'hastscript'
3636
import { fromMarkdown } from 'mdast-util-from-markdown'
3737
import { toHast } from 'mdast-util-to-hast'
38-
// import { header } from './code-header.js'
38+
import { header } from './code-header.js'
3939

4040
const languages = yaml.load(fs.readFileSync('./data/variables/code-languages.yml', 'utf8'))
4141

@@ -121,7 +121,10 @@ function template({ lang, code, rows }) {
121121
return h(
122122
'div',
123123
{ class: 'annotate' },
124-
// header(lang, code),
124+
h('div', { className: 'annotate-row header' }, [
125+
h('div', { className: 'annotate-code header color-bg-default' }, header(lang, code)),
126+
h('div', { className: 'annotate-note header' }),
127+
]),
125128
rows.map(([note, code]) =>
126129
h('div', { className: 'annotate-row' }, [
127130
h(

stylesheets/utilities.scss

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,79 @@
126126
white-space: normal;
127127
}
128128
}
129+
130+
/* Code annotations
131+
----------------------------------------------------------------------------*/
132+
$annotation-breakpoint: 1550px;
133+
134+
.annotate {
135+
margin: 0 -250px;
136+
137+
@media (max-width: $annotation-breakpoint) {
138+
margin: auto;
139+
}
140+
141+
& > div:last-child > .annotate-code {
142+
border-bottom-left-radius: 6px;
143+
border-bottom-right-radius: 6px;
144+
border-bottom: 1px solid var(--color-border-default);
145+
}
146+
}
147+
148+
.annotate-row {
149+
display: flex;
150+
flex-direction: column;
151+
152+
@media (min-width: $annotation-breakpoint) {
153+
flex-direction: row;
154+
margin: 0 auto;
155+
156+
&:not(.header):hover {
157+
border-radius: 4px;
158+
outline: 2px solid var(--color-accent-fg);
159+
}
160+
}
161+
}
162+
163+
.annotate-code {
164+
background-color: var(--color-canvas-subtle);
165+
166+
&:not(.header) {
167+
border-left: 1px solid var(--color-border-default);
168+
border-right: 1px solid var(--color-border-default);
169+
}
170+
171+
pre {
172+
border: 0px !important;
173+
margin: 0px !important;
174+
175+
.hljs {
176+
overflow-x: auto;
177+
white-space: pre-wrap;
178+
white-space: -moz-pre-wrap;
179+
white-space: -pre-wrap;
180+
white-space: -o-pre-wrap;
181+
word-wrap: break-word;
182+
}
183+
}
184+
185+
@media (min-width: $annotation-breakpoint) {
186+
width: 50%;
187+
}
188+
}
189+
190+
.annotate-note {
191+
@media (min-width: $annotation-breakpoint) {
192+
width: 50%;
193+
194+
padding: 16px 0 16px 16px;
195+
font-size: 14px;
196+
}
197+
198+
@media (max-width: $annotation-breakpoint) {
199+
.annotate-note {
200+
padding: 16px 0 32px 0px;
201+
font-size: 14px;
202+
}
203+
}
204+
}

tests/rendering/__snapshots__/annotate.js.snap

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`annotate renders annotations 1`] = `
4-
"<div class="annotate"><div class="annotate-row"><div class="annotate-code"><pre><code class="hljs language-yaml"><span class="hljs-attr">name:</span> <span class="hljs-string">Post</span> <span class="hljs-string">welcome</span> <span class="hljs-string">comment</span></code></pre></div><div class="annotate-note"><p>The name of the workflow as it will appear in the "Actions" tab of the GitHub repository.</p></div></div><div class="annotate-row"><div class="annotate-code"><pre><code class="hljs language-yaml"><span class="hljs-attr">on:</span>
4+
"<div class="annotate"><div class="annotate-row header"><div class="annotate-code header color-bg-default"><header class="d-flex flex-items-center flex-justify-between p-2 text-small rounded-top-1 border-top border-left border-right"><span>YAML</span><button class="js-btn-copy btn btn-sm tooltipped tooltipped-nw" data-clipboard-text="# The name of the workflow as it will appear in the &#x22;Actions&#x22; tab of the GitHub repository.
5+
name: Post welcome comment
6+
7+
# Add the &#x60;pull_request&#x60; event, so that the workflow runs automatically
8+
# every time a pull request is created.
9+
on:
10+
pull_request:
11+
types: [opened]
12+
" aria-label="Copy code to clipboard"><svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-copy" aria-hidden="true"><path d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 0 1 0 1.5h-1.5a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-1.5a.75.75 0 0 1 1.5 0v1.5A1.75 1.75 0 0 1 9.25 16h-7.5A1.75 1.75 0 0 1 0 14.25Z"></path><path d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0 1 14.25 11h-7.5A1.75 1.75 0 0 1 5 9.25Zm1.75-.25a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-7.5a.25.25 0 0 0-.25-.25Z"></path></svg></button></header></div><div class="annotate-note header"></div></div><div class="annotate-row"><div class="annotate-code"><pre><code class="hljs language-yaml"><span class="hljs-attr">name:</span> <span class="hljs-string">Post</span> <span class="hljs-string">welcome</span> <span class="hljs-string">comment</span></code></pre></div><div class="annotate-note"><p>The name of the workflow as it will appear in the "Actions" tab of the GitHub repository.</p></div></div><div class="annotate-row"><div class="annotate-code"><pre><code class="hljs language-yaml"><span class="hljs-attr">on:</span>
513
<span class="hljs-attr">pull_request:</span>
614
<span class="hljs-attr">types:</span> [<span class="hljs-string">opened</span>]</code></pre></div><div class="annotate-note"><p>Add the <code>pull_request</code> event, so that the workflow runs automatically
715
every time a pull request is created.</p></div></div></div>"

0 commit comments

Comments
 (0)