Skip to content

Commit dad34fb

Browse files
1 parent 3f5baa7 commit dad34fb

4 files changed

Lines changed: 36 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2222
- Add remove instructions button modal (#1176)
2323
- Dark mode colours (#1182)
2424
- Dark mode for instuctions code block (#1187)
25+
- Change markdown links to open in new tab (#1188)
2526

2627
### Changed
2728

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
/* eslint-disable jsx-a11y/anchor-has-content */
2+
// This is disabled because the empty anchor tag is used for translation and will have content when rendered.
13
import React, { useEffect, useRef, useMemo, useState } from "react";
24
import SidebarPanel from "../SidebarPanel";
35
import { Trans, useTranslation } from "react-i18next";
46
import { useSelector, useDispatch } from "react-redux";
57
import { Tabs, TabList, Tab, TabPanel } from "react-tabs";
6-
import { Link } from "react-router-dom";
78

89
import ProgressBar from "./ProgressBar/ProgressBar";
910
import "../../../../assets/stylesheets/Instructions.scss";
@@ -198,8 +199,8 @@ const InstructionsPanel = () => {
198199
<Trans
199200
i18nKey="instructionsPanel.emptyState.markdown"
200201
components={[
201-
<Link
202-
href="https://commonmark.org/help/"
202+
<a
203+
href="https://www.markdownguide.org/cheat-sheet/"
203204
target="_blank"
204205
rel="noreferrer"
205206
/>,

src/components/WebComponentProject/WebComponentProject.jsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const WebComponentProject = ({
6060
const isMobile = useMediaQuery({ query: MOBILE_MEDIA_QUERY });
6161
const [codeHasRun, setCodeHasRun] = useState(codeHasBeenRun);
6262
const dispatch = useDispatch();
63+
const renderer = new marked.Renderer();
6364

6465
useEffect(() => {
6566
dispatch(setIsSplitView(outputSplitView));
@@ -82,6 +83,15 @@ const WebComponentProject = ({
8283
}
8384
}, [projectIdentifier]);
8485

86+
renderer.link = function (data) {
87+
return `<a href="${data.href}" target="_blank" rel="noreferrer"
88+
}">${data.text}</a>`;
89+
};
90+
91+
marked.setOptions({
92+
renderer: renderer,
93+
});
94+
8595
useEffect(() => {
8696
if (!permitInstructionsOverride) return;
8797

src/components/WebComponentProject/WebComponentProject.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,27 @@ describe("When state set", () => {
114114
});
115115
});
116116

117+
describe("When there are instructions", () => {
118+
beforeEach(() => {
119+
renderWebComponentProject({
120+
instructions: "[Link](https://example.com)",
121+
codeRunTriggered: true,
122+
});
123+
});
124+
125+
test("Renders a tag with target _blank", () => {
126+
const instructions = store
127+
.getActions()
128+
.find((e) => e.type === "instructions/setInstructions");
129+
130+
const content = instructions.payload.project.steps[0].content;
131+
132+
expect(content).toEqual(
133+
'<p><a href="https://example.com" target="_blank" rel="noreferrer"\n }">Link</a></p>\n',
134+
);
135+
});
136+
});
137+
117138
describe("When there are no instructions", () => {
118139
beforeEach(() => {
119140
renderWebComponentProject({});

0 commit comments

Comments
 (0)