Skip to content

Commit b8421ce

Browse files
authored
Merge pull request #28023 from github/repo-sync
Repo sync
2 parents f2d3077 + eee5ecf commit b8421ce

File tree

8 files changed

+148
-4
lines changed

8 files changed

+148
-4
lines changed

content/code-security/security-overview/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
2-
title: Viewing security alerts for repositories in your organization
2+
title: Viewing security information for your organization or enterprise
33
shortTitle: Security overview
44
allowTitleToDifferFromFilename: true
5-
intro: 'View, sort, and filter the security alerts from across your organization in one place.'
5+
intro: 'View, sort, and filter security alerts and coverage information from across your organization or enterprise, and enable security features for their repositories.'
66
product: '{% data reusables.gated-features.security-overview %}'
77
versions:
88
fpt: '*'

src/content-render/liquid/data.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ export default {
1313
}
1414

1515
this.path = tagToken.args
16+
this.tagToken = tagToken
1617
},
1718

1819
async render(scope) {
19-
const text = getDataByLanguage(this.path, scope.environments.currentLanguage)
20+
let text = getDataByLanguage(this.path, scope.environments.currentLanguage)
2021
if (text === undefined) {
2122
if (scope.environments.currentLanguage === 'en') {
2223
const message = `Can't find the key 'data ${this.path}' in the scope.`
@@ -28,6 +29,21 @@ export default {
2829
return
2930
}
3031

31-
return this.liquid.parseAndRender(text.trim(), scope.environments)
32+
if (text.trim().split('\n\n').length === 1 && text.split('\n').length > 0) {
33+
const { input, begin } = this.tagToken
34+
let i = 1
35+
while (input.charAt(begin - i) === ' ') {
36+
i++ // this goes one character "to the left"
37+
}
38+
const goBack = input.slice(begin - i, begin)
39+
if (goBack.charAt(0) === '\n' && goBack.length > 1) {
40+
const numSpaces = goBack.length - 1
41+
text = text.trim().replace(/^/gm, ' '.repeat(numSpaces)).trim()
42+
}
43+
} else {
44+
text = text.trim()
45+
}
46+
47+
return this.liquid.parseAndRender(text, scope.environments)
3248
},
3349
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
title: Data Liquid tag
3+
intro: The `data` Liquid tag can understand where it was used
4+
versions:
5+
fpt: '*'
6+
ghes: '*'
7+
ghae: '*'
8+
ghec: '*'
9+
type: how_to
10+
---
11+
12+
## Introduction
13+
14+
What this fixture accomplishes is that it uses the `\{\% data %}` Liquid
15+
tag to inject itself after some left-side whitespace. That same amount
16+
of left-side whitespace is then "replicated" to all lines of the string
17+
that gets injected.
18+
19+
In this example, the
20+
21+
1. Bullet point
22+
23+
{% data reusables.injectables.multiple_numbers %}
24+
25+
1. Another bullet point
26+
27+
After 3 spaces, here's the "body" of the second bullet point.
28+
29+
## Injected insode a code block
30+
31+
1. Here's some Yaml code.
32+
33+
```yaml copy
34+
{% data reusables.injectables.multiple_numbers %}
35+
36+
{% data reusables.injectables.one_line_numbers %}
37+
38+
name: Move assigned card
39+
on:
40+
issues:
41+
types:
42+
- assigned
43+
```
44+
45+
## Injected without any leading whitespace
46+
47+
On its own line:
48+
49+
{% data reusables.injectables.multiple_numbers %}
50+
51+
Directly after this: {% data reusables.injectables.multiple_numbers %}
52+
53+
And now for a table on its own starting line
54+
55+
{% data reusables.injectables.some_table %}
56+
57+
## Insert the same table inside a bullet point
58+
59+
1. Point 1
60+
61+
1. Point 2
62+
63+
What's important here is that in CommonMark when a Markdown table
64+
is injected and indented into a bullet point, that it works at all.
65+
66+
{% data reusables.injectables.some_table %}

tests/fixtures/content/get-started/liquid/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ children:
1818
- /ifversion
1919
- /links-with-liquid
2020
- /tool-specific
21+
- /data
2122
---
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
One
2+
Two
3+
Three
4+
Four
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
One Two Three Four
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
| Port | Service | Description |
2+
|------|---------|------------------------------------------------------------|
3+
| 22 | SSH | Git over SSH access. |
4+
| 25 | SMTP | SMTP with encryption (STARTTLS) support. |
5+
| 80 | HTTP | Web application access. |
6+
| 122 | SSH | Instance shell access. |
7+
| 161 | SNMP | Required for network monitoring protocol operation. |
8+
| 443 | HTTPS | Web application and Git over HTTPS access. |
9+
| 1194 | VPN | Secure replication network tunnel in high availability configuration. |

tests/rendering-fixtures/liquid.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,50 @@ describe('misc Liquid', () => {
233233
expect(texts[1]).toBe('Pricing')
234234
})
235235
})
236+
237+
describe('data tag', () => {
238+
test('injects data reusables with the right whitespace', async () => {
239+
const $ = await getDOM('/get-started/liquid/data')
240+
241+
// This proves that the two injected reusables tables work.
242+
// CommonMark is finicky if the indentation isn't perfect, so
243+
// if you don't get exactly 2 tables, something is wrong, and if it's
244+
// wrong it's most likely because of the leading whitespaces.
245+
expect($('#article-contents table').length).toBe(2)
246+
247+
// To truly understand this test, you have to see
248+
// http://localhost:4000/en/get-started/liquid/data to understand it.
249+
// The page uses `{% data ... %}` within the bodies of bullet points.
250+
// If the whitespace isn't correct and working, the bullet points
251+
// would get confused and think the bullet point "body" is a new
252+
// bullet point on its own.
253+
expect($('#article-contents ol').length).toBe(3)
254+
expect($('#article-contents ol li').length).toBe(2 + 1 + 2)
255+
256+
// In the very first bullet point we inject something that multiple
257+
// linebreaks in it. The source looks like this:
258+
//
259+
// 1. Bullet point
260+
//
261+
// {% data reusables.injectables.multiple_numbers %}
262+
//
263+
// (The code comment itself here has 3 spaces of manual indentation)
264+
// What's important is that all the expected lines of that reusables
265+
// stick inside this `ul li` block.
266+
const liText = $('#article-contents ol li').first().text()
267+
expect(liText).toMatch(/Bullet point\nOne\nTwo\nThree\nFour/)
268+
269+
// The code block uses `{% data ... %}` and it should be indented
270+
// so that it aligns perfectly with the code block itself.
271+
// One of the injected data reusables contains multiple lines.
272+
// It's important that each line from that starts at the far
273+
// left. No more or less whitespace.
274+
const codeBlock = $('#article-contents li pre').text()
275+
expect(codeBlock).toMatch(/^One\n/)
276+
expect(codeBlock).toMatch(/^One\nTwo\n/)
277+
expect(codeBlock).toMatch(/^One\nTwo\nThree\n/)
278+
279+
// The code block also a reusables that is just one line.
280+
expect(codeBlock).toMatch(/One Two Three Four\n/)
281+
})
282+
})

0 commit comments

Comments
 (0)