Skip to content

Commit d68dde1

Browse files
heiskrchiedorachmari
authored
Upgrade pipeline with env COMMONMARK=1 npm start to see new, otherwise parse current (github#20508)
* Update the trim nightmare * Update create-processor.js * Update other packages in the rendering pipeline * A few more updates * Fix tables * Update lint-files.js * Fix copy code blocks * Update render-content.js * remove whitespace from liquid conditionals * We no longer need require eslint rules * Neat, it worked * Revert test change * Update create-processor.js * Without aliases Co-authored-by: Chiedo John <2156688+chiedo@users.noreply.github.com> Co-authored-by: Rachael Sewell <rachmari@github.com>
1 parent 648c129 commit d68dde1

13 files changed

Lines changed: 6217 additions & 4239 deletions

.eslintrc.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ module.exports = {
1515
},
1616
rules: {
1717
'import/no-extraneous-dependencies': ['error', { packageDir: '.' }],
18-
'node/global-require': ['error'],
19-
'import/no-dynamic-require': ['error'],
2018
},
2119
overrides: [
2220
{

includes/rest_operation.html

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ <h3 id="{{operation.slug}}" class="pt-3">
77
</div>
88
<pre><code><span class="color-bg-info-inverse color-text-inverse rounded-1 px-2 py-1" style="text-transform: uppercase">{{operation.verb}}</span> {{operation.requestPath}}</code></pre>
99
<div>
10-
{% if operation.parameters.size > 0 or operation.bodyParameters.size > 0 %}
10+
{%- if operation.parameters.size > 0 or operation.bodyParameters.size > 0 -%}
1111
<h4 id="{{operation.slug}}--parameters">
12-
<a href="#{{operation.slug}}--parameters">{% data ui.products.rest.reference.parameters %}</a>
12+
<a href="#{{operation.slug}}--parameters">{%- data ui.products.rest.reference.parameters -%}</a>
1313
</h4>
1414
<table>
1515
<thead>
@@ -31,121 +31,121 @@ <h4 id="{{operation.slug}}--parameters">
3131
<td class="opacity-70">header</td>
3232
<td class="opacity-70">
3333
<p>
34-
{% if operation.hasRequiredPreviews %}
34+
{%- if operation.hasRequiredPreviews -%}
3535
This API is under preview and subject to change.
36-
{% else %}
36+
{%- else -%}
3737
Setting to <code>application/vnd.github.v3+json</code> is recommended.
38-
{% endif %}
39-
{% if operation.x-github.previews.size > 0 %}
38+
{%- endif -%}
39+
{%- if operation.x-github.previews.size > 0 -%}
4040
<a href="#{{operation.slug}}-preview-notices">
41-
{% if operation.x-github.previews.size > 1 %}
42-
{% data ui.products.rest.reference.see_preview_notices %}
43-
{% else %}
44-
{% data ui.products.rest.reference.see_preview_notice %}
45-
{% endif %}
41+
{%- if operation.x-github.previews.size > 1 -%}
42+
{%- data ui.products.rest.reference.see_preview_notices -%}
43+
{%- else -%}
44+
{%- data ui.products.rest.reference.see_preview_notice -%}
45+
{%- endif -%}
4646
</a>
47-
{% endif %}
47+
{%- endif -%}
4848
</p>
4949
</td>
5050
</tr>
51-
{% for param in operation.parameters %}
51+
{%- for param in operation.parameters -%}
5252
<tr>
5353
<td><code>{{ param.name }}</code></td>
5454
<td class="opacity-70">{{ param.schema.type }}</td>
5555
<td class="opacity-70">{{ param.in }}</td>
5656
<td class="opacity-70">
5757
{{ param.descriptionHTML }}
58-
{% if param.schema.default != nil %}
58+
{%- if param.schema.default != nil -%}
5959
Default: <code>{{ param.schema.default }}</code>
60-
{% endif %}
60+
{%- endif -%}
6161
</td>
6262
</tr>
63-
{% endfor %}
64-
{% for bodyParam in operation.bodyParameters %}
63+
{%- endfor -%}
64+
{%- for bodyParam in operation.bodyParameters -%}
6565
<tr>
6666
<td><code>{{ bodyParam.name }}</code></td>
6767
<td class="opacity-70">{{ bodyParam.type }}</td>
6868
<td class="opacity-70">{{ bodyParam.in }}</td>
6969
<td class="opacity-70">
7070
{{ bodyParam.description }}
71-
{% if bodyParam.default != nil %}
71+
{%- if bodyParam.default != nil -%}
7272
Default: <code>{{ bodyParam.default }}</code>
73-
{% endif %}
73+
{%- endif -%}
7474
</td>
7575
</tr>
76-
{% if bodyParam.childParamsGroups.size > 0 %}
76+
{%- if bodyParam.childParamsGroups.size > 0 -%}
7777
<tr style="border: none;">
7878
<td colspan="4" class="has-nested-table">
79-
{% for childParamsGroup in bodyParam.childParamsGroups %}
79+
{%- for childParamsGroup in bodyParam.childParamsGroups -%}
8080
<details>
8181
<summary class="color-text-secondary"><h4 id="{{ childParamsGroup.id }}">Properties of the <code>{{ childParamsGroup.parentName }}</code> {{ childParamsGroup.parentType }}</h4></summary>
8282
<table>
8383
<tbody>
84-
{% for childParam in childParamsGroup.params %}
84+
{%- for childParam in childParamsGroup.params -%}
8585
<tr>
8686
<td class="opacity-60"><code>{{ childParam.name }}</code> ({{ childParam.type }})</td>
8787
<td class="opacity-60">{{ childParam.description }}</td>
8888
</tr>
89-
{% endfor %}
89+
{%- endfor -%}
9090
</tbody>
9191
</table>
9292
</details>
93-
{% endfor %}
93+
{%- endfor -%}
9494
</td>
9595
</tr>
96-
{% endif %}
97-
{% endfor %}
96+
{%- endif -%}
97+
{%- endfor -%}
9898
</tbody>
9999
</table>
100-
{% endif %}
101-
{% if operation.x-codeSamples.size > 0 %}
100+
{%- endif -%}
101+
{%- if operation.x-codeSamples.size > 0 -%}
102102
<h4 id="{{operation.slug}}--code-samples">
103-
<a href="#{{operation.slug}}--code-samples">{% data ui.products.rest.reference.code_samples %}</a>
103+
<a href="#{{operation.slug}}--code-samples">{%- data ui.products.rest.reference.code_samples -%}</a>
104104
</h4>
105-
{% for sample in operation.x-codeSamples %}
106-
{% unless sample.lang == "Ruby" %}
105+
{%- for sample in operation.x-codeSamples -%}
106+
{%- unless sample.lang == "Ruby" -%}
107107
<h5>
108-
{% if sample.lang == "JavaScript" %}
108+
{%- if sample.lang == "JavaScript" -%}
109109
{{sample.lang}} (<a href="https://github.com/octokit/core.js#readme">@octokit/core.js</a>)
110-
{% else %}
110+
{%- else -%}
111111
{{sample.lang}}
112-
{% endif %}
112+
{%- endif -%}
113113
</h5>
114114
{{sample.html}}
115-
{% endunless %}
116-
{% endfor %}
117-
{% endif %}
118-
{% for response in operation.responses %}
115+
{%- endunless -%}
116+
{%- endfor -%}
117+
{%- endif -%}
118+
{%- for response in operation.responses -%}
119119
<h4>{{ response.description }}</h4>
120120
<pre><code>Status: {{ response.httpStatusCode }} {{ response.httpStatusMessage }}</code></pre>
121121
<div class="height-constrained-code-block">{{ response.payload }}</div>
122-
{% endfor %}
123-
{% if operation.notes.size > 0 or operation.x-github.enabledForGitHubApps %}
122+
{%- endfor -%}
123+
{%- if operation.notes.size > 0 or operation.x-github.enabledForGitHubApps -%}
124124
<h4>Notes</h4>
125125
<ul class="mt-2">
126-
{% if operation.x-github.enabledForGitHubApps %}
126+
{%- if operation.x-github.enabledForGitHubApps -%}
127127
<li><a href="{{ restGitHubAppsLink }}">Works with GitHub Apps</a></li>
128-
{% endif %}
129-
{% for note in operation.notes %}
128+
{%- endif -%}
129+
{%- for note in operation.notes -%}
130130
<li>{{ note }}</li>
131-
{% endfor %}
131+
{%- endfor -%}
132132
</ul>
133-
{% endif %}
134-
{% if operation.x-github.previews.size > 0 %}
133+
{%- endif -%}
134+
{%- if operation.x-github.previews.size > 0 -%}
135135
<h4 id="{{operation.slug}}-preview-notices">
136-
{% if operation.x-github.previews.size > 1 %}
137-
{% data ui.products.rest.reference.preview_notices %}
138-
{% else %}
139-
{% data ui.products.rest.reference.preview_notice %}
140-
{% endif %}
136+
{%- if operation.x-github.previews.size > 1 -%}
137+
{%- data ui.products.rest.reference.preview_notices -%}
138+
{%- else -%}
139+
{%- data ui.products.rest.reference.preview_notice -%}
140+
{%- endif -%}
141141
</h4>
142-
{% for preview in operation.x-github.previews %}
142+
{%- for preview in operation.x-github.previews -%}
143143
<div class="extended-markdown note border rounded-1 mb-4 p-3 color-border-info color-bg-info f5">
144144
{{ preview.html }}
145-
{% if preview.required %}☝️ {% data ui.products.rest.reference.preview_header_is_required %}.{% endif %}
145+
{%- if preview.required -%}☝️ {%- data ui.products.rest.reference.preview_header_is_required -%}.{%- endif -%}
146146
</div>
147-
{% endfor %}
148-
{% endif %}
147+
{%- endfor -%}
148+
{%- endif -%}
149149
</div>
150150
<hr>
151151
</div>

lib/get-english-headings.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import astFromMarkdown from 'mdast-util-from-markdown'
2-
import toString from 'mdast-util-to-string'
3-
import visit from 'unist-util-visit'
1+
import { fromMarkdown } from 'mdast-util-from-markdown'
2+
import { toString } from 'mdast-util-to-string'
3+
import { visit } from 'unist-util-visit'
44
import findPage from './find-page.js'
55

66
// for any translated page, first get corresponding English markdown
@@ -41,7 +41,7 @@ export default function getEnglishHeadings(page, context) {
4141
}
4242

4343
function getHeadings(markdown) {
44-
const ast = astFromMarkdown(markdown)
44+
const ast = fromMarkdown(markdown)
4545
const headings = []
4646

4747
visit(ast, (node) => {

lib/render-content/create-processor.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import unified from 'unified'
2-
import markdown from 'remark-parse'
1+
import { unified } from 'unified'
2+
import markdown from 'remark-parse-no-trim'
3+
import markdownNext from 'remark-parse'
4+
import gfm from 'remark-gfm'
35
import emoji from 'remark-gemoji-to-emoji'
46
import remark2rehype from 'remark-rehype'
57
import raw from 'rehype-raw'
@@ -18,7 +20,8 @@ const graphql = xHighlightjsGraphql.definer
1820

1921
export default function createProcessor(context) {
2022
return unified()
21-
.use(markdown)
23+
.use(process.env.COMMONMARK ? markdownNext : markdown)
24+
.use(process.env.COMMONMARK ? gfm : null)
2225
.use(remarkCodeExtra, { transform: codeHeader })
2326
.use(emoji)
2427
.use(remark2rehype, { allowDangerousHtml: true })

lib/render-content/plugins/code-header.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import h from 'hastscript'
1+
import { h } from 'hastscript'
22
import octicons from '@primer/octicons'
33
import parse5 from 'parse5'
4-
import fromParse5 from 'hast-util-from-parse5'
4+
import { fromParse5 } from 'hast-util-from-parse5'
55

66
const LANGUAGE_MAP = {
77
asp: 'ASP',
@@ -94,8 +94,8 @@ export default function addCodeHeader(node) {
9494
const language = LANGUAGE_MAP[node.lang] || node.lang || 'Code'
9595

9696
const btnIconHtml = octicons.clippy.toSVG()
97-
const btnIconAst = parse5.parse(String(btnIconHtml))
98-
const btnIcon = fromParse5(btnIconAst, btnIconHtml)
97+
const btnIconAst = parse5.parse(String(btnIconHtml), { sourceCodeLocationInfo: true })
98+
const btnIcon = fromParse5(btnIconAst, { file: btnIconHtml })
9999

100100
// Need to create the header using Markdown AST utilities, to fit
101101
// into the Unified processor ecosystem.

lib/render-content/plugins/rewrite-legacy-asset-paths.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import visit from 'unist-util-visit'
1+
import { visit } from 'unist-util-visit'
22
import fs from 'fs'
33
import { legacyAssetVersions } from '../../enterprise-server-releases.js'
44
import { allVersions } from '../../all-versions.js'

lib/render-content/plugins/rewrite-local-links.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 visit from 'unist-util-visit'
2+
import { visit } from 'unist-util-visit'
33
import { getPathWithoutLanguage, getVersionStringFromPath } from '../../path-utils.js'
44
import { getNewVersionedPath } from '../../old-versions-utils.js'
55
import patterns from '../../patterns.js'

lib/render-content/plugins/use-english-headings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import GithubSlugger from 'github-slugger'
22
import xHtmlEntities from 'html-entities'
33
import toString from 'hast-util-to-string'
4-
import visit from 'unist-util-visit'
4+
import { visit } from 'unist-util-visit'
55
const Entities = xHtmlEntities.XmlEntities
66
const slugger = new GithubSlugger()
77
const entities = new Entities()

lib/render-content/plugins/wrap-in-element.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import visit from 'unist-util-visit'
1+
import { visit } from 'unist-util-visit'
22
import { selectAll } from 'hast-util-select'
3-
import parseSelector from 'hast-util-parse-selector'
3+
import { parseSelector } from 'hast-util-parse-selector'
44

55
/*
66
* Attacher

0 commit comments

Comments
 (0)