@@ -118,12 +118,16 @@ Some linting rules return warnings or errors based on HTML comments that you can
|
||||
|
||||
Rules `GHD038` and `GHD039` check for content that has been manually given an expiration date. Fourteen days before the specified date, the content linter will return a warning that the content is expiring soon. Starting on the specified date, the content linter will return an error and flag the content for remediation.
|
||||
|
||||
You can add an expiration date to content by wrapping it in HTML tags that contain an expiration date in the format: <pre><!-- expires yyyy-mm-dd --> <!-- end expires yyyy-mm-dd --></pre>
|
||||
You can add an expiration date to content by wrapping it in HTML tags that contain an expiration date in the format: `<!-- expires yyyy-mm-dd --> <!-- end expires yyyy-mm-dd -->`
|
||||
|
||||
**Use:**
|
||||
|
||||
```markdown
|
||||
This content does not expire. {% raw %}<{% endraw %}!-- expires 2022-01-28 -->This content expires on January 28, 2022. {% raw %}<{% endraw %}!-- end expires 2022-01-28 -->This content also does not expire.
|
||||
This content does not expire.
|
||||
<!-- expires 2022-01-28 -->
|
||||
This content expires on January 28, 2022.
|
||||
<!-- end expires 2022-01-28 -->
|
||||
This content also does not expire.
|
||||
```
|
||||
|
||||
## Suppressing linter rules
|
||||
@@ -133,19 +137,19 @@ Rarely, you may need to document something that violates one or more linter rule
|
||||
<!-- markdownlint-disable MD011 -->
|
||||
For example, if you are writing an article that includes the regular expression `(^|/)[Cc]+odespace/` that checks for reversed link syntax, it will trigger the `MD011` rule that checks for reversed links. You can disable the rule `MD011` on that specific line by adding the following comment.
|
||||
|
||||
<pre>
|
||||
(^|/)[Cc]+odespace/ <!-- markdownlint-disable-line MD011 -->
|
||||
</pre>
|
||||
```text
|
||||
(^|/)[Cc]+odespace/ <!-- markdownlint-disable-line MD011 -->
|
||||
```
|
||||
|
||||
If the line you're trying to ignore is in a code block, you can ignore the code block by surrounding it with the following comments.
|
||||
|
||||
<pre>
|
||||
<!-- markdownlint-disable MD011 -->
|
||||
````text
|
||||
<!-- markdownlint-disable MD011 -->
|
||||
```
|
||||
(^|/)[Cc]+odespace/
|
||||
```
|
||||
<!-- markdownlint-enable MD011 -->
|
||||
</pre>
|
||||
<!-- markdownlint-enable MD011 -->
|
||||
````
|
||||
|
||||
<!-- markdownlint-enable MD011 -->
|
||||
|
||||
@@ -153,11 +157,11 @@ You can use these comments to enable or disable rules.
|
||||
|
||||
| Comment | Effect |
|
||||
| :-- | :-- |
|
||||
| <pre><!-- markdownlint-disable --></pre> | Disable all rules |
|
||||
| <pre><!-- markdownlint-enable --></pre> | Enable all rules |
|
||||
| <pre><!-- markdownlint-disable-line --></pre> | Disable all rules for the current line |
|
||||
| <pre><!-- markdownlint-disable-next-line --></pre> | Disable all rules for the next line |
|
||||
| <pre><!-- markdownlint-disable RULE-ONE RULE-TWO --></pre> | Disable one or more rules by name |
|
||||
| <pre><!-- markdownlint-enable RULE-ONE RULE-TWO --></pre> | Enable one or more rules by name |
|
||||
| <pre><!-- markdownlint-disable-line RULE-NAME --></pre> | Disable one or more rules by name for the current line |
|
||||
| <pre><!-- markdownlint-disable-next-line RULE-NAME --></pre> | Disable one or more rules by name for the next line |
|
||||
| `<!-- markdownlint-disable -->`<!-- markdownlint-restore --> | Disable all rules |
|
||||
| `<!-- markdownlint-enable -->`<!-- markdownlint-restore -->| Enable all rules |
|
||||
| `<!-- markdownlint-disable-line -->`<!-- markdownlint-restore --> | Disable all rules for the current line |
|
||||
| `<!-- markdownlint-disable-next-line -->`<!-- markdownlint-restore --> | Disable all rules for the next line |
|
||||
| `<!-- markdownlint-disable RULE-ONE RULE-TWO -->`|<!-- markdownlint-restore --> | Disable one or more rules by name |
|
||||
| `<!-- markdownlint-enable RULE-ONE RULE-TWO -->`<!-- markdownlint-restore --> | Enable one or more rules by name |
|
||||
| `<!-- markdownlint-disable-line RULE-NAME -->`<!-- markdownlint-restore --> | Disable one or more rules by name for the current line |
|
||||
| `<!-- markdownlint-disable-next-line RULE-NAME -->`<!-- markdownlint-restore --> | Disable one or more rules by name for the next line |
|
||||
|
||||
@@ -73,7 +73,7 @@ Use `git status` to list all new or modified files that haven't yet been committ
|
||||
|
||||
To format code or text into its own distinct block, use triple backticks.
|
||||
|
||||
````text
|
||||
````markdown
|
||||
Some basic Git commands are:
|
||||
```
|
||||
git status
|
||||
@@ -373,9 +373,9 @@ Here are the rendered alerts:
|
||||
|
||||
You can tell {% data variables.product.product_name %} to hide content from the rendered Markdown by placing the content in an HTML comment.
|
||||
|
||||
<pre>
|
||||
<!-- This content will not appear in the rendered Markdown -->
|
||||
</pre>
|
||||
```text
|
||||
<!-- This content will not appear in the rendered Markdown -->
|
||||
```
|
||||
|
||||
## Ignoring Markdown formatting
|
||||
|
||||
|
||||
@@ -191,20 +191,20 @@ You can use HTML comment syntax to add a comment that will be hidden in the outp
|
||||
|
||||
1. Two lines below the `## About me` header, insert a comment by using the following markup.
|
||||
|
||||
<pre>
|
||||
<!-- COMMENT -->
|
||||
</pre>
|
||||
```text
|
||||
<!-- COMMENT -->
|
||||
```
|
||||
|
||||
Replace `COMMENT` with a "to-do" item you remind yourself to do something later (for example, to add more items to the table).
|
||||
1. To check your comment is hidden in the output, click the **Preview** tab.
|
||||
|
||||
### Example of a comment
|
||||
|
||||
<pre>
|
||||
```markdown
|
||||
## About me
|
||||
|
||||
<!-- TO DO: add more details about me later -->
|
||||
</pre>
|
||||
<!-- TO DO: add more details about me later -->
|
||||
```
|
||||
|
||||
## Saving your work
|
||||
|
||||
|
||||
47
package-lock.json
generated
47
package-lock.json
generated
@@ -79,13 +79,13 @@
|
||||
"remark-gfm": "^4.0.0",
|
||||
"remark-parse": "^11.0.0",
|
||||
"remark-rehype": "^11.1.0",
|
||||
"remark-remove-comments": "^1.0.1",
|
||||
"rss-parser": "^3.13.0",
|
||||
"scroll-anchoring": "^0.1.0",
|
||||
"semver": "^7.6.2",
|
||||
"sharp": "0.33.1",
|
||||
"slash": "^5.1.0",
|
||||
"strip-ansi": "7.1.0",
|
||||
"strip-html-comments": "^1.0.0",
|
||||
"styled-components": "^5.3.5",
|
||||
"swr": "^2.2.4",
|
||||
"tcp-port-used": "1.0.2",
|
||||
@@ -8078,6 +8078,11 @@
|
||||
"node": ">=14"
|
||||
}
|
||||
},
|
||||
"node_modules/html-comment-regex": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/html-comment-regex/-/html-comment-regex-1.1.2.tgz",
|
||||
"integrity": "sha512-P+M65QY2JQ5Y0G9KKdlDpo0zK+/OHptU5AaBwUfAIDJZk1MYf32Frm84EcOytfJE0t5JvkAnKlmjsXDnWzCJmQ=="
|
||||
},
|
||||
"node_modules/html-entities": {
|
||||
"version": "2.5.2",
|
||||
"resolved": "https://registry.npmjs.org/html-entities/-/html-entities-2.5.2.tgz",
|
||||
@@ -12736,6 +12741,42 @@
|
||||
"url": "https://opencollective.com/unified"
|
||||
}
|
||||
},
|
||||
"node_modules/remark-remove-comments": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/remark-remove-comments/-/remark-remove-comments-1.0.1.tgz",
|
||||
"integrity": "sha512-aoBnwdr9VjMdRYkKLzU2MD11KuxLAiCYGFimR79z7DIzfmC8yjohbpCl9x/6+qx0SpPnfZ2aFBFa2QPXPdT/LQ==",
|
||||
"dependencies": {
|
||||
"html-comment-regex": "^1.1.2",
|
||||
"unist-util-visit": "^4.1.1"
|
||||
}
|
||||
},
|
||||
"node_modules/remark-remove-comments/node_modules/unist-util-visit": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-4.1.2.tgz",
|
||||
"integrity": "sha512-MSd8OUGISqHdVvfY9TPhyK2VdUrPgxkUtWSuMHF6XAAFuL4LokseigBnZtPnJMu+FbynTkFNnFlyjxpVKujMRg==",
|
||||
"dependencies": {
|
||||
"@types/unist": "^2.0.0",
|
||||
"unist-util-is": "^5.0.0",
|
||||
"unist-util-visit-parents": "^5.1.1"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
}
|
||||
},
|
||||
"node_modules/remark-remove-comments/node_modules/unist-util-visit-parents": {
|
||||
"version": "5.1.3",
|
||||
"resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-5.1.3.tgz",
|
||||
"integrity": "sha512-x6+y8g7wWMyQhL1iZfhIPhDAs7Xwbn9nRosDXl7qoPTSCy0yNxnKc+hWokFifWQIDGi154rdUqKvbCa4+1kLhg==",
|
||||
"dependencies": {
|
||||
"@types/unist": "^2.0.0",
|
||||
"unist-util-is": "^5.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
}
|
||||
},
|
||||
"node_modules/remark-stringify": {
|
||||
"version": "11.0.0",
|
||||
"resolved": "https://registry.npmjs.org/remark-stringify/-/remark-stringify-11.0.0.tgz",
|
||||
@@ -13637,10 +13678,6 @@
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/strip-html-comments": {
|
||||
"version": "1.0.0",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/strip-json-comments": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz",
|
||||
|
||||
@@ -266,13 +266,13 @@
|
||||
"remark-gfm": "^4.0.0",
|
||||
"remark-parse": "^11.0.0",
|
||||
"remark-rehype": "^11.1.0",
|
||||
"remark-remove-comments": "^1.0.1",
|
||||
"rss-parser": "^3.13.0",
|
||||
"scroll-anchoring": "^0.1.0",
|
||||
"semver": "^7.6.2",
|
||||
"sharp": "0.33.1",
|
||||
"slash": "^5.1.0",
|
||||
"strip-ansi": "7.1.0",
|
||||
"strip-html-comments": "^1.0.0",
|
||||
"styled-components": "^5.3.5",
|
||||
"swr": "^2.2.4",
|
||||
"tcp-port-used": "1.0.2",
|
||||
|
||||
@@ -469,6 +469,9 @@ function formatResult(object, isPrecommit) {
|
||||
|
||||
// Add severity to each result object
|
||||
const ruleName = object.ruleNames[1] || object.ruleNames[0]
|
||||
if (!allConfig[ruleName]) {
|
||||
throw new Error(`Rule not found in allConfig: '${ruleName}'`)
|
||||
}
|
||||
formattedResult.severity =
|
||||
allConfig[ruleName].severity || getSearchReplaceRuleSeverity(ruleName, object, isPrecommit)
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { processLiquidPre } from './pre.js'
|
||||
import { processLiquidPost } from './post.js'
|
||||
import { engine } from './engine.js'
|
||||
|
||||
export async function renderLiquid(template, context) {
|
||||
template = processLiquidPre(template)
|
||||
template = await engine.parseAndRender(template, context)
|
||||
template = processLiquidPost(template)
|
||||
return template
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
import stripHtmlComments from 'strip-html-comments'
|
||||
|
||||
export function processLiquidPre(template) {
|
||||
template = removeHtmlComments(template)
|
||||
return template
|
||||
}
|
||||
|
||||
function removeHtmlComments(template) {
|
||||
// remove any newlines that precede html comments, then remove the comments
|
||||
template = template.replace(/\n<!--/g, '<!--')
|
||||
template = stripHtmlComments(template)
|
||||
return template
|
||||
}
|
||||
@@ -54,45 +54,6 @@ describe('renderContent', () => {
|
||||
expect(output, 'my favorite color is orange.')
|
||||
})
|
||||
|
||||
test('throws on rendering errors', async () => {
|
||||
const template = 1
|
||||
const context = {}
|
||||
|
||||
let err
|
||||
|
||||
try {
|
||||
await renderContent(template, context)
|
||||
} catch (_err) {
|
||||
err = _err
|
||||
}
|
||||
|
||||
expect(err).toBeTruthy()
|
||||
})
|
||||
|
||||
test('warns and throws on rendering errors when the file name is passed', async () => {
|
||||
const template = 1
|
||||
const context = {}
|
||||
|
||||
let err
|
||||
let warned = false
|
||||
|
||||
const error = console.error
|
||||
console.error = (message) => {
|
||||
expect(message, 'renderContent failed on file: name')
|
||||
console.error = error
|
||||
warned = true
|
||||
}
|
||||
|
||||
try {
|
||||
await renderContent(template, context, { filename: 'name' })
|
||||
} catch (_err) {
|
||||
err = _err
|
||||
}
|
||||
|
||||
expect(err).toBeTruthy()
|
||||
expect(warned).toBeTruthy()
|
||||
})
|
||||
|
||||
test('renders empty templates', async () => {
|
||||
const template = ''
|
||||
const context = {}
|
||||
|
||||
@@ -28,11 +28,13 @@ import parseInfoString from './parse-info-string.js'
|
||||
import annotate from './annotate.js'
|
||||
import alerts from './alerts.js'
|
||||
import replaceDomain from './replace-domain.js'
|
||||
import removeHtmlComments from 'remark-remove-comments'
|
||||
|
||||
export function createProcessor(context) {
|
||||
return (
|
||||
unified()
|
||||
.use(remarkParse)
|
||||
.use(removeHtmlComments)
|
||||
.use(gfm)
|
||||
// Markdown AST below vvv
|
||||
.use(parseInfoString)
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
---
|
||||
title: HTML comments
|
||||
intro: Certain HTML comments should be deleted, some should be preserved
|
||||
versions:
|
||||
fpt: '*'
|
||||
ghes: '*'
|
||||
ghec: '*'
|
||||
type: how_to
|
||||
---
|
||||
|
||||
## Introduction
|
||||
|
||||
If you're looking at this page fully rendered in a browser, if you view
|
||||
source of this page, you should not find a HTML comment in the HTML that
|
||||
mentions the word `gooblygook`.
|
||||
|
||||
<!-- This comment should get deleted since it mentions gooblygook -->
|
||||
|
||||
<!--
|
||||
|
||||
Another multi-line
|
||||
HTML comments that also
|
||||
mentions the word `gooblygook`
|
||||
|
||||
-->
|
||||
|
||||
```html
|
||||
This is a <!-- html comment -->
|
||||
```
|
||||
|
||||
You can use HTML comments inside the `<-- paragraph -->`
|
||||
|
||||
## Tables are OK too
|
||||
|
||||
| Comment | Effect |
|
||||
| :-- | :-- |
|
||||
| `<!-- markdownlint-disable -->` | Disable all rules |
|
||||
| `<!-- markdownlint-enable -->` | Enable all rules |
|
||||
@@ -11,4 +11,5 @@ children:
|
||||
- /code-annotations
|
||||
- /alerts
|
||||
- /replace-domain
|
||||
- /html-comments
|
||||
---
|
||||
|
||||
16
src/fixtures/tests/html-comments.js
Normal file
16
src/fixtures/tests/html-comments.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { describe, expect, test } from 'vitest'
|
||||
|
||||
import { getDOMCached as getDOM } from '#src/tests/helpers/e2etest.js'
|
||||
|
||||
describe('html-comments', () => {
|
||||
test('regular comments are removed', async () => {
|
||||
const $ = await getDOM('/get-started/markdown/html-comments')
|
||||
const contents = $('#article-contents')
|
||||
const html = contents.html()
|
||||
expect(html).not.toContain('This comment should get deleted since it mentions gooblygook')
|
||||
expect(html).toContain('<code><-- paragraph --></code>')
|
||||
expect(html).toContain('<span class="hljs-comment"><!-- html comment --></span>')
|
||||
expect(html).toContain('<code><!-- markdownlint-disable --></code>')
|
||||
expect(html).not.toContain('Another multi-line')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user