Skip to content

Commit c98d12e

Browse files
authored
Add line numbers and line highlight (#1254)
1 parent 8608e32 commit c98d12e

File tree

5 files changed

+40
-7
lines changed

5 files changed

+40
-7
lines changed

.babelrc

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
{
2-
"presets": [
3-
"react-app",
2+
"presets": ["react-app"],
3+
"plugins": [
4+
[
5+
"prismjs",
6+
{
7+
"languages": ["javascript", "css", "python", "html"],
8+
"plugins": [
9+
"line-numbers",
10+
"line-highlight",
11+
"highlight-keywords",
12+
"normalize-whitespace"
13+
],
14+
"theme": "twilight",
15+
"css": true
16+
}
17+
]
418
]
519
}

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
77
## Unreleased
88

99
### Added
10+
1011
- Sidebar plugin functionality (#1251)
1112

1213
### Changed
1314

1415
- Changed `set_pixel` to quantise the colour before writing (#1247)
16+
- Changed Prism config to use babel plugin enabling line highlighting and numbering (#1254)
1517

1618
## [0.31.1] - 2025-09-19
1719

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
"babel-jest": "^29.1.2",
122122
"babel-loader": "^8.2.5",
123123
"babel-plugin-named-asset-import": "^0.3.7",
124+
"babel-plugin-prismjs": "^2.1.0",
124125
"babel-preset-react-app": "^10.0.1",
125126
"bfj": "^7.0.2",
126127
"camelcase": "^6.1.0",

src/components/Menus/Sidebar/InstructionsPanel/InstructionsPanel.jsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,27 @@ import { Tabs, TabList, Tab, TabPanel } from "react-tabs";
88

99
import ProgressBar from "./ProgressBar/ProgressBar";
1010
import "../../../../assets/stylesheets/Instructions.scss";
11-
import "prismjs/plugins/highlight-keywords/prism-highlight-keywords.js";
12-
import "prismjs/plugins/line-highlight/prism-line-highlight";
13-
import "prismjs/plugins/line-numbers/prism-line-numbers.css";
14-
import "prismjs/plugins/line-highlight/prism-line-highlight.css";
1511
import { quizReadyEvent } from "../../../../events/WebComponentCustomEvents";
1612
import { setCurrentStepPosition } from "../../../../redux/InstructionsSlice";
1713
import DesignSystemButton from "../../../DesignSystemButton/DesignSystemButton";
1814
import { setProjectInstructions } from "../../../../redux/EditorSlice";
1915
import demoInstructions from "../../../../assets/markdown/demoInstructions.md";
2016
import RemoveInstructionsModal from "../../../Modals/RemoveInstructionsModal";
2117
import Prism from "prismjs";
22-
import "prismjs/components/prism-python";
2318
import populateMarkdownTemplate from "../../../../utils/populateMarkdownTemplate";
2419

2520
const InstructionsPanel = () => {
21+
useEffect(() => {
22+
// prism and prism plugin config
23+
Prism.manual = true;
24+
if (Prism.plugins.NormalizeWhitespace) {
25+
Prism.plugins.NormalizeWhitespace.setDefaults({
26+
"remove-indent": false,
27+
"remove-initial-line-feed": true,
28+
"left-trim": false,
29+
});
30+
}
31+
}, []);
2632
const [showModal, setShowModal] = useState(false);
2733
const instructionsEditable = useSelector(
2834
(state) => state.editor?.instructionsEditable,

yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2781,6 +2781,7 @@ __metadata:
27812781
babel-jest: ^29.1.2
27822782
babel-loader: ^8.2.5
27832783
babel-plugin-named-asset-import: ^0.3.7
2784+
babel-plugin-prismjs: ^2.1.0
27842785
babel-preset-react-app: ^10.0.1
27852786
bfj: ^7.0.2
27862787
camelcase: ^6.1.0
@@ -5411,6 +5412,15 @@ __metadata:
54115412
languageName: node
54125413
linkType: hard
54135414

5415+
"babel-plugin-prismjs@npm:^2.1.0":
5416+
version: 2.1.0
5417+
resolution: "babel-plugin-prismjs@npm:2.1.0"
5418+
peerDependencies:
5419+
prismjs: ^1.18.0
5420+
checksum: 8bc59ca46b493cb255ec914e26a0dd39c1aaee881e3701d6726db40152d4a176a96ac1438f80b0d705b188bee4106538de809bc79dff9774400da3d8331affce
5421+
languageName: node
5422+
linkType: hard
5423+
54145424
"babel-plugin-syntax-object-rest-spread@npm:^6.8.0":
54155425
version: 6.13.0
54165426
resolution: "babel-plugin-syntax-object-rest-spread@npm:6.13.0"

0 commit comments

Comments
 (0)