Skip to content

Commit 9e9da5d

Browse files
committed
add myst
1 parent 98b1e20 commit 9e9da5d

File tree

8 files changed

+1593
-43
lines changed

8 files changed

+1593
-43
lines changed

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,17 @@
3838
"graphql": "16.11.0",
3939
"graphql-tag": "2.12.6",
4040
"lodash-es": "4.17.21",
41-
"markdown-it": "14.1.0",
4241
"mitt": "3.0.1",
42+
"myst-parser": "1.5.12",
43+
"myst-theme": "0.0.0",
44+
"myst-to-html": "1.5.12",
4345
"nprogress": "1.0.0-1",
4446
"preact": "10.26.5",
47+
"rehype-stringify": "^10.0.1",
4548
"simple-icons": "2.19.0",
4649
"subscriptions-transport-ws": "0.11.0",
4750
"svg-pan-zoom": "3.6.2",
51+
"unified": "11.0.5",
4852
"vue": "3.5.16",
4953
"vue-i18n": "11.1.3",
5054
"vue-router": "4.5.1",

renovate.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,17 @@
145145
"addLabels": [
146146
"data workflows team"
147147
]
148+
},
149+
{
150+
"groupName": "MyST packages",
151+
"matchPackageNames": [
152+
"myst-*",
153+
"rehype-stringify",
154+
"unified"
155+
],
156+
"schedule": [
157+
"on the 23rd day of the month"
158+
]
148159
}
149160
],
150161
"vulnerabilityAlerts": {

src/components/Markdown.vue

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,17 @@
2424
</template>
2525

2626
<script>
27-
import MarkdownIt from 'markdown-it'
28-
29-
const md = new MarkdownIt()
27+
import { mystParser } from 'myst-parser'
28+
import { State, transform, mystToHast, formatHtml } from 'myst-to-html'
29+
import rehypeStringify from 'rehype-stringify'
30+
import { unified } from 'unified'
31+
32+
const pipe = unified()
33+
.use(mystParser)
34+
.use(transform, new State())
35+
.use(mystToHast)
36+
.use(formatHtml)
37+
.use(rehypeStringify)
3038
3139
export default {
3240
name: 'Markdown',
@@ -40,7 +48,7 @@ export default {
4048
4149
computed: {
4250
html () {
43-
return md.render(this.markdown)
51+
return pipe.processSync(this.markdown).value
4452
}
4553
}
4654
}

src/components/cylc/Info.vue

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
5454
</v-expansion-panel-title>
5555
<v-expansion-panel-text>
5656
<dl>
57-
<dt>Title</dt>
58-
<dd>{{ taskMetadata.title }}</dd>
59-
<v-divider />
60-
<dt>Description</dt>
61-
<dd><span class="markup">{{ taskMetadata.description }}</span></dd>
57+
<dt><h1 class="meta-title">{{ taskMetadata.title || '(Title)'}}</h1></dt>
6258
<v-divider />
6359
<dt>URL</dt>
6460
<dd>
@@ -75,9 +71,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
7571
</a>
7672
</dd>
7773
<v-divider />
74+
<dt>Description</dt>
75+
<dd><Markdown :markdown="taskMetadata.description || ''"/></dd>
76+
<v-divider />
7877
<template v-for="(value, key) in customMetadata" :key="key">
7978
<dt>{{ key }}</dt>
80-
<dd><span class="markup">{{ value }}</span></dd>
79+
<dd><Markdown :markdown="value"/></dd>
8180
<v-divider />
8281
</template>
8382
</dl>
@@ -168,12 +167,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
168167
<script>
169168
import { useJobTheme } from '@/composables/localStorage'
170169
import GraphNode from '@/components/cylc/GraphNode.vue'
170+
import Markdown from '@/components/Markdown.vue'
171171
import { formatCompletion } from '@/utils/outputs'
172172
173173
export default {
174174
name: 'InfoComponent',
175175
176176
components: {
177+
Markdown,
177178
GraphNode,
178179
},
179180

src/services/mock/json/infoView.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,17 @@
1414
"meanElapsedTime": "10",
1515
"meta": {
1616
"title": "Failed Task",
17-
"description": "A task that always fails!",
17+
"description": "# A task that always fails!\n\n - Bullet point\n - Bullet 🐜\n",
1818
"URL": "https://cylc.org",
1919
"userDefined": {
20-
"my custom field": "My custom value!"
20+
"my custom field": "My custom value!",
21+
"Links and images": "[Great Auk - link example](https://en.wikipedia.org/wiki/Great_Auk)\n\n![Great Auk](https://upload.wikimedia.org/wikipedia/commons/4/4e/Great_Auk_%28Pinguinis_impennis%29_specimen%2C_Kelvingrove%2C_Glasgow_-_geograph.org.uk_-_1108249.jpg)",
22+
"Admonitions": ":::{note}\nB-flat\n:::\n\n:::{tip}\nMy Shed\n:::\n\n:::{warning}\nLive without...\n:::\n\n:::{danger}\nMouse\n:::\n\n:::{caution}\nHorses\n:::",
23+
"Titles": "## Level 2\n### Level 3\n#### Level 4\n##### Level 5\n###### Level 6",
24+
"Tables": "| Header 1 | Header 2 |\n| -------- | -------- |\n| Row 1 | Row 2 |\n| Row 3 | Row 4 |\n",
25+
"List Table": ":::{list-table}\n:header-rows: 1\n\n* - Header 1\n - Header 2\n* - Row 1\n - Row 2\n* - Row 3\n - Row 4\n:::\n",
26+
"Code blocks": "```python\n# Python\nprint('Hello, world!')\n```\n\n```bash\n# bash\nls -l\n```\n",
27+
"Maths": "Inline math: $E=mc^2$ and block math:\n\n$$\n\\int_0^1 x^2 \\, dx = \\frac{1}{3}\n$$\n"
2128
}
2229
}
2330
},

src/styles/cylc/_markdown.scss

Lines changed: 181 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,183 @@
1-
/**
2-
* Copyright (C) NIWA & British Crown (Met Office) & Contributors.
3-
*
4-
* This program is free software: you can redistribute it and/or modify
5-
* it under the terms of the GNU General Public License as published by
6-
* the Free Software Foundation, either version 3 of the License, or
7-
* (at your option) any later version.
8-
*
9-
* This program is distributed in the hope that it will be useful,
10-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
* GNU General Public License for more details.
13-
*
14-
* You should have received a copy of the GNU General Public License
15-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16-
*/
1+
// This is code taken from jupyter-book/mystmd project
2+
// https://github.com/jupyter-book/mystmd/blob/01efd316754aee61f0e95fb5b1c5c9b35a23c5b9/packages/myst-parser/myst.css
3+
// and modified to fit the needs of the Cylc project.
4+
// The original license is as follows:
5+
6+
// The MIT License (MIT)
7+
8+
// Copyright (c) 2024 Project Jupyter
9+
10+
// Permission is hereby granted, free of charge, to any person obtaining a copy
11+
// of this software and associated documentation files (the "Software"), to deal
12+
// in the Software without restriction, including without limitation the rights
13+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
// copies of the Software, and to permit persons to whom the Software is
15+
// furnished to do so, subject to the following conditions:
16+
17+
// The above copyright notice and this permission notice shall be included in all
18+
// copies or substantial portions of the Software.
19+
20+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
// SOFTWARE.
27+
28+
aside.admonition {
29+
width: 95%;
30+
margin: 1.5625em auto;
31+
padding: 0 0.6rem 0.8rem !important;
32+
overflow: hidden;
33+
page-break-inside: avoid;
34+
border-left: 0.2rem solid #007bff;
35+
border-radius: 0.1rem;
36+
box-shadow: 0 0.2rem 0.5rem rgba(0, 0, 0, 0.05), 0 0 0.05rem rgba(0, 0, 0, 0.1);
37+
}
38+
39+
aside.admonition > p.admonition-title {
40+
position: relative;
41+
margin: 0 -0.6rem !important;
42+
/* Changed the final from 2rem, without icon */
43+
padding: 0.4rem 0.6rem 0.4rem 1rem;
44+
font-weight: 700;
45+
background-color: #e7f2fa;
46+
}
47+
48+
aside.admonition.attention {
49+
border-left-color: #fd7e14;
50+
}
51+
aside.admonition.attention > header {
52+
background-color: #ffedcc;
53+
}
54+
aside.admonition.caution {
55+
border-left-color: #fd7e14;
56+
}
57+
aside.admonition.caution > header {
58+
background-color: #ffedcc;
59+
}
60+
aside.admonition.warning {
61+
border-left-color: #dc3545;
62+
}
63+
aside.admonition.warning > header {
64+
background-color: #fdf3f2;
65+
}
66+
aside.admonition.danger {
67+
border-left-color: #dc3545;
68+
}
69+
aside.admonition.danger > header {
70+
background-color: #fdf3f2;
71+
}
72+
aside.admonition.error {
73+
border-left-color: #dc3545;
74+
}
75+
aside.admonition.error > header {
76+
background-color: #fdf3f2;
77+
}
78+
aside.admonition.hint {
79+
border-left-color: #ffc107;
80+
}
81+
aside.admonition.hint > header {
82+
background-color: #fff6dd;
83+
}
84+
aside.admonition.important {
85+
border-left-color: #007bff;
86+
}
87+
aside.admonition.important > header {
88+
background-color: #e7f2fa;
89+
}
90+
aside.admonition.note {
91+
border-left-color: #007bff;
92+
}
93+
aside.admonition.note > header {
94+
background-color: #e7f2fa;
95+
}
96+
aside.admonition.tip {
97+
border-left-color: #ffc107;
98+
}
99+
aside.admonition.tip > header {
100+
background-color: #fff6dd;
101+
}
102+
103+
aside.admonition > p {
104+
padding: 0 1.4rem;
105+
}
106+
107+
abbr {
108+
text-decoration: none;
109+
border-bottom: 1px solid #ddd;
110+
cursor: help;
111+
}
112+
113+
a {
114+
color: #0071bc;
115+
text-decoration: none;
116+
}
117+
118+
a:hover {
119+
text-decoration: underline;
120+
}
121+
122+
code {
123+
font-size: 95%;
124+
font-family: monospace;
125+
color: #e83e8c;
126+
word-wrap: break-word;
127+
}
128+
129+
pre {
130+
width: calc(100% - 20px - 3em);
131+
padding: 10px;
132+
background-color: #fafafa;
133+
color: #222;
134+
line-height: 1.2em;
135+
border: 1px solid #c9c9c9;
136+
margin: 1.5em 0;
137+
box-shadow: 1px 1px 1px #d8d8d8;
138+
}
139+
pre > code {
140+
font-size: 87.5%;
141+
font-family: monospace;
142+
color: #222;
143+
}
144+
145+
hr {
146+
width: 80%;
147+
margin: 20px auto;
148+
}
149+
150+
blockquote {
151+
color: rgb(90, 90, 90);
152+
padding: 0.1rem 1rem;
153+
border-left: 0.2rem solid #aaa;
154+
}
155+
156+
figure {
157+
text-align: center;
158+
}
159+
160+
figure > figcaption {
161+
color: rgb(90, 90, 90);
162+
font-size: 90%;
163+
}
164+
165+
figure > figcaption .caption-number {
166+
font-weight: 700;
167+
padding-right: 5px;
168+
}
169+
170+
.math .MathJax {
171+
outline: none;
172+
}
173+
div.math.numbered {
174+
width: calc(100% - 50px);
175+
margin: 0 auto;
176+
}
177+
div.math.numbered:before {
178+
content: '(' attr(number) ')';
179+
float: right;
180+
}
17181

18182
.markdown {
19183
p, ul, ol {
@@ -30,4 +194,4 @@
30194
.v-theme--dark & code {
31195
background-color: rgba(255, 255, 255, 0.1);
32196
}
33-
}
197+
}

tests/component/specs/info.cy.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ import { Tokens } from '@/utils/uid'
2121
const DESCRIPTION = `Lorem ipsum dolor sit amet, consectetur adipiscing elit.
2222
Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
2323
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi.
24+
25+
# New Section
26+
27+
H{sub}\`2\`O, and 5{sup}\`th\` of November.
28+
29+
\`\`\`{list-table} A Liszt Table
30+
:header-rows: 1
31+
32+
* - Piece
33+
- Year
34+
* - Hungarian Rhapsody No. 2
35+
- 1847
36+
* - La Campanella
37+
- 1851
38+
* - Liebestraum No. 3
39+
- 1850
2440
`
2541
const TOKENS = new Tokens('~user/workflow//1234/foo')
2642
const TASK = {
@@ -155,6 +171,21 @@ describe('Info component', () => {
155171
.get('.metadata-panel a:first') // the URL should be an anchor
156172
.should('have.attr', 'href', 'https://cylc.org')
157173
.contains(/^https:\/\/cylc.org$/)
174+
// Markdonw allows the adding of additional titles:
175+
.get('h1').eq(1)
176+
.contains('New Section')
177+
// Markdown subscripts and superscripts should be rendered:
178+
.get('sub')
179+
.contains('2')
180+
.get('sup')
181+
.contains('th')
182+
// Markdown tables should be rendered:
183+
.get('table')
184+
.should('be.visible')
185+
.get('table tr')
186+
.contains('Hungarian Rhapsody No. 2')
187+
.get('table th')
188+
.contains('Piece')
158189

159190
// the prerequisites panel
160191
cy.get('.prerequisites-panel.v-expansion-panel--active').should('be.visible')
@@ -278,5 +309,13 @@ describe('Info component', () => {
278309
panelExpansion: [0, 1, 2],
279310
}
280311
})
312+
313+
// the metadata panel contains default values where there is no data:
314+
cy.get('.metadata-panel.v-expansion-panel--active').should('be.visible')
315+
.contains('(Title)')
316+
.get('.metadata-panel')
317+
.contains('Description')
318+
.get('.metadata-panel')
319+
.contains('URL')
281320
})
282321
})

0 commit comments

Comments
 (0)