summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-markdown/lib/tomarkdown.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-20 15:31:59 +0100
committerSamy Pessé <samypesse@gmail.com>2016-12-22 15:00:51 +0100
commitdbee17ddec2e786fbf02572e7bf6050c207b492f (patch)
tree8d93bd8eb985e3bd8132612935bc5a1583fe15e3 /packages/gitbook-markdown/lib/tomarkdown.js
parent9b3888005d5098079056fa889a84e75cf3c57670 (diff)
downloadgitbook-dbee17ddec2e786fbf02572e7bf6050c207b492f.zip
gitbook-dbee17ddec2e786fbf02572e7bf6050c207b492f.tar.gz
gitbook-dbee17ddec2e786fbf02572e7bf6050c207b492f.tar.bz2
Use gitbook-html as base parser
Diffstat (limited to 'packages/gitbook-markdown/lib/tomarkdown.js')
-rw-r--r--packages/gitbook-markdown/lib/tomarkdown.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/packages/gitbook-markdown/lib/tomarkdown.js b/packages/gitbook-markdown/lib/tomarkdown.js
new file mode 100644
index 0000000..5bee4e0
--- /dev/null
+++ b/packages/gitbook-markdown/lib/tomarkdown.js
@@ -0,0 +1,43 @@
+
+// Return N time a string
+function ns(s, n) {
+ return Array(n + 1).join(s);
+}
+
+module.exports = {
+ onTitleStart: function(level) {
+ return ns('#', level) + ' ';
+ },
+ onTitleEnd: function(level) {
+ return this.onBL();
+ },
+
+ onParagraphStart: function() {
+ return this.onSection();
+ },
+ onParagraphEnd: function() {
+ return this.onSection();
+ },
+
+ onLinkStart: function() {
+ return '[';
+ },
+ onLinkEnd: function(href) {
+ return '](' + href +')';
+ },
+
+ onListStart: function(level) {
+ return '';
+ },
+ onListEnd: function() {
+ return '';
+ },
+
+ onListItemStart: function(level) {
+ return ns(' ', level * 4) + '* ';
+ },
+ onListItemEnd: function() {
+ return '';
+ },
+};
+