Skip to content
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

XS✔ ◾ Improved content + readability "set-language-on-code-blocks" #9429

Merged
merged 2 commits into from
Oct 16, 2024
Merged
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
19 changes: 8 additions & 11 deletions rules/set-language-on-code-blocks/rule.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
type: rule
title: Markdown – Do you set the language on code blocks?
title: Do you set the language on code blocks?
uri: set-language-on-code-blocks
authors:
- title: Adam Cogan
Expand All @@ -13,20 +13,17 @@ guid: 1f4e6b03-d6d3-45ca-9a8f-9595f3ff5fd5

You should have a syntax highlighter to show pieces of code on your pages for a better readability. By specifying the language within your code block, you can enable color coding similar to that in an IDE.

Examples:

* [Prism](https://prismjs.com)
* [highlight.js](https://highlightjs.org)
Tools like [Prism](https://prismjs.com), [highlight.js](https://highlightjs.org), or [Code Prettify](https://github.com/googlearchive/code-prettify) automatically apply syntax highlighting, making it easier for users to read code by color-coding different elements (e.g., keywords, strings, and variables).

<!--endintro-->

::: info
See this [json file](https://unpkg.com/[email protected]/lib/grammars/manifest.json) for all supported languages and their aliases we can use in SSW Rules.
See this [json file](https://unpkg.com/[email protected]/lib/grammars/manifest.json) for all supported languages and their aliases that can be used in SSW Rules.
:::

To activate this feature, add the language name right after the opening [3 backticks used to write a code in Markdown](https://www.ssw.com.au/rules/rule/#11-code). For example, instead of starting a JavaScript code example with just <code>\`\`\`</code>, you should use <code>\`\`\`js</code> or <code>\`\`\`javascript</code> for highlighting.
To activate this feature, add the language name right after the opening 3 backticks (used to [write a code in Markdown](https://www.ssw.com.au/rules/rule/#11-code)).

::: bad
For example, instead of starting a **JavaScript** code example with: **<code>\`\`\`</code>**, you should use **<code>\`\`\`js</code>** or **<code>\`\`\`javascript</code>** for syntax highlighting.

```none
let iceCream = 'chocolate';
Expand All @@ -37,12 +34,11 @@ if (iceCream === 'chocolate') {
alert('Awwww, but chocolate is my favorite...');
}
```


::: bad
Figure: Bad example - No syntax highlighting
:::

::: good

```javascript
let iceCream = 'chocolate';

Expand All @@ -53,6 +49,7 @@ if (iceCream === 'chocolate') {
}
```

::: good
Figure: Good example - This JavaScript code block shows its syntax highlighted
:::

Expand Down