├── .gitignore ├── .gitmodules ├── .npmignore ├── History.md ├── Readme.md ├── examples ├── example.md ├── flags.js └── run.js ├── package.json ├── src └── markdown.cc └── wscript /.gitignore: -------------------------------------------------------------------------------- 1 | src/*.o 2 | build 3 | .lock-wscript -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "deps/discount"] 2 | path = deps/discount 3 | url = git://github.com/Orc/discount.git 4 | [submodule "discount"] 5 | path = discount 6 | url = https://github.com/Orc/discount.git 7 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | build -------------------------------------------------------------------------------- /History.md: -------------------------------------------------------------------------------- 1 | 2 | 0.2.3 / 2012-01-09 3 | ================== 4 | 5 | * Added compatibility with node 0.6.x. 6 | 7 | 0.2.2 / 2011-09-13 8 | ================== 9 | 10 | * Fixed: compile discount with -fPIC [visnup] 11 | 12 | 0.2.1 / 2011-09-13 13 | ================== 14 | 15 | * Changed: submodule discount and statically link to it [visnup] 16 | 17 | 0.2.0 / 2011-07-27 18 | ================== 19 | 20 | * Added support for flags [afriggeri] 21 | 22 | 0.1.3 / 2011-04-15 23 | ================== 24 | 25 | * Add -fPIC and -mimpure-text [isaacs] 26 | 27 | 0.0.1 / 2010-04-07 28 | ================== 29 | 30 | * Initial release -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | 2 | # Markdown.js 3 | 4 | node bindings for the C "discount" markdown implementation by David Parsons. 5 | 6 | ## Installation 7 | 8 | $ npm install discount 9 | 10 | ## Usage 11 | 12 | var md = require('discount'); 13 | md.parse('markdown is *awesome*') 14 | // => '

markdown is awesome

' 15 | 16 | ### Flags 17 | 18 | md.parse('[links](http://github.com/) are *not* allowed here', md.flags.noLinks) 19 | // => '

[links](http://github.com/) are not allowed here

' 20 | 21 | All [Discount flags](http://www.pell.portland.or.us/~orc/Code/discount/#flags) are supported: 22 | `noLinks`, `noImage`, `noPants`, `noHTML`, `strict`, `tagText`, `noExt`, `cdata`, `noSuperscript`, `noRelaxed`, `noTables`, `noStrikethrough`, `toc`, `md1Compat`, `autolink`, `safelink`, `noHeader`, `tabStop`, `noDivQuote`, `noAlphaList`, `noDlist` and `extraFootnote`. 23 | 24 | ## License 25 | 26 | (The MIT License) 27 | 28 | Copyright (c) 2009 TJ Holowaychuk <tj@vision-media.ca> 29 | 30 | Permission is hereby granted, free of charge, to any person obtaining 31 | a copy of this software and associated documentation files (the 32 | 'Software'), to deal in the Software without restriction, including 33 | without limitation the rights to use, copy, modify, merge, publish, 34 | distribute, sublicense, and/or sell copies of the Software, and to 35 | permit persons to whom the Software is furnished to do so, subject to 36 | the following conditions: 37 | 38 | The above copyright notice and this permission notice shall be 39 | included in all copies or substantial portions of the Software. 40 | 41 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 42 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 43 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 44 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 45 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 46 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 47 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /examples/example.md: -------------------------------------------------------------------------------- 1 | # Title 2 | 3 | [this is a link](http://foo) 4 | Just some random paragraph stuff here. 5 | 6 | ## Lists 7 | 8 | - oh sweet 9 | - some list 10 | - items 11 | 1. booyah! √ 12 | 2. awesome √ 13 | 14 | ## Code 15 | 16 | Even some code: 17 | 18 | foobar! 19 | bazz! 20 | 21 | ~~strikethrough~~ -------------------------------------------------------------------------------- /examples/flags.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Module dependencies. 4 | */ 5 | 6 | var md = require('../build/default/markdown') 7 | , fs = require('fs'); 8 | 9 | fs.readFile(__dirname + '/example.md', 'utf8', function(err, str){ 10 | console.log(md.parse(str, md.flags.noStrikethrough|md.flags.noLinks)); 11 | }); -------------------------------------------------------------------------------- /examples/run.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Module dependencies. 4 | */ 5 | 6 | var md = require('../build/default/markdown') 7 | , fs = require('fs'); 8 | 9 | fs.readFile(__dirname + '/example.md', 'utf8', function(err, str){ 10 | console.log(md.parse(str)); 11 | }); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { "name": "discount" 2 | , "description": "C markdown implementation using discount" 3 | , "tags": ["markdown", "md", "parser", "native"] 4 | , "author" : "TJ Holowaychuk " 5 | , "version": "0.2.3" 6 | , "lib": "./build/Release" 7 | , "main": "./build/Release/markdown" 8 | , "scripts": { "preinstall": "node-waf configure build" } 9 | , "repository" : { "type" : "git" 10 | , "url" : "http://github.com/visionmedia/node-discount.git" 11 | } 12 | , "bugs" : { "web" : "http://github.com/visionmedia/node-discount/issues" } 13 | } 14 | -------------------------------------------------------------------------------- /src/markdown.cc: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // markdown.cc 4 | // 5 | // (c) 2009 TJ Holowaychuk (MIT Licensed) 6 | // 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | extern "C" { 13 | #include 14 | } 15 | 16 | using namespace v8; 17 | using namespace node; 18 | 19 | /* 20 | * Parse the given string of markdown. 21 | */ 22 | 23 | static Handle 24 | Parse(const Arguments& args) { 25 | HandleScope scope; 26 | char *buf; 27 | int len; 28 | int flags; 29 | if (args.Length() < 1 || !args[0]->IsString()) 30 | return ThrowException(Exception::TypeError(String::New("String expected"))); 31 | 32 | if (args.Length() == 2){ 33 | if (!args[1]->IsNumber()){ 34 | return ThrowException(Exception::TypeError(String::New("Flag should be a number"))); 35 | }else{ 36 | flags = args[1]->Int32Value(); 37 | } 38 | } else { 39 | flags = 0; 40 | } 41 | 42 | MMIOT *doc; 43 | String::Utf8Value in(args[0]); 44 | if ((doc = mkd_string(*in, in.length(), flags)) == 0) 45 | return ThrowException(Exception::Error(String::New("Failed to parse markdown"))); 46 | if (mkd_compile(doc, flags)) 47 | len = mkd_document(doc, &buf); 48 | Handle md = String::New(buf); 49 | mkd_cleanup(doc); 50 | return scope.Close(md); 51 | } 52 | 53 | /* 54 | * Initialize. 55 | */ 56 | 57 | extern "C" void 58 | init (Handle target) { 59 | HandleScope scope; 60 | Handle flags; 61 | flags = Object::New(); 62 | flags->Set(String::New("noLinks"), Number::New(MKD_NOLINKS)); 63 | flags->Set(String::New("noImage"), Number::New(MKD_NOIMAGE)); 64 | flags->Set(String::New("noPants"), Number::New(MKD_NOPANTS)); 65 | flags->Set(String::New("noHTML"), Number::New(MKD_NOHTML)); 66 | flags->Set(String::New("strict"), Number::New(MKD_STRICT)); 67 | flags->Set(String::New("tagText"), Number::New(MKD_TAGTEXT)); 68 | flags->Set(String::New("noExt"), Number::New(MKD_NO_EXT)); 69 | flags->Set(String::New("cdata"), Number::New(MKD_CDATA)); 70 | flags->Set(String::New("noSuperscript"), Number::New(MKD_NOSUPERSCRIPT)); 71 | flags->Set(String::New("noRelaxed"), Number::New(MKD_NORELAXED)); 72 | flags->Set(String::New("noTables"), Number::New(MKD_NOTABLES)); 73 | flags->Set(String::New("noStrikethrough"), Number::New(MKD_NOSTRIKETHROUGH)); 74 | flags->Set(String::New("toc"), Number::New(MKD_TOC)); 75 | flags->Set(String::New("md1Compat"), Number::New(MKD_1_COMPAT)); 76 | flags->Set(String::New("autolink"), Number::New(MKD_AUTOLINK)); 77 | flags->Set(String::New("safelink"), Number::New(MKD_SAFELINK)); 78 | flags->Set(String::New("noHeader"), Number::New(MKD_NOHEADER)); 79 | flags->Set(String::New("tabStop"), Number::New(MKD_TABSTOP)); 80 | flags->Set(String::New("noDivQuote"), Number::New(MKD_NODIVQUOTE)); 81 | flags->Set(String::New("noAlphaList"), Number::New(MKD_NOALPHALIST)); 82 | flags->Set(String::New("noDlist"), Number::New(MKD_NODLIST)); 83 | flags->Set(String::New("extraFootnote"), Number::New(MKD_EXTRA_FOOTNOTE)); 84 | target->Set(String::New("version"), String::New("0.2.0")); 85 | target->Set(String::New("flags"), flags); 86 | NODE_SET_METHOD(target, "parse", Parse); 87 | } -------------------------------------------------------------------------------- /wscript: -------------------------------------------------------------------------------- 1 | srcdir = '.' 2 | blddir = 'build' 3 | VERSION = '0.0.1' 4 | 5 | import sys 6 | 7 | def set_options(opt): 8 | opt.tool_options('compiler_cxx') 9 | 10 | def configure(conf): 11 | conf.check_tool('compiler_cxx') 12 | conf.check_tool('node_addon') 13 | conf.check_cfg(atleast_pkgconfig_version='0.0.0', mandatory=True, errmsg='pkg-config was not found') 14 | conf.env.set_variant('Release') 15 | 16 | def build(bld): 17 | bld.exec_command('cp -r ../discount/* .') 18 | bld.exec_command('./configure.sh --with-dl=Both --enable-all-features && make CFLAGS="-g -fPIC"') 19 | 20 | obj = bld.new_task_gen('cxx', 'shlib', 'node_addon') 21 | if sys.platform == 'linux2': 22 | obj.linkflags = ["-lmarkdown", "-L."] 23 | else: 24 | obj.linkflags = ["-lmarkdown", "-mimpure-text", "-L."] 25 | obj.target = 'markdown' 26 | obj.source = 'src/markdown.cc' 27 | obj.cxxflags = ["-fPIC", "-I."] 28 | --------------------------------------------------------------------------------