Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ NEW: Add tableExtension #12

Merged
merged 1 commit into from Apr 11, 2022
Merged

✨ NEW: Add tableExtension #12

merged 1 commit into from Apr 11, 2022

Conversation

chrisjsewell
Copy link
Member

@chrisjsewell chrisjsewell commented Apr 11, 2022

import { Processor } from '@unified-myst/core-parse'
import * as ext from '@unified-myst/core-parse/extensions'
import { removePosition } from 'unist-util-remove-position'
import { dump } from 'js-yaml'

const parser = new Processor()
    .use(ext.syntaxMystExtension)
    .use(ext.tableExtension)

let text = `
\`\`\`{table} This is a caption
:name: test
:class: a

| a | b |
| - | - |
| c | d |
\`\`\`
`

let ast = parser.toAst(text).ast
ast = removePosition(ast, true)

console.log(dump(ast))

Creates:

type: root
children:
  - type: mystDirective
    name: table
    args:
      - This is a caption
    options:
      name: test
      class:
        - a
    value: |-
      | a | b |
      | - | - |
      | c | d |
    bodyOffset: 4
    children:
      - type: container
        kind: table
        children:
          - type: caption
            children:
              - type: text
                value: This is a caption
          - type: table
            align:
              - null
              - null
            children:
              - type: tableRow
                children:
                  - type: tableCell
                    children:
                      - type: text
                        value: a
                  - type: tableCell
                    children:
                      - type: text
                        value: b
              - type: tableRow
                children:
                  - type: tableCell
                    children:
                      - type: text
                        value: c
                  - type: tableCell
                    children:
                      - type: text
                        value: d
        classes:
          - a
        label: test
        mystIds:
          - test

@chrisjsewell chrisjsewell merged commit 8395520 into main Apr 11, 2022
@chrisjsewell chrisjsewell deleted the table branch April 11, 2022 16:04
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.

None yet

1 participant