Orga

Abstract Syntax Tree

Paragraph

Paragraph represents a consecutive lines of non-special lines.

Hello World.

Yields:

{
  "type": "paragraph",
  "children": [
    {
      "type": "text.plain",
      "value": "Hello World.",
      "position": {
        "start": {
          "line": 1,
          "column": 1
        },
        "end": {
          "line": 1,
          "column": 13
        }
      }
    }
  ],
  "position": {
    "start": {
      "line": 1,
      "column": 1
    },
    "end": {
      "line": 1,
      "column": 13
    }
  }
}

Section

Section starts with a headline, and it can be nested.

* Headline 1
And this is the content.
** Headline 1.1
*** Headline 1.1.1
* Headline 2

Yields:

{
  "type": "section",
  "level": 1,
  "properties": {},
  "children": [
    {
      "type": "headline",
      "actionable": false,
      "content": "Headline 1",
      "children": [
        {
          "type": "stars",
          "level": 1,
          "position": {
            "start": {
              "line": 1,
              "column": 1
            },
            "end": {
              "line": 1,
              "column": 2
            }
          }
        },
        {
          "type": "text.plain",
          "value": "Headline 1",
          "position": {
            "start": {
              "line": 1,
              "column": 3
            },
            "end": {
              "line": 1,
              "column": 13
            }
          }
        },
        {
          "type": "newline",
          "position": {
            "start": {
              "line": 1,
              "column": 13
            },
            "end": {
              "line": 2,
              "column": 1
            }
          }
        }
      ],
      "level": 1,
      "position": {
        "start": {
          "line": 1,
          "column": 1
        },
        "end": {
          "line": 2,
          "column": 1
        }
      }
    },
    {
      "type": "paragraph",
      "children": [
        {
          "type": "text.plain",
          "value": "And this is the content.",
          "position": {
            "start": {
              "line": 2,
              "column": 1
            },
            "end": {
              "line": 2,
              "column": 25
            }
          }
        },
        {
          "type": "text.plain",
          "value": " "
        }
      ],
      "position": {
        "start": {
          "line": 2,
          "column": 1
        },
        "end": {
          "line": 2,
          "column": 25
        }
      }
    },
    {
      "type": "section",
      "level": 2,
      "properties": {},
      "children": [
        {
          "type": "headline",
          "actionable": false,
          "content": "Headline 1.1",
          "children": [
            {
              "type": "stars",
              "level": 2,
              "position": {
                "start": {
                  "line": 3,
                  "column": 1
                },
                "end": {
                  "line": 3,
                  "column": 3
                }
              }
            },
            {
              "type": "text.plain",
              "value": "Headline 1.1",
              "position": {
                "start": {
                  "line": 3,
                  "column": 4
                },
                "end": {
                  "line": 3,
                  "column": 16
                }
              }
            },
            {
              "type": "newline",
              "position": {
                "start": {
                  "line": 3,
                  "column": 16
                },
                "end": {
                  "line": 4,
                  "column": 1
                }
              }
            }
          ],
          "level": 2,
          "position": {
            "start": {
              "line": 3,
              "column": 1
            },
            "end": {
              "line": 4,
              "column": 1
            }
          }
        },
        {
          "type": "section",
          "level": 3,
          "properties": {},
          "children": [
            {
              "type": "headline",
              "actionable": false,
              "content": "Headline 1.1.1",
              "children": [
                {
                  "type": "stars",
                  "level": 3,
                  "position": {
                    "start": {
                      "line": 4,
                      "column": 1
                    },
                    "end": {
                      "line": 4,
                      "column": 4
                    }
                  }
                },
                {
                  "type": "text.plain",
                  "value": "Headline 1.1.1",
                  "position": {
                    "start": {
                      "line": 4,
                      "column": 5
                    },
                    "end": {
                      "line": 4,
                      "column": 19
                    }
                  }
                },
                {
                  "type": "newline",
                  "position": {
                    "start": {
                      "line": 4,
                      "column": 19
                    },
                    "end": {
                      "line": 5,
                      "column": 1
                    }
                  }
                }
              ],
              "level": 3,
              "position": {
                "start": {
                  "line": 4,
                  "column": 1
                },
                "end": {
                  "line": 5,
                  "column": 1
                }
              }
            }
          ],
          "position": {
            "start": {
              "line": 4,
              "column": 1
            },
            "end": {
              "line": 5,
              "column": 1
            }
          }
        }
      ],
      "position": {
        "start": {
          "line": 3,
          "column": 1
        },
        "end": {
          "line": 5,
          "column": 1
        }
      }
    }
  ],
  "position": {
    "start": {
      "line": 1,
      "column": 1
    },
    "end": {
      "line": 5,
      "column": 1
    }
  }
}

Headline

Headline can have keyword, priority, tags, planning, drawers.

* TODO [#A] Hello World   :tag1:tag2:
DEADLINE: <2018-01-01 Mon>
:PROPERTY:
key0: value0
key1: value1
:END:

Yields:

{
  "type": "section",
  "level": 1,
  "properties": {},
  "children": [
    {
      "type": "headline",
      "actionable": true,
      "content": "[#A]Hello World",
      "children": [
        {
          "type": "stars",
          "level": 1,
          "position": {
            "start": {
              "line": 1,
              "column": 1
            },
            "end": {
              "line": 1,
              "column": 2
            }
          }
        },
        {
          "type": "todo",
          "keyword": "TODO",
          "actionable": true,
          "position": {
            "start": {
              "line": 1,
              "column": 3
            },
            "end": {
              "line": 1,
              "column": 7
            }
          }
        },
        {
          "type": "priority",
          "value": "[#A]",
          "position": {
            "start": {
              "line": 1,
              "column": 8
            },
            "end": {
              "line": 1,
              "column": 12
            }
          }
        },
        {
          "type": "text.plain",
          "value": "Hello World",
          "position": {
            "start": {
              "line": 1,
              "column": 13
            },
            "end": {
              "line": 1,
              "column": 24
            }
          }
        },
        {
          "type": "tags",
          "tags": [
            "tag1",
            "tag2"
          ],
          "position": {
            "start": {
              "line": 1,
              "column": 27
            },
            "end": {
              "line": 1,
              "column": 38
            }
          }
        },
        {
          "type": "newline",
          "position": {
            "start": {
              "line": 1,
              "column": 38
            },
            "end": {
              "line": 2,
              "column": 1
            }
          }
        }
      ],
      "level": 1,
      "position": {
        "start": {
          "line": 1,
          "column": 1
        },
        "end": {
          "line": 2,
          "column": 1
        }
      },
      "keyword": "TODO",
      "tags": [
        "tag1",
        "tag2"
      ]
    },
    {
      "type": "planning",
      "keyword": "DEADLINE",
      "timestamp": {
        "date": "2017-12-31T11:00:00.000Z"
      },
      "position": {
        "start": {
          "line": 2,
          "column": 1
        },
        "end": {
          "line": 2,
          "column": 27
        }
      }
    },
    {
      "type": "drawer",
      "name": "PROPERTY",
      "position": {
        "start": {
          "line": 3,
          "column": 1
        },
        "end": {
          "line": 6,
          "column": 6
        }
      },
      "value": "key0: value0\nkey1: value1"
    }
  ],
  "position": {
    "start": {
      "line": 1,
      "column": 1
    },
    "end": {
      "line": 6,
      "column": 6
    }
  }
}

Blocks

#+BEGIN_SRC javascript
const parser = new Parser()
const ast = parser.parse(`Hello World`)
#+END_SRC

Yields:

{
  "type": "block",
  "name": "SRC",
  "params": [
    "javascript"
  ],
  "position": {
    "start": {
      "line": 1,
      "column": 1
    },
    "end": {
      "line": 4,
      "column": 11
    }
  },
  "value": "const parser = new Parser()\nconst ast = parser.parse(`Hello World`)"
}

List and List Item

- [x] build an awesome org-mode parser
- [ ] let people use it everywhere
- orga :: the ultimate org-mode parser

Yields:

{
  "type": "list",
  "indent": 0,
  "ordered": false,
  "children": [
    {
      "type": "list.item",
      "indent": 0,
      "children": [
        {
          "type": "list.item.bullet",
          "indent": 0,
          "ordered": false,
          "position": {
            "start": {
              "line": 1,
              "column": 1
            },
            "end": {
              "line": 1,
              "column": 2
            }
          }
        },
        {
          "type": "list.item.checkbox",
          "checked": true,
          "position": {
            "start": {
              "line": 1,
              "column": 3
            },
            "end": {
              "line": 1,
              "column": 6
            }
          }
        },
        {
          "type": "text.plain",
          "value": "build an awesome org-mode parser",
          "position": {
            "start": {
              "line": 1,
              "column": 7
            },
            "end": {
              "line": 1,
              "column": 39
            }
          }
        }
      ],
      "position": {
        "start": {
          "line": 1,
          "column": 1
        },
        "end": {
          "line": 1,
          "column": 39
        }
      }
    },
    {
      "type": "list.item",
      "indent": 0,
      "children": [
        {
          "type": "list.item.bullet",
          "indent": 0,
          "ordered": false,
          "position": {
            "start": {
              "line": 2,
              "column": 1
            },
            "end": {
              "line": 2,
              "column": 2
            }
          }
        },
        {
          "type": "list.item.checkbox",
          "checked": false,
          "position": {
            "start": {
              "line": 2,
              "column": 3
            },
            "end": {
              "line": 2,
              "column": 6
            }
          }
        },
        {
          "type": "text.plain",
          "value": "let people use it everywhere",
          "position": {
            "start": {
              "line": 2,
              "column": 7
            },
            "end": {
              "line": 2,
              "column": 35
            }
          }
        }
      ],
      "position": {
        "start": {
          "line": 2,
          "column": 1
        },
        "end": {
          "line": 2,
          "column": 35
        }
      }
    },
    {
      "type": "list.item",
      "indent": 0,
      "children": [
        {
          "type": "list.item.bullet",
          "indent": 0,
          "ordered": false,
          "position": {
            "start": {
              "line": 3,
              "column": 1
            },
            "end": {
              "line": 3,
              "column": 2
            }
          }
        },
        {
          "type": "text.plain",
          "value": "the ultimate org-mode parser\n",
          "position": {
            "start": {
              "line": 3,
              "column": 11
            },
            "end": {
              "line": 3,
              "column": 40
            }
          }
        }
      ],
      "position": {
        "start": {
          "line": 3,
          "column": 1
        },
        "end": {
          "line": 3,
          "column": 40
        }
      },
      "tag": "orga"
    }
  ],
  "position": {
    "start": {
      "line": 1,
      "column": 1
    },
    "end": {
      "line": 3,
      "column": 40
    }
  }
}

Table, Table Row and Table Cell

| foo | bar |
|-----|-----|
| baz | qux |

Yields:

{
  "type": "table",
  "children": [
    {
      "type": "table.row",
      "children": [
        {
          "type": "table.cell",
          "children": [
            {
              "type": "text.plain",
              "value": " foo ",
              "position": {
                "start": {
                  "line": 1,
                  "column": 2
                },
                "end": {
                  "line": 1,
                  "column": 7
                }
              }
            }
          ],
          "position": {
            "start": {
              "line": 1,
              "column": 2
            },
            "end": {
              "line": 1,
              "column": 7
            }
          }
        },
        {
          "type": "table.cell",
          "children": [
            {
              "type": "text.plain",
              "value": " bar ",
              "position": {
                "start": {
                  "line": 1,
                  "column": 8
                },
                "end": {
                  "line": 1,
                  "column": 13
                }
              }
            }
          ],
          "position": {
            "start": {
              "line": 1,
              "column": 8
            },
            "end": {
              "line": 1,
              "column": 13
            }
          }
        }
      ],
      "position": {
        "start": {
          "line": 1,
          "column": 2
        },
        "end": {
          "line": 1,
          "column": 13
        }
      }
    },
    {
      "type": "table.hr",
      "position": {
        "start": {
          "line": 2,
          "column": 1
        },
        "end": {
          "line": 2,
          "column": 14
        }
      }
    },
    {
      "type": "table.row",
      "children": [
        {
          "type": "table.cell",
          "children": [
            {
              "type": "text.plain",
              "value": " baz ",
              "position": {
                "start": {
                  "line": 3,
                  "column": 2
                },
                "end": {
                  "line": 3,
                  "column": 7
                }
              }
            }
          ],
          "position": {
            "start": {
              "line": 3,
              "column": 2
            },
            "end": {
              "line": 3,
              "column": 7
            }
          }
        },
        {
          "type": "table.cell",
          "children": [
            {
              "type": "text.plain",
              "value": " qux ",
              "position": {
                "start": {
                  "line": 3,
                  "column": 8
                },
                "end": {
                  "line": 3,
                  "column": 13
                }
              }
            }
          ],
          "position": {
            "start": {
              "line": 3,
              "column": 8
            },
            "end": {
              "line": 3,
              "column": 13
            }
          }
        },
        {
          "type": "table.cell",
          "children": [
            {
              "type": "text.plain",
              "value": "\n",
              "position": {
                "start": {
                  "line": 3,
                  "column": 14
                },
                "end": {
                  "line": 3,
                  "column": 15
                }
              }
            }
          ],
          "position": {
            "start": {
              "line": 3,
              "column": 14
            },
            "end": {
              "line": 3,
              "column": 15
            }
          }
        }
      ],
      "position": {
        "start": {
          "line": 3,
          "column": 2
        },
        "end": {
          "line": 3,
          "column": 15
        }
      }
    }
  ],
  "position": {
    "start": {
      "line": 1,
      "column": 2
    },
    "end": {
      "line": 3,
      "column": 15
    }
  }
}

Horizontal Rule

-----

Yields:

{
  "type": "hr",
  "position": {
    "start": {
      "line": 1,
      "column": 1
    },
    "end": {
      "line": 1,
      "column": 6
    }
  }
}

Inline Markup

_Orga_ is +probably+ the *best* /org-mode/ ~parser~ =alive=.

Yields:

{
  "type": "paragraph",
  "children": [
    {
      "type": "text.underline",
      "value": "Orga",
      "position": {
        "start": {
          "line": 1,
          "column": 1
        },
        "end": {
          "line": 1,
          "column": 7
        }
      }
    },
    {
      "type": "text.plain",
      "value": " is ",
      "position": {
        "start": {
          "line": 1,
          "column": 7
        },
        "end": {
          "line": 1,
          "column": 11
        }
      }
    },
    {
      "type": "text.strikeThrough",
      "value": "probably",
      "position": {
        "start": {
          "line": 1,
          "column": 11
        },
        "end": {
          "line": 1,
          "column": 21
        }
      }
    },
    {
      "type": "text.plain",
      "value": " the ",
      "position": {
        "start": {
          "line": 1,
          "column": 21
        },
        "end": {
          "line": 1,
          "column": 26
        }
      }
    },
    {
      "type": "text.bold",
      "value": "best",
      "position": {
        "start": {
          "line": 1,
          "column": 26
        },
        "end": {
          "line": 1,
          "column": 32
        }
      }
    },
    {
      "type": "text.plain",
      "value": " ",
      "position": {
        "start": {
          "line": 1,
          "column": 32
        },
        "end": {
          "line": 1,
          "column": 33
        }
      }
    },
    {
      "type": "text.italic",
      "value": "org-mode",
      "position": {
        "start": {
          "line": 1,
          "column": 33
        },
        "end": {
          "line": 1,
          "column": 43
        }
      }
    },
    {
      "type": "text.plain",
      "value": " ",
      "position": {
        "start": {
          "line": 1,
          "column": 43
        },
        "end": {
          "line": 1,
          "column": 44
        }
      }
    },
    {
      "type": "text.code",
      "value": "parser",
      "position": {
        "start": {
          "line": 1,
          "column": 44
        },
        "end": {
          "line": 1,
          "column": 52
        }
      }
    },
    {
      "type": "text.plain",
      "value": " ",
      "position": {
        "start": {
          "line": 1,
          "column": 52
        },
        "end": {
          "line": 1,
          "column": 53
        }
      }
    },
    {
      "type": "text.verbatim",
      "value": "alive",
      "position": {
        "start": {
          "line": 1,
          "column": 53
        },
        "end": {
          "line": 1,
          "column": 60
        }
      }
    },
    {
      "type": "text.plain",
      "value": ".",
      "position": {
        "start": {
          "line": 1,
          "column": 60
        },
        "end": {
          "line": 1,
          "column": 61
        }
      }
    }
  ],
  "position": {
    "start": {
      "line": 1,
      "column": 1
    },
    "end": {
      "line": 1,
      "column": 61
    }
  }
}

Link

Find the Source [[https://github.com/xiaoxinghu/orgajs][Here]]

Yields:

{
  "type": "paragraph",
  "children": [
    {
      "type": "text.plain",
      "value": "Find the Source ",
      "position": {
        "start": {
          "line": 1,
          "column": 1
        },
        "end": {
          "line": 1,
          "column": 17
        }
      }
    },
    {
      "type": "link",
      "description": "Here",
      "protocol": "https",
      "value": "https://github.com/xiaoxinghu/orgajs",
      "position": {
        "start": {
          "line": 1,
          "column": 17
        },
        "end": {
          "line": 1,
          "column": 63
        }
      }
    }
  ],
  "position": {
    "start": {
      "line": 1,
      "column": 1
    },
    "end": {
      "line": 1,
      "column": 63
    }
  }
}

Export

#+HTML: <p>Hello World.</p>

Yields:

{
  "type": "html",
  "value": "<p>Hello World.</p>"
}

Export Block

#+BEGIN_EXPORT html
<div>
    <p>Hello World.</p>
</div>
#+END_EXPORT

Yields:

{
  "type": "block",
  "name": "EXPORT",
  "params": [
    "html"
  ],
  "position": {
    "start": {
      "line": 1,
      "column": 1
    },
    "end": {
      "line": 5,
      "column": 14
    }
  },
  "value": "<div>\n    <p>Hello World.</p>\n</div>"
}