Skip to content
/ afm Public

Command-line tool to render Astro Flavored Markdown documents to JSON abstract syntax trees or HTML

License

Notifications You must be signed in to change notification settings

nasa-gcn/afm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

a13eeaa · Sep 16, 2024
Sep 3, 2024
Jul 18, 2024
Sep 13, 2023
May 14, 2024
Sep 13, 2023
Sep 11, 2023
May 14, 2024
Jan 12, 2023
Sep 16, 2024
Jul 29, 2024
May 14, 2024

Repository files navigation

NPM Version

Astro Flavored Markdown

This is a command-line tool to render Astro Flavored Markdown documents to JSON abstract syntax trees or HTML. Astro Flavored Markdown is a dialect of Markdown for rapid astronomy communications. Astro Flavored Markdown detects and enriches dates, times, sky coordinates, and bibliographic references in text.

This command-line interface is a thin wrapper around remark-rehype-astro, the reference implementation of Astro Flavored Markdown as a plugin for the Unified parser ecosystem.

Usage

Usage: afm [options] [input]

Render Astro Flavored Markdown as a JSON syntax tree or as HTML

Arguments:
  input                  input file [default: stdin]

Options:
  --html                 output is in HTML [default: output is in JSON]
  -o, --output <output>  output file [default: stdout]
  -h, --help             display help for command

Example

Place the following text into a file called example.md:

# Example

Here is a table:

| Transient | Classification |
| --------- | -------------- |
| AT2017gfo | kilonova       |

To render as a JSON syntax tree:

$ npx @nasa-gcn/afm example.md
{
  "type": "root",
  "children": [
    {
      "type": "heading",
      "depth": 1,
      "children": [
        {
          "type": "text",
          "value": "Example"
        }
      ]
    },
    {
      "type": "paragraph",
      "children": [
        {
          "type": "text",
          "value": "Here is a table:"
        }
      ]
    },
    {
      "type": "table",
      "align": [
        null,
        null
      ],
      "children": [
        {
          "type": "tableRow",
          "children": [
            {
              "type": "tableCell",
              "children": [
                {
                  "type": "text",
                  "value": "Transient"
                }
              ]
            },
            {
              "type": "tableCell",
              "children": [
                {
                  "type": "text",
                  "value": "Classification"
                }
              ]
            }
          ]
        },
        {
          "type": "tableRow",
          "children": [
            {
              "type": "tableCell",
              "children": [
                {
                  "type": "text",
                  "value": "AT2017gfo",
                  "data": {
                    "class": "tns",
                    "value": "2017gfo"
                  }
                }
              ]
            },
            {
              "type": "tableCell",
              "children": [
                {
                  "type": "text",
                  "value": "kilonova"
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

To render as HTML:

$ npx @nasa-gcn/afm --html example.md

<h1>Example</h1>
<p>Here is a table:</p>
<table>
  <thead>
    <tr>
      <th>Transient</th>
      <th>Classification</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><data class="tns" value="2017gfo">AT2017gfo</data></td>
      <td>kilonova</td>
    </tr>
  </tbody>
</table>