Skip to content

Commit

Permalink
Implementing markdown2wiki script that reads markdown form stdin and …
Browse files Browse the repository at this point in the history
…writes wiki to stdout
  • Loading branch information
Gozala committed Sep 21, 2010
1 parent 9376739 commit 387c98e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
11 changes: 11 additions & 0 deletions bin/markdown2wiki
@@ -0,0 +1,11 @@
#!/usr/bin/env node
// vim:ft=javascript

var markdown2wiky = require('markdown-wiki').markdown2wiki
, stdin = process.openStdin()

stdin.setEncoding('utf8')
stdin.on('data', function (data) {
process.stdout.write((markdown2wiky(data)))
})

25 changes: 25 additions & 0 deletions lib/markdown-wiki.js
@@ -0,0 +1,25 @@
var markdown2html = require('node-markdown').Markdown
, html2wiki = require('wiky').toWiki

function markdown2wiki(input) {
return html2wiki(markdown2html(input)).
// `x` -> <tt>x</tt>
replace(/%([^%]*)%/g, '<tt>$1<\/tt>').
// <code>x</code> -> <source>x</source>
replace(/<([\/]*)code>/g, '<$1source>').
// *x* -> <strong>x</strong>
replace(/\*([^\*]*)\*/g, '<strong>$1</strong>').
// <li> -> *
replace(/<li>/g, '* ').
// <p>x</p> -> x
replace(/<p[^>]*>/g, '').
//
replace(/<\/source><\/tt>\]/g, '</source>').
replace(/\[<tt><source>/g, '<source>')//.
//replace(/_([^_]*)_/g, '<emphasis>$1</emphasis>')
}
exports.markdown2wiki = markdown2wiki

function wiki2markdown(input) {
}
exports.wiki2markdown = wiki2markdown
6 changes: 3 additions & 3 deletions package.json
@@ -1,4 +1,4 @@
{ "name": "wiky2markdown"
{ "name": "markdown-wiki"
, "version": "0.0.1"
, "description": "A Bidirectional WikiText to Markdown converter."
, "homepage": "http://github.com/Gozala/wiky2markdown/"
Expand All @@ -20,8 +20,8 @@
"node-markdown": ">=0.1.0",
"wiky": ">=0.95.1"
}
, "main": "./lib/wiky2markdown"
, "bin" : { "wiky2markdown" : "./bin/wiky2markdown" }
, "main": "./lib/markdown-wiki"
, "bin" : { "markdown2wiki" : "./bin/markdown2wiki" }
, "engines": { "node": ">=0.1.103" }
, "licenses" :
[ { "type" : "MIT"
Expand Down

2 comments on commit 387c98e

@ashb
Copy link

@ashb ashb commented on 387c98e Sep 21, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing with rexeps makes for a sad panda - have you considered using github.com/evilstreak/markdown-js/ for the markdown part? It has an AST which might make the processing more robust.

@Gozala
Copy link
Owner Author

@Gozala Gozala commented on 387c98e Oct 6, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks I'll take a look at that! I guess it's not / was not in npm registry back then

Please sign in to comment.