papyri icon indicating copy to clipboard operation
papyri copied to clipboard

Try to adopt Myst Spec where possible.

Open Carreau opened this issue 3 years ago • 5 comments

I've recently talks with a couple of the myst folks, and I'd like to see if we can adopt the myst AST, or at least something as close to it as possible.

See the structure of the Myst AST

The myst spec are published as json schema, I haven't found it as Python objects, so I've started to write a notebook to see if we can directly generate teh Python dataclasses to represent those nodes.

https://gist.github.com/Carreau/d5d80d644b4f43e601e67874619d855a

It a bit rough on the edges, and I'm ok if there is some manual edition.

Once this is done, the goal is to mostly replace the custom ast I have in here

Carreau avatar Nov 10 '22 09:11 Carreau

Once the above is roughly done, we can also replace the serializers I have with something more straightforward : https://gist.github.com/Carreau/62350dabcd75b90eccffb9fca7c2c431,

This would allow to emit json that can be rendered by the MyST Js libraries.

I don't expect us to have custom nodes and variations, but the closer we are to another spec the better. The Myst folks would I think also welcome feedback on their AST if we need any changes.

If we also find a library that already goes from json schema to pyhton-implementation i'm all for it, I just hadn't found any that support json schema $ref.

Carreau avatar Nov 10 '22 09:11 Carreau

Note, it look like we can render the Mdast directly using MystJS:

<html>
  <head>
    <script src="https://unpkg.com/mystjs"></script>
  </head>
  <body onload="init();">
    <div id="output"></div>
    <script>
      function init() {
        const myst = new MyST();
        const html = myst.renderMdast({type: "text", value:"Hello"})
        document.getElementById('output').innerHTML = html;
      }
    </script>
  </body>
</html>

Carreau avatar Jan 26 '23 13:01 Carreau

Are you aware of something equivalent of BlockVerbatim in the myst spec? The closest I have found is Code, but syntax of Code is different from BlockVerbatim, as in the three backticks.

Trying to replace BlockVerbatim for parsing this block in numpy docs: https://github.com/numpy/numpy/blob/b30653165c4a44b40be733217b26ac9a936772a5/numpy/distutils/init.py#L7-L11

UPDATE: Code and InlineCode seems to work fine for BlockVerbatim and Verbatim

aktech avatar Jan 31 '23 11:01 aktech

UPDATE: Code and InlineCode seems to work fine for BlockVerbatim and Verbatim

Perfect, That sounds good, and if it makes less nodes that's a plus !

Carreau avatar Feb 01 '23 08:02 Carreau

Status of Nodes to replace/remove:

Node Replaced Removed Comments
Verbatim
  • [ ]
  • [ ]
  • --
    Directive
  • [ ]
  • [ ]
  • --
    Link
  • [ ]
  • [ ]
  • --
    Math
  • [x]
  • [x]
  • --
    BlockMath
  • [x]
  • [x]
  • --
    SubstitutionDef
  • [ ]
  • [ ]
  • --
    SubstitutionRef
  • [ ]
  • [ ]
  • --
    Target
  • [ ]
  • [ ]
  • --
    Unimplemented
  • [ ]
  • [ ]
  • --
    Comment
  • [x]
  • [x]
  • --
    Fig
  • [ ]
  • [ ]
  • --
    RefInfo
  • [ ]
  • [ ]
  • --
    ListItem
  • [ ]
  • [ ]
  • --
    Signature
  • [ ]
  • [ ]
  • --
    NumpydocExample
  • [ ]
  • [ ]
  • --
    NumpydocSeeAlso
  • [ ]
  • [ ]
  • --
    NumpydocSignature
  • [ ]
  • [ ]
  • --
    Section
  • [ ]
  • [ ]
  • --
    Parameters
  • [ ]
  • [ ]
  • --
    Param
  • [ ]
  • [ ]
  • --
    Token
  • [ ]
  • [ ]
  • --
    Code3
  • [x]
  • [x]
  • --
    CodeLine
  • [ ]
  • [ ]
  • --
    Code2
  • [ ]
  • [ ]
  • --
    GenToken
  • [ ]
  • [ ]
  • --
    Code
  • [ ]
  • [ ]
  • --
    BlockQuote
  • [x]
  • [x]
  • --
    Transition
  • [ ]
  • [ ]
  • --
    Paragraph
  • [x]
  • [ ]
  • --
    Admonition
  • [ ]
  • [ ]
  • --
    TocTree
  • [ ]
  • [ ]
  • --
    BlockDirective
  • [ ]
  • [ ]
  • --
    BlockVerbatim
  • [ ]
  • [ ]
  • --
    Options
  • [ ]
  • [ ]
  • --
    FieldList
  • [ ]
  • [ ]
  • --
    FieldListItem
  • [ ]
  • [ ]
  • --
    DefList
  • [ ]
  • [ ]
  • --
    DefListItem
  • [ ]
  • [ ]
  • --
    SeeAlsoItem
  • [ ]
  • [ ]
  • --

    aktech avatar Mar 22 '23 13:03 aktech