Browse files

Implementing markdown2wiki script that reads markdown form stdin and …

…writes wiki to stdout
  • Loading branch information...
1 parent 9376739 commit 387c98e08268b34a2474de7ae5d59d8aacbbfe27 @Gozala committed Sep 21, 2010
Showing with 39 additions and 3 deletions.
  1. +11 −0 bin/markdown2wiki
  2. +25 −0 lib/markdown-wiki.js
  3. +3 −3 package.json
View
11 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)))
+})
+
View
25 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
View
6 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/"
@@ -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"

2 comments on commit 387c98e

@ashb

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
Owner

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.