Skip to content

Conversation

wxtim
Copy link
Member

@wxtim wxtim commented Mar 31, 2025

Also replaces markdown-it with the more powerful package MyST.

After offline discussion @oliver-sanders and I decided to try MyST because

  • It has both Python and JS interfaces, so we can allow users to both build docs with Sphinx and display them in the GUI.
  • It is a superset of markdown, so at a basic level users can use MD.
  • It has many of the features of RST available, so more sophisticated documents can be written.

Branch-specific checks

  • Mutation.Vue
  • FormGenerator.Vue
  • Input.Vue
  • MyST security escaping documentation read.

Security

I can't find a vast amount of info:

The default for CommonMark standard is to pass everything through (or at least that's what CommonMark.js does)

But this doesn't seem to be implemented by MyST.js, whose own rather limited docs suggest that only <sub>, <super> and <abbr> will do anything. Testing this out seems to suggest that these aren't parsed correctly!

> myst.render('<p>Hi</p>')
''
> myst.render('<sub>Hi</sub>')
'<p>Hi</p>'
> myst.render('<style>.foo {color: #f00}</style>')
''
> myst.render('<script>console.log("copy rm -fr /* and run it in your terminal")</script>')
''
> myst.render('<center>Hi</center>')
''
> myst.render('<p>Hi</p>')
''

Check List

  • I have read CONTRIBUTING.md and added my name as a Code Contributor.
  • Contains logically grouped changes (else tidy your branch by rebase).
  • Does not contain off-topic changes (use other PRs for other changes).
  • Applied any dependency changes to both setup.cfg (and conda-environment.yml if present).
  • Tests are included (or explain why tests are not needed).
  • Changelog entry included if this is a change that can affect users
  • Cylc-Doc pull request opened if required at cylc/cylc-doc/pull/XXXX.
  • If this is a bug fix, PR should be raised against the relevant ?.?.x branch.

@wxtim wxtim marked this pull request as draft March 31, 2025 10:41
@wxtim wxtim self-assigned this Mar 31, 2025
@wxtim
Copy link
Member Author

wxtim commented Apr 24, 2025

@oliver-sanders - I'm a little concerned that MySTjs is quite primitive atm - See the list of features not available in mystjs at https://www.npmjs.com/package/mystjs#mystjs-features.

I'm also concerned that we may need to supply our own CSS to make it render well:

Shows that the admonition isn't obvious

The code isn't well rendered, and the admonition and the maths aren't rendered at all. Inspection suggests that they have the correct classes for styling, but that there isn't any inline: Inserting some CSS into the markdown made the tip box look like a tip box, but I'm not sure that we should be responsible for that.

Colour in the tip box horribly. If you need a text reader not seeing my choice of colours is a bonus

@oliver-sanders
Copy link
Member

oliver-sanders commented Apr 24, 2025

@oliver-sanders - I'm a little concerned that MySTjs is quite primitive atm

Quoting from the link, these are the missing features:

Not yet complete:

div
proof
margin
sidebar
colon fence
Citations
Bibliography
Epigraph
Glosary
Terms
Tabs
Panels
CSV Tables
Multi-document

These are all either HTML features or ReStructuredText features.

MySt would appear to be feature complete for the common-mark specification.

So I think this is pretty good.


I'm also concerned that we may need to supply our own CSS to make it render well:

Their examples render very nicely, see the sandbox - https://mystmd.org/sandbox

From a quick search of the repo I found this CSS. You may need to link it into your HTML if using the JS library standalone:

https://github.com/jupyter-book/mystmd/blob/68c93b9a07014e01eac4d721dfd3b5f74d174258/packages/myst-parser/myst.css

@wxtim wxtim marked this pull request as ready for review April 24, 2025 10:09
@oliver-sanders
Copy link
Member

@wxtim, have you pulled through the MyST CSS in this PR?

@wxtim wxtim marked this pull request as draft April 28, 2025 10:50
@wxtim
Copy link
Member Author

wxtim commented Apr 28, 2025

@wxtim, have you pulled through the MyST CSS in this PR?

Not yet - drafting until I've worked it out.

@oliver-sanders
Copy link
Member

(unsubscribing)

@wxtim
Copy link
Member Author

wxtim commented Apr 29, 2025

Manual Test, showing what is possible:

The Workflow Definition
[scheduling]
    cycling mode = integer
    [[graph]]
        R1 = foo

[runtime]
    [[foo]]
        script = while true; do sleep 30; done
        [[[meta]]]
            title = "My Title"
            description = """
                # Every Single

                some text

                ## Heading

                some text

                ### Level

                some text

                #### Possible

                some text

                ##### No

                some text

                ###### Rêally

                > A moose bit my sister once.

                ---

                ## New section

                % This is a comment.

                [Great Auk - link example](https://en.wikipedia.org/wiki/Great_Auk)

                ![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)

                ## Lists

                1. First item
                2. Second item
                  * Yellow Submarine

                ## Admonitions

                :::{note}
                B flat
                :::

                :::{warning}
                Live without warning.
                :::

                :::{tip}
                My hobby room
                :::

                :::{danger}
                Mouse
                :::

                :::{caution}
                Horses
                :::

                :::{admonition} My Admonition
                :class: customadmonition
                This is a custom admonition.
                :::


                ## Maths

                This math is a role, {math}`e=mc^2`, while this math is wrapped in dollar signs, $Ax=b$.


                ## Table

                :::{list-table}
                :header-rows: 1
                * - Header 1
                  - Header 2
                  - Header 3
                * - Row 1
                  - Row 1
                  - Row 1
                * - Row 2
                  - Row 2
                  - Row 2

"""
Another Metadata Section = """
            :::{note}
            This is a note admonition.
            :::

            """

How about some code blocks = """

            :::{code-block} python

            # Python
            def foo():
                return "bar"
            :::

            :::{code-block} bash
            #!/bin/bash
            # Bash
            echo "Hello, World!"
            :::

"""
The Output

image

Note

I've note made this an explicit test in the test battery because that woudl be testing the dependency.

@wxtim wxtim marked this pull request as ready for review April 29, 2025 12:23
@wxtim
Copy link
Member Author

wxtim commented Apr 29, 2025

@oliver-sanders : Ready for review

@oliver-sanders oliver-sanders added this to the 2.8.0 milestone May 6, 2025
@wxtim wxtim requested review from oliver-sanders and MetRonnie May 7, 2025 09:43
Copy link
Member

@MetRonnie MetRonnie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add some example markdown that makes use of this to src\services\mock\json\infoView.json

@wxtim wxtim requested a review from MetRonnie May 13, 2025 13:11
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the myst-theme package provides CSS: https://github.com/jupyter-book/myst-theme/tree/main/styles

Can we just import this from there? We can always apply additional modifications if needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that will work - a quick look at that library suggests that it doesn't really contain things like .admonition which are required.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yet they seem to have good support for admonitions on their website?

https://jupyter-book.github.io/myst-theme/?path=/docs/components-admonitions--docs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jupyter-book is using myst-to-react, which looks like it's different output to myst-to-html. I can see if I can do that, but it sounds a bit wierd.

Copy link
Member Author

@wxtim wxtim May 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spent quite a while trying to address this as well as trying to get the maths parsing working - these threads seemed to hint at solutions, but I was unable to- get them working:

There was a suggestion that css could be included like this:

  .use(rehypeDocument, {
    css: ['myst.css', 'https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css'],
    js: ["https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js", "https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js"],
    script: `document.addEventListener("DOMContentLoaded", (event) => {
        renderMathInElement(document.body, {
            delimiters: [{
                    left: "$$",
                    right: "$$",
                    display: true
                },
                {
                    left: "$",
                    right: "$",
                    display: false
                }
            ]
        });
    });`
  })

But I haven't been able to make that work either.

@wxtim wxtim marked this pull request as draft May 15, 2025 09:36
@wxtim wxtim force-pushed the try_md branch 2 times, most recently from 5d2cfb5 to ccf59de Compare May 20, 2025 13:57
@wxtim wxtim requested a review from oliver-sanders May 21, 2025 14:14
@wxtim wxtim marked this pull request as ready for review May 22, 2025 10:09
@MetRonnie
Copy link
Member

(Needs deconflicting, and this:)

Could you add some example markdown that makes use of this to src\services\mock\json\infoView.json

Comment on lines 19 to 32
p, ul, ol {
&:not(:last-child) {
margin-bottom: 0.8em;
}
}
ul, ol {
padding-left: 24px;
}
.v-theme--light & code {
background-color: rgba(0, 0, 0, 0.05);
}
.v-theme--dark & code {
background-color: rgba(255, 255, 255, 0.1);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could look at more carefully incorporating the old styling into the new, as it was chosen to ensure the limited Markdown we already had fits with Vuetify

@wxtim wxtim marked this pull request as draft May 28, 2025 14:14
@oliver-sanders oliver-sanders modified the milestones: 2.8.0, 2.9.0 Jun 18, 2025
@MetRonnie MetRonnie modified the milestones: 2.9.0, 2.x Sep 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants