Giter Site home page Giter Site logo

org-mode-parser's Introduction

README.org

A Nodejs org mode parser module

“So What?”

This node.js module implements an org-mode file format parser. Org-mode is a cool Emacs package that lets you structure information in a nice way, and export it in html, latex, pdf and so on.

What does org-mode-parser do that I couldn’t do before?

I was unable to find a JavaScript parser for org-mode. Now we have one. Org-mode is so useful you will start writing in org-mode instead of text files for everything needing a bit of structuring.

It is also XML-free and yes, we like it :)

What are further benefits?

A lot of unit testing (over 100) and a pretty fast parser (see below). Also, it has minimal requirements.

Where can I find more news?

Take a look at http://gioorgi.com/tag/org-mode-parser/ for latest news

Installation

The full installation can be obtained via the npm package repository. On a shell which can run node, try out these lines:

curl http://nodejs.org/dist/v0.10.28/node-v0.10.28.tar.gz | tar xzvf -
(cd node-v0.10.28/ ;  ./configure --prefix=$HOME ; make && make install)
curl --insecure https://www.npmjs.org/install.sh  | bash
npm install org-mode-parser

or launch fast-install.sh

Usage example:

var org=require('../lib/org-mode-parser');
org.makelist("README.org", function (nodelist){
   // Here nodelist is a list of Orgnode objects (ref:putyourcode)
   console.dir(nodelist[0]);
});

API

The parser’s main entry point is the makelist function, which accepts a filename and a callback function. makelist() will pass to the function the list of parsed nodes as first parameter, as described in the opening example.

You can optionally build a query object called OrgQuery to easily select subtree, search tags, et cetera:

var org=require('../lib/org-mode-parser');
org.makelist("./test/treeLevel.org",function(nodes){
    var ofd=new org.OrgQuery(nodes);
    // ofd is a complex object for use in querying and so on
    console.log(ofd.selectTag('complex').first().toOrgString());
});

Supported methods of OrgQuery are:

  • selectSubtree(node) Extract the nodes hierarchically below the given input
  • selectTag(tagString)
  • sortBy
  • reject(function)
  • rejectTag(tagName)
  • toArray()
  • each(functionToPassEach)
  • random() Extract a random element
  • toHtml(options) Generate a fair html rendering. It also support pug (jade) template system. This code is not meant to replace org-mode export functionality, but can be an handy friend. For usage example see test/to-html-test.js

See the unit test section ‘basicLibraries OrgQuery-Complex’ on test/parseTest.js for more usage examples, and do not miss the FAQ

Known Limitations

The input must be a well-formed org-mode file. Parser can detect some corruptions, but it does not provide a complete sanity check.

Every text must have a header. Parser does not support “no-headed” inputs. Anyway, empty headers are supported (see github Issue #11)

Design Goals

API Stability

In general, every API component described in the API section is here to stay. Compatibility will be retained as far as possible in future releases.

Performance

At the time of writing, the parser is pretty fast. On a Linux virtual machine, we get about 20.000 nodes per seconds. We will keep an eye on performance.

You are welcome to help us stress test the parser and find its true limits.

Minimize dependency

Org-mode-parser depends only on two packages, underscore and vows. Vows dependency is used only for regression tests, so the parser really depends only on underscore.

Tests are documentation

Take a look at the examples/ directory for some tiny examples. Please look at test/parserTest.js file for API usage examples. Tests are commented and pretty self-explanatory: they are the primary source for correctness of this module.

FAQ

Where can I find stable packages?

On npm repository. The master branch on GitHub is the development version, so use it at your own risk.

Who is my best friend?

OrgQuery is a very handy object (see below), because it allows you to filter nodes in a structured way. Use it instead of hand-parsing.

How can I get rid of archived nodes?

Use the OrgQuery.rejectArchived() method

Are undeclared drawers parsed?

Yes, but org mode wants them to be declared (see par 2.9 Drawers on documentation). Thus, it is best to not rely on undeclared drawers, because the parser could change in the future to be more stringent. Also, undeclared drawers are not indented!

Querying Questions

How can I find all the subnodes of the node tagged releaseNotes and query it?

var org=require('../lib/org-mode-parser');
org.makelist("./README.org",function(nl){
    var q=new org.OrgQuery(nl);
    var subtree=q.selectSubtree(q.selectTag('releaseNotes').first());
    console.log("Dev version is:"+subtree.selectTag('dev').first().headline);
});

Do you support SETUPFILE and INCLUDE?

No, at least not at the moment.

Github

https://github.com/daitangio/org-mode-parser

Development HOWTO

Globally install vows and try out something like:

npm install -g [email protected]
NODE_PATH=$(dirname $(which node))/../lib/node_modules:. ./bin/testme

Release command sequence / Kitchensink

At the time of writing, the github repository is the master code repository

  1. Check the package.json version
  2. Issue the following commands:
./bin/releaseVersion.sh ORG_MODE_PARSER_0.0.6

Known bugs in progress

Fixing a known bug on vows which is creating false positive on tests vowsjs/vows#187

“vows”:”>=0.5.11” worked, then an incompatibile change was made on vows

Fixes #11 nodelist does not include headers with no text

org-mode-parser's People

Contributors

aviav avatar ben-miller avatar daitangio avatar ddlsmurf avatar gravitywp avatar jinwoo avatar kevzettler avatar mdlavin avatar thesebas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

org-mode-parser's Issues

Error: ParseError: DRAWER :50: Found but :END: missed

I'm trying to parse a very simple org-file:

* Python
** time
#+BEGIN_SRC python
from time import strftime
strftime("%Y-%m-%d %H:%M:%S")
=> '2014-06-06 13:50:52'
#+END_SRC

With this:

var org = require('org-mode-parser');
org.makelist("python-notes.org", function (nodelist){
    // Here nodelist is a list of Orgnode objects (ref:putyourcode)
    console.dir(nodelist[0]);
});

but it says:

/home/kuanyui/Dropbox/Blog/hexo-renderer-org/node_modules/org-mode-parser/lib/org-mode-parser.js:504
            throw x;
                  ^
Error: ParseError:  DRAWER :50: Found but :END: missed
    at ParseError (/home/kuanyui/Dropbox/Blog/hexo-renderer-org/node_modules/org-mode-parser/lib/org-mode-parser.js:85:12)
    at parseBigString (/home/kuanyui/Dropbox/Blog/hexo-renderer-org/node_modules/org-mode-parser/lib/org-mode-parser.js:431:12)
    at makelistFromStringWithPerformance (/home/kuanyui/Dropbox/Blog/hexo-renderer-org/node_modules/org-mode-parser/lib/org-mode-parser.js:501:19)
    at /home/kuanyui/Dropbox/Blog/hexo-renderer-org/node_modules/org-mode-parser/lib/org-mode-parser.js:533:2
    at fs.js:271:14
    at Object.oncomplete (fs.js:107:15)

org-mode parser npm license to MIT or BSD?

Hello daitangio,

Firstly thank you for the superb library. I wanted to use for my own org-mode files within my company, but unfortunately the policy does not allow us to request software with GPL licenses from Node.

Would it be possible to switch the npm version to another acceptable license (e.g. FreeBSD, MIT) so that I am able to use at work? (We import packages directly from npm, so the license would need to be changed there if this is possible)

Many thanks!

nodelist does not include headers with no text

Hi! love this package

in the following org file

* Test
hello
*
sup
* wow
cool

I see the nodelist

[ Orgnode {
    key: 'orgNode_1.*',
    level: 1,
    headline: 'Test',
    body: 'hello\n',
    tag: null,
    tags: {},
    todo: null,
    priority: null,
    scheduled: null,
    deadline: null,
    properties: {},
    drawer: {} },
  Orgnode {
    key: 'orgNode_2.*',
    level: 1,
    headline: 'wow',
    body: 'cool\n\n',
    tag: null,
    tags: {},
    todo: null,
    priority: null,
    scheduled: null,
    deadline: null,
    properties: {},
    drawer: {} } ]

The middle node, with no headline, seems to be omitted. Is this intentional?

thank you!

Colon in the headline mistakenly treated as tag

Hi there!

Thanks a lot for this! This is the best parser I've found so far, for org-mode. Some are too simplistic and others try to do too much and are too complex to be practical out-of-the-box (like orga). org-mode-parser has a great balance of features while being simple and practical to use! Perfect for my use case where I don't really need an AST but a way to make sense of and find org items :) Keep it up!

I've found a small problem, if the headline has a : in it, it will confuse the parser and it will think the headline is actually a tag. Example:

****** Feature: create and register new wordpress-powered (source) jekyll blog :toblog:
       yaya, cool
       markdown here

For this item, org-mode-parser thinks Feature: ... is a tag, besides :toblog:. If I remove the : in Feature, then it correctly detects it as a headline, and :toblog: as the sole tag.

Idea for collaboration

Hello, I found your project from the worg tools list. First, sorry for the semi-spam nature of this issue. I had a notion for a project that the org community might find useful and I'm looking for feedback. Feel free to close this issue if it doesn't sound useful to you.

My idea is to start a list of org-mode snippets which can serve as a test bed for people developing tools. The idea is that having a separate collection of repositories makes it easier for others in the community to benefit from the examples developed through communication with users.

Users could use these samples to try to construct minimal examples of issues they're having and/or contribute examples there which others could benefit from. Exactly how it will take shape is still up in the air.

These samples could also serve as a place to discuss ideas about how to develop the grammar itself. According to worg, the spec is still in draft state.

There's not much there at the moment. Mostly because I don't want to commit too early to what seems like it might be useful. I'll add more examples as I go.

If you like the concept and/or want to contribute and/or just want to offer feedback, I'd very much appreciate it.

Again, sorry for the spam.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.