Skip to content

Commit b305d93

Browse files
authored
Merge pull request #26260 from github/repo-sync
Repo sync
2 parents f42acdc + 071a3f8 commit b305d93

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+292
-255
lines changed

.github/actions-scripts/rendered-content-link-checker.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ import contextualize from '../../middleware/context.js'
1414
import features from '../../middleware/contextualizers/features.js'
1515
import getRedirect from '../../lib/get-redirect.js'
1616
import warmServer from '../../lib/warm-server.js'
17-
import liquid from '../../lib/render-content/liquid.js'
17+
import { liquid } from '../../src/content-render/index.js'
1818
import { deprecated } from '../../lib/enterprise-server-releases.js'
1919
import excludedLinks from '../../lib/excluded-links.js'
2020
import { getEnvInputs, boolEnvVar } from './lib/get-env-inputs.js'
2121
import { debugTimeEnd, debugTimeStart } from './lib/debug-time-taken.js'
2222
import { uploadArtifact as uploadArtifactLib } from './lib/upload-artifact.js'
2323
import github from '../../script/helpers/github.js'
2424
import { getActionContext } from './lib/action-context.js'
25-
import { createMinimalProcessor } from '../../lib/render-content/create-processor.js'
25+
import { createMinimalProcessor } from '../../src/content-render/unified/processor.js'
2626

2727
const STATIC_PREFIXES = {
2828
assets: path.resolve('assets'),

lib/get-mini-toc-items.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import cheerio from 'cheerio'
22
import { range } from 'lodash-es'
33

4-
import renderContent from './render-content/index.js'
4+
import { renderContent } from '#src/content-render/index.js'
55

66
// Keep maxHeadingLevel=2 for accessibility reasons, see docs-engineering#2701 for more info
77
export default function getMiniTocItems(html, maxHeadingLevel = 2, headingScope = '') {

lib/page.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import getTocItems from './get-toc-items.js'
99
import pathUtils from './path-utils.js'
1010
import Permalink from './permalink.js'
1111
import languages from './languages.js'
12-
import renderContent from './render-content/index.js'
12+
import { renderContent } from '#src/content-render/index.js'
1313
import processLearningTracks from '#src/learning-track/lib/process-learning-tracks.js'
1414
import { productMap } from './all-products.js'
1515
import slash from 'slash'

lib/release-notes-utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import semver from 'semver'
2-
import renderContent from './render-content/index.js'
2+
import { renderContent } from '#src/content-render/index.js'
33

44
/**
55
* Create an array of release note objects and sort them by number.

lib/render-content/README.md

Lines changed: 0 additions & 48 deletions
This file was deleted.

lib/render-content/index.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

lib/render-content/liquid.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

lib/render-content/renderContent.js

Lines changed: 0 additions & 79 deletions
This file was deleted.

lib/render-with-fallback.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import renderContent from './render-content/index.js'
1+
import { renderContent } from '#src/content-render/index.js'
22
import Page from './page.js'
3-
import { TitleFromAutotitleError } from './render-content/plugins/rewrite-local-links.js'
3+
import { TitleFromAutotitleError } from '#src/content-render/unified/rewrite-local-links.js'
44

55
class EmptyTitleError extends Error {}
66

middleware/contextualizers/current-product-tree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from 'path'
2-
import liquid from '../../lib/render-content/liquid.js'
2+
import { liquid } from '#src/content-render/index.js'
33
import findPageInSiteTree from '../../lib/find-page-in-site-tree.js'
44
import removeFPTFromPath from '../../lib/remove-fpt-from-path.js'
55
import { executeWithFallback } from '../../lib/render-with-fallback.js'

middleware/contextualizers/glossaries.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getDataByLanguage } from '../../lib/get-data.js'
2-
import liquid from '../../lib/render-content/liquid.js'
2+
import { liquid } from '#src/content-render/index.js'
33
import { executeWithFallback } from '../../lib/render-with-fallback.js'
44
import { correctTranslatedContentStrings } from '../../lib/correct-translation-content.js'
55

script/dev-toc/generate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { execSync } from 'child_process'
66
import { program } from 'commander'
77
import fpt from '../../lib/non-enterprise-default-version.js'
88
import { allVersionKeys } from '../../lib/all-versions.js'
9-
import { liquid } from '../../lib/render-content/index.js'
9+
import { liquid } from '#src/content-render/index.js'
1010
import contextualize from '../../middleware/context.js'
1111

1212
const layoutFilename = path.posix.join(process.cwd(), 'script/dev-toc/layout.html')

script/reconcile-category-dirs-with-ids.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import walk from 'walk-sync'
1919
import slash from 'slash'
2020
import GithubSlugger from 'github-slugger'
2121
import { decode } from 'html-entities'
22-
import renderContent from '../lib/render-content/index.js'
22+
import { renderContent } from '#src/content-render/index.js'
2323

2424
const slugger = new GithubSlugger()
2525

src/content-linter/lib/linting-rules/image-alt-text-length.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { addError, forEachInlineChild } from 'markdownlint-rule-helpers'
2-
import renderContent from '../../../../lib/render-content/index.js'
2+
import { renderContent } from '#src/content-render/index.js'
33

44
export const incorrectAltTextLength = {
55
names: ['MD111', 'incorrect-alt-text-length'],

src/content-linter/tests/category-pages.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import GithubSlugger from 'github-slugger'
77
import { decode } from 'html-entities'
88

99
import matter from '../../../lib/read-frontmatter.js'
10-
import renderContent from '../../../lib/render-content/index.js'
10+
import { renderContent } from '#src/content-render/index.js'
1111
import getApplicableVersions from '../../../lib/get-applicable-versions.js'
1212
import contextualize from '../../../middleware/context.js'
1313
import shortVersions from '../../../middleware/contextualizers/short-versions.js'

src/content-linter/tests/lint-files.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import { jest } from '@jest/globals'
1616

1717
import { frontmatter, deprecatedProperties } from '../../../lib/frontmatter.js'
1818
import languages from '../../../lib/languages.js'
19-
import { tags } from '../../../lib/liquid-tags/extended-markdown.js'
19+
import { tags } from '#src/content-render/liquid/extended-markdown.js'
2020
import releaseNotesSchema from '../lib/release-notes-schema.js'
2121
import learningTracksSchema from '../lib/learning-tracks-schema.js'
22-
import renderContent from '../../../lib/render-content/index.js'
22+
import { renderContent } from '#src/content-render/index.js'
2323
import getApplicableVersions from '../../../lib/get-applicable-versions.js'
2424
import { allVersions } from '../../../lib/all-versions.js'
2525
import { getDiffFiles } from '../lib/diff-files.js'

src/content-linter/tests/lint-versioning.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import semver from 'semver'
77
import { allVersions, allVersionShortnames } from '../../../lib/all-versions.js'
88
import { supported, next, nextNext, deprecated } from '../../../lib/enterprise-server-releases.js'
99
import { getLiquidConditionals } from '../../../script/helpers/get-liquid-conditionals.js'
10-
import allowedVersionOperators from '../../../lib/liquid-tags/ifversion-supported-operators.js'
10+
import allowedVersionOperators from '#src/content-render/liquid/ifversion-supported-operators.js'
1111
import featureVersionsSchema from '../lib/feature-versions-schema.js'
1212
import walkFiles from '../../../script/helpers/walk-files.js'
1313
import { getDeepDataByLanguage } from '../../../lib/get-data.js'

lib/liquid-tags/README.md renamed to src/content-render/README.md

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,55 @@
1-
# Liquid Tags
1+
# Render content
2+
3+
In this directory is the main pipeline that converts our content from Liquid, Markdown and YAML into HTML. This directory _does not include React components_.
4+
5+
## Usage
6+
7+
```js
8+
const renderContent = require('.')
9+
10+
const html = await renderContent(`
11+
# Beep
12+
{{ foo }}
13+
`, {
14+
foo: 'bar'
15+
})
16+
```
17+
18+
Creates:
19+
20+
```html
21+
<h1 id="beep"><a href="#beep">Beep</a></h1>
22+
<p>bar</p>
23+
```
24+
25+
## API
26+
27+
### renderContent(markdown, context = {}, options = {})
28+
29+
Render a string of `markdown` with optional `context`. Returns a `Promise`.
30+
31+
Liquid will be looking for includes in `${process.cwd()}/includes`.
32+
33+
Options:
34+
35+
- `fileName`: File name for debugging purposes.
36+
- `textOnly`: Output text instead of html using [cheerio](https://ghub.io/cheerio).
37+
38+
### .liquid
39+
40+
The [Liquid](https://ghub.io/liquidjs) instance used internally.
41+
42+
### Code block headers
43+
44+
You can add a header to code blocks by adding the ` copy` annotation after the code fences, and a specified language:
45+
46+
```js copy
47+
const copyMe = true
48+
```
49+
50+
The un-highlighted text is available as `button.js-btn-copy`'s `data-clipboard-text` attribute.
51+
52+
## Liquid tags
253

354
See also [contributing/liquid-helpers.md](../../contributing/liquid-helpers.md)
455

@@ -36,7 +87,7 @@ Each custom tag has the following:
3687

3788
The class and the template should have corresponding names, like `lib/liquid-tags/my-tag.js` and `includes/liquid-tags/my-tag.html`
3889

39-
You must also register the new tag in `lib/render-content/index.js` with a line like this:
90+
You must also register the new tag in `src/content-render/liquid/engine.js` with a line like this:
4091

4192
```
4293
renderContent.liquid.registerTag('my_tag', require('./liquid-tags/my-tag'))

src/content-render/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { renderLiquid } from './liquid/index.js'
2+
import { renderUnified } from './unified/index.js'
3+
import { engine } from './liquid/engine.js'
4+
5+
// parse multiple times because some templates contain more templates. :]
6+
export async function renderContent(template = '', context = {}, options = {}) {
7+
// If called with a falsy template, it can't ever become something
8+
// when rendered. We can exit early to save some pointless work.
9+
if (!template) return template
10+
try {
11+
template = await renderLiquid(template, context)
12+
const html = await renderUnified(template, context, options)
13+
return html
14+
} catch (error) {
15+
if (options.filename) {
16+
console.error(`renderContent failed on file: ${options.filename}`)
17+
}
18+
throw error
19+
}
20+
}
21+
22+
export const liquid = engine

0 commit comments

Comments
 (0)