Skip to content

Repo sync #28023

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

Merged
merged 3 commits into from
Sep 5, 2023
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
4 changes: 2 additions & 2 deletions content/code-security/security-overview/index.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: Viewing security alerts for repositories in your organization
title: Viewing security information for your organization or enterprise
shortTitle: Security overview
allowTitleToDifferFromFilename: true
intro: 'View, sort, and filter the security alerts from across your organization in one place.'
intro: 'View, sort, and filter security alerts and coverage information from across your organization or enterprise, and enable security features for their repositories.'
product: '{% data reusables.gated-features.security-overview %}'
versions:
fpt: '*'
Expand Down
20 changes: 18 additions & 2 deletions src/content-render/liquid/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ export default {
}

this.path = tagToken.args
this.tagToken = tagToken
},

async render(scope) {
const text = getDataByLanguage(this.path, scope.environments.currentLanguage)
let text = getDataByLanguage(this.path, scope.environments.currentLanguage)
if (text === undefined) {
if (scope.environments.currentLanguage === 'en') {
const message = `Can't find the key 'data ${this.path}' in the scope.`
Expand All @@ -28,6 +29,21 @@ export default {
return
}

return this.liquid.parseAndRender(text.trim(), scope.environments)
if (text.trim().split('\n\n').length === 1 && text.split('\n').length > 0) {
const { input, begin } = this.tagToken
let i = 1
while (input.charAt(begin - i) === ' ') {
i++ // this goes one character "to the left"
}
const goBack = input.slice(begin - i, begin)
if (goBack.charAt(0) === '\n' && goBack.length > 1) {
const numSpaces = goBack.length - 1
text = text.trim().replace(/^/gm, ' '.repeat(numSpaces)).trim()
}
} else {
text = text.trim()
}

return this.liquid.parseAndRender(text, scope.environments)
},
}
66 changes: 66 additions & 0 deletions tests/fixtures/content/get-started/liquid/data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
title: Data Liquid tag
intro: The `data` Liquid tag can understand where it was used
versions:
fpt: '*'
ghes: '*'
ghae: '*'
ghec: '*'
type: how_to
---

## Introduction

What this fixture accomplishes is that it uses the `\{\% data %}` Liquid
tag to inject itself after some left-side whitespace. That same amount
of left-side whitespace is then "replicated" to all lines of the string
that gets injected.

In this example, the

1. Bullet point

{% data reusables.injectables.multiple_numbers %}

1. Another bullet point

After 3 spaces, here's the "body" of the second bullet point.

## Injected insode a code block

1. Here's some Yaml code.

```yaml copy
{% data reusables.injectables.multiple_numbers %}

{% data reusables.injectables.one_line_numbers %}

name: Move assigned card
on:
issues:
types:
- assigned
```

## Injected without any leading whitespace

On its own line:

{% data reusables.injectables.multiple_numbers %}

Directly after this: {% data reusables.injectables.multiple_numbers %}

And now for a table on its own starting line

{% data reusables.injectables.some_table %}

## Insert the same table inside a bullet point

1. Point 1

1. Point 2

What's important here is that in CommonMark when a Markdown table
is injected and indented into a bullet point, that it works at all.

{% data reusables.injectables.some_table %}
1 change: 1 addition & 0 deletions tests/fixtures/content/get-started/liquid/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ children:
- /ifversion
- /links-with-liquid
- /tool-specific
- /data
---
4 changes: 4 additions & 0 deletions tests/fixtures/data/reusables/injectables/multiple_numbers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
One
Two
Three
Four
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
One Two Three Four
9 changes: 9 additions & 0 deletions tests/fixtures/data/reusables/injectables/some_table.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
| Port | Service | Description |
|------|---------|------------------------------------------------------------|
| 22 | SSH | Git over SSH access. |
| 25 | SMTP | SMTP with encryption (STARTTLS) support. |
| 80 | HTTP | Web application access. |
| 122 | SSH | Instance shell access. |
| 161 | SNMP | Required for network monitoring protocol operation. |
| 443 | HTTPS | Web application and Git over HTTPS access. |
| 1194 | VPN | Secure replication network tunnel in high availability configuration. |
47 changes: 47 additions & 0 deletions tests/rendering-fixtures/liquid.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,50 @@ describe('misc Liquid', () => {
expect(texts[1]).toBe('Pricing')
})
})

describe('data tag', () => {
test('injects data reusables with the right whitespace', async () => {
const $ = await getDOM('/get-started/liquid/data')

// This proves that the two injected reusables tables work.
// CommonMark is finicky if the indentation isn't perfect, so
// if you don't get exactly 2 tables, something is wrong, and if it's
// wrong it's most likely because of the leading whitespaces.
expect($('#article-contents table').length).toBe(2)

// To truly understand this test, you have to see
// http://localhost:4000/en/get-started/liquid/data to understand it.
// The page uses `{% data ... %}` within the bodies of bullet points.
// If the whitespace isn't correct and working, the bullet points
// would get confused and think the bullet point "body" is a new
// bullet point on its own.
expect($('#article-contents ol').length).toBe(3)
expect($('#article-contents ol li').length).toBe(2 + 1 + 2)

// In the very first bullet point we inject something that multiple
// linebreaks in it. The source looks like this:
//
// 1. Bullet point
//
// {% data reusables.injectables.multiple_numbers %}
//
// (The code comment itself here has 3 spaces of manual indentation)
// What's important is that all the expected lines of that reusables
// stick inside this `ul li` block.
const liText = $('#article-contents ol li').first().text()
expect(liText).toMatch(/Bullet point\nOne\nTwo\nThree\nFour/)

// The code block uses `{% data ... %}` and it should be indented
// so that it aligns perfectly with the code block itself.
// One of the injected data reusables contains multiple lines.
// It's important that each line from that starts at the far
// left. No more or less whitespace.
const codeBlock = $('#article-contents li pre').text()
expect(codeBlock).toMatch(/^One\n/)
expect(codeBlock).toMatch(/^One\nTwo\n/)
expect(codeBlock).toMatch(/^One\nTwo\nThree\n/)

// The code block also a reusables that is just one line.
expect(codeBlock).toMatch(/One Two Three Four\n/)
})
})