From ef3ce54bcb3b4c1c7bba8d64d7478a3528ce290f Mon Sep 17 00:00:00 2001 From: Nicolas Bevacqua Date: Sun, 15 Mar 2015 19:55:14 -0300 Subject: [PATCH] initial commit --- .editorconfig | 13 ++ .gitignore | 4 + .jshintignore | 5 + .jshintrc | 23 ++ TODO.md | 3 + bower.json | 11 + changelog.markdown | 3 + example/example.css | 152 ++++++++++++ example/example.js | 25 ++ index.html | 41 ++++ license | 20 ++ package.json | 41 ++++ ponymark/configure.js | 23 ++ ponymark/node.js | 81 +++++++ readme.markdown | 167 ++++++++++++++ src/InputHistory.js | 199 ++++++++++++++++ src/InputState.js | 79 +++++++ src/barkup.js | 266 +++++++++++++++++++++ src/barkup.styl | 67 ++++++ src/bindCommands.js | 73 ++++++ src/chunks/parseLinkInput.js | 51 ++++ src/chunks/trim.js | 19 ++ src/classes.js | 20 ++ src/extendRegExp.js | 18 ++ src/fixEOL.js | 7 + src/getCommandHandler.js | 38 +++ src/getSurface.js | 199 ++++++++++++++++ src/html/HtmlChunks.js | 16 ++ src/html/blockquote.js | 10 + src/html/boldOrItalic.js | 10 + src/html/codeblock.js | 10 + src/html/heading.js | 34 +++ src/html/hr.js | 8 + src/html/linkOrImage.js | 69 ++++++ src/html/list.js | 71 ++++++ src/html/wrapping.js | 33 +++ src/isVisibleElement.js | 11 + src/many.js | 7 + src/markdown/MarkdownChunks.js | 69 ++++++ src/markdown/blockquote.js | 126 ++++++++++ src/markdown/boldOrItalic.js | 37 +++ src/markdown/codeblock.js | 85 +++++++ src/markdown/heading.js | 47 ++++ src/markdown/hr.js | 9 + src/markdown/linkOrImage.js | 117 ++++++++++ src/markdown/list.js | 87 +++++++ src/markdown/settings.js | 5 + src/markdown/wrapping.js | 29 +++ src/once.js | 14 ++ src/polyfills/getSelection.js | 14 ++ src/polyfills/getSelectionNullOp.js | 12 + src/polyfills/getSelectionRaw.js | 7 + src/polyfills/getSelectionSynthetic.js | 307 +++++++++++++++++++++++++ src/polyfills/isHost.js | 29 +++ src/prompts/close.js | 35 +++ src/prompts/image.js | 117 ++++++++++ src/prompts/link.js | 58 +++++ src/prompts/render.js | 72 ++++++ src/renderers.js | 28 +++ src/setText.js | 7 + src/strings.js | 25 ++ 61 files changed, 3263 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 .jshintignore create mode 100644 .jshintrc create mode 100644 TODO.md create mode 100644 bower.json create mode 100644 changelog.markdown create mode 100644 example/example.css create mode 100644 example/example.js create mode 100644 index.html create mode 100644 license create mode 100644 package.json create mode 100644 ponymark/configure.js create mode 100644 ponymark/node.js create mode 100644 readme.markdown create mode 100644 src/InputHistory.js create mode 100644 src/InputState.js create mode 100644 src/barkup.js create mode 100644 src/barkup.styl create mode 100644 src/bindCommands.js create mode 100644 src/chunks/parseLinkInput.js create mode 100644 src/chunks/trim.js create mode 100644 src/classes.js create mode 100644 src/extendRegExp.js create mode 100644 src/fixEOL.js create mode 100644 src/getCommandHandler.js create mode 100644 src/getSurface.js create mode 100644 src/html/HtmlChunks.js create mode 100644 src/html/blockquote.js create mode 100644 src/html/boldOrItalic.js create mode 100644 src/html/codeblock.js create mode 100644 src/html/heading.js create mode 100644 src/html/hr.js create mode 100644 src/html/linkOrImage.js create mode 100644 src/html/list.js create mode 100644 src/html/wrapping.js create mode 100644 src/isVisibleElement.js create mode 100644 src/many.js create mode 100644 src/markdown/MarkdownChunks.js create mode 100644 src/markdown/blockquote.js create mode 100644 src/markdown/boldOrItalic.js create mode 100644 src/markdown/codeblock.js create mode 100644 src/markdown/heading.js create mode 100644 src/markdown/hr.js create mode 100644 src/markdown/linkOrImage.js create mode 100644 src/markdown/list.js create mode 100644 src/markdown/settings.js create mode 100644 src/markdown/wrapping.js create mode 100644 src/once.js create mode 100644 src/polyfills/getSelection.js create mode 100644 src/polyfills/getSelectionNullOp.js create mode 100644 src/polyfills/getSelectionRaw.js create mode 100644 src/polyfills/getSelectionSynthetic.js create mode 100644 src/polyfills/isHost.js create mode 100644 src/prompts/close.js create mode 100644 src/prompts/image.js create mode 100644 src/prompts/link.js create mode 100644 src/prompts/render.js create mode 100644 src/renderers.js create mode 100644 src/setText.js create mode 100644 src/strings.js diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..5d12634 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +# editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..900f6bd --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +node_modules +npm-debug.log +.DS_Store +Thumbs.db diff --git a/.jshintignore b/.jshintignore new file mode 100644 index 0000000..b392aa8 --- /dev/null +++ b/.jshintignore @@ -0,0 +1,5 @@ +node_modules +bower_components +dist +example +ponymark diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..b51347f --- /dev/null +++ b/.jshintrc @@ -0,0 +1,23 @@ +{ + "curly": true, + "eqeqeq": true, + "newcap": true, + "noarg": true, + "noempty": true, + "nonew": true, + "sub": true, + "undef": true, + "unused": true, + "trailing": true, + "boss": true, + "eqnull": true, + "strict": true, + "immed": true, + "expr": true, + "latedef": "nofunc", + "quotmark": "single", + "validthis": true, + "indent": 2, + "node": true, + "browser": true +} diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..a09ffed --- /dev/null +++ b/TODO.md @@ -0,0 +1,3 @@ +- image uploading +- arbitrary attachments/endpoints/file types +- play nicely with autocompletion diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..8b39bc1 --- /dev/null +++ b/bower.json @@ -0,0 +1,11 @@ +{ + "name": "barkup", + "version": "1.0.0", + "description": "Barking up the DOM tree. A modular, progressive, and beautiful Markdown and HTML editor", + "main": "dist/barkup.js", + "homepage": "https://github.com/bevacqua/barkup", + "authors": [ + "Nicolas Bevacqua " + ], + "license": "MIT" +} diff --git a/changelog.markdown b/changelog.markdown new file mode 100644 index 0000000..6fb6b91 --- /dev/null +++ b/changelog.markdown @@ -0,0 +1,3 @@ +# 1.0.0 IPO + +- Initial Public Release diff --git a/example/example.css b/example/example.css new file mode 100644 index 0000000..e442c1f --- /dev/null +++ b/example/example.css @@ -0,0 +1,152 @@ +body { + background-color: #e74c3c; + margin: 0 auto; + max-width: 760px; +} + +html, body { + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; +} + +*, *:before, *:after { + -webkit-box-sizing: inherit; + -moz-box-sizing: inherit; + box-sizing: inherit; +} + +body, input, button { + font-family: Georgia, Helvetica; + font-size: 17px; + color: #ecf0f1; +} + +h1 { + margin-top: 20px; + padding: 10px 0; + text-align: center; +} + +h1,h2,h3,h4,h5,h6{ + background-color: rgba(255, 255, 255, 0.2); +} + +h3 { + padding: 10px; + text-align: center; + line-height: 36px; +} + +h3 b { + font-size: 27px; + color: #2c3e50; +} + +a, +a:hover { + color: #ecf0f1; +} + +pre code { + color: #fff; + font-size: 18px; +} + +blockquote { + border-left: 5px solid #fff; + margin: 10px 0; + padding: 0 15px; +} + +label { + display: block; + margin-bottom: 15px; +} + +sub { + display: block; + margin-top: -10px; + margin-bottom: 15px; + font-size: 11px; + font-style: italic; +} + +ul { + margin: 0; + padding: 0; +} + +.parent { + background-color: rgba(255, 255, 255, 0.2); + margin: 50px 0; + padding: 20px; +} + +input, +textarea { + border: none; + outline: none; + background-color: #ecf0f1; + padding: 10px; + color: #e74c3c; + border: 0; + display: block; + width: 100%; +} + +textarea { + min-height: 350px; + font-size: 14px; +} + +button { + background-color: #ecf0f1; + color: #e74c3c; + border: 0; + padding: 18px 12px; + cursor: pointer; + outline: none; +} + +button:hover { + background-color: #e74c3c; + color: #ecf0f1; +} + +kbd { + display: inline-block; + border: 1px solid #ccc; + margin: -2px 0.1em 0; + padding: 0.1em 0.6em; + line-height: 1.4; + font-size: 11px; + background-color: #f8f8f8; + box-shadow: 0 1px 0 #bbb, 0 0 0 2px #fff inset; + border-radius: 3px; + color: #555; + text-shadow: 0 1px 0 #fff; + white-space: nowrap; + vertical-align: middle; +} + +.nsg-tag { + border-color: #e74c3c; +} + +.inline { + display: inline-block; +} + +.gh-fork { + position: fixed; + top: 0; + right: 0; + border: 0; + z-index: 1; +} + +.autofruit { + width: 16px; + margin-right: 3px; +} diff --git a/example/example.js b/example/example.js new file mode 100644 index 0000000..248467c --- /dev/null +++ b/example/example.js @@ -0,0 +1,25 @@ +void function () { + 'use strict'; + + barkup(ta, { + parseMarkdown: megamark, + parseHTML: domador + }); + + function events (el, type, fn) { + if (el.addEventListener) { + el.addEventListener(type, fn); + } else if (el.attachEvent) { + el.attachEvent('on' + type, wrap(fn)); + } else { + el['on' + type] = wrap(fn); + } + function wrap (originalEvent) { + var e = originalEvent || global.event; + e.target = e.target || e.srcElement; + e.preventDefault = e.preventDefault || function preventDefault () { e.returnValue = false; }; + e.stopPropagation = e.stopPropagation || function stopPropagation () { e.cancelBubble = true; }; + fn.call(el, e); + } + } +}(); diff --git a/index.html b/index.html new file mode 100644 index 0000000..07b1aaa --- /dev/null +++ b/index.html @@ -0,0 +1,41 @@ + + + +barkup +

barkup

+

Barking up the DOM tree. **woof** <strong>woof</strong>
A modular, progressive, and beautiful Markdown and HTML editor

+ + Fork me on GitHub + +
+ +
+ +
+
+    
+barkup(ta, {
+  parseMarkdown: megamark,
+  parseHTML: domador
+});
+    
+  
+
+

Get it on GitHub! bevacqua/barkup

+ + + + diff --git a/license b/license new file mode 100644 index 0000000..b980cef --- /dev/null +++ b/license @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright © 2015 Nicolas Bevacqua + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/package.json b/package.json new file mode 100644 index 0000000..9118c81 --- /dev/null +++ b/package.json @@ -0,0 +1,41 @@ +{ + "name": "barkup", + "version": "1.0.0", + "description": "Barking up the DOM tree. A modular, progressive, and beautiful Markdown and HTML editor", + "main": "src/barkup.js", + "scripts": { + "start": "browserify -s barkup -do dist/barkup.js src/barkup.js && watchify -s barkup -dvo dist/barkup.js src/barkup.js & stylus -w src/barkup.styl -o dist", + "scripts": "jshint . && browserify -s barkup -do dist/barkup.js src/barkup.js && uglifyjs -m -c -o dist/barkup.min.js dist/barkup.js", + "styles": "stylus src/barkup.styl -o dist && cleancss dist/barkup.css -o dist/barkup.min.css", + "build": "npm run scripts && npm run styles", + "deployment": "git add dist && npm version ${BUMP:-\"patch\"} --no-git-tag-version && git add package.json && git commit -m \"Autogenerated pre-deployment commit\" && bower version ${BUMP:-\"patch\"} && git reset HEAD~2 && git add . && git commit -am \"Release $(cat package.json | jq -r .version)\" && git push --tags && npm publish && git push", + "sync": "git checkout gh-pages ; git merge master ; git push ; git checkout master", + "deploy": "npm run build && npm run deployment && npm run sync" + }, + "repository": { + "type": "git", + "url": "https://github.com/bevacqua/barkup.git" + }, + "author": "Nicolas Bevacqua (http://bevacqua.io/)", + "license": "MIT", + "bugs": { + "url": "https://github.com/bevacqua/barkup/issues" + }, + "homepage": "https://github.com/bevacqua/barkup", + "devDependencies": { + "browserify": "^8.1.0", + "clean-css": "^3.0.4", + "domador": "^1.1.0", + "jshint": "^2.5.11", + "megamark": "^2.1.3", + "nib": "^1.0.4", + "stylus": "^0.49.3", + "uglify-js": "^2.4.16", + "watchify": "^2.2.1" + }, + "dependencies": { + "crossvent": "^1.1.0", + "kanye": "^2.0.2", + "local-storage": "^1.4.0" + } +} diff --git a/ponymark/configure.js b/ponymark/configure.js new file mode 100644 index 0000000..cd0bcd4 --- /dev/null +++ b/ponymark/configure.js @@ -0,0 +1,23 @@ +'use strict'; + +function configure (opts) { + var uploads; + var o = opts || {}; + if (o.imageUploads) { + if (typeof o.imageUploads === 'string') { + uploads = { url: o.imageUploads }; + } else { + uploads = o.imageUploads; + } + if (!uploads.url) { throw new Error('Required imageUploads.url property missing'); } + if (!uploads.method) { uploads.method = 'PUT'; } + if (!uploads.key) { uploads.key = 'image'; } + if (!uploads.timeout) { uploads.timeout = 15000; } + configure.imageUploads = uploads; + } + if (o.markdown) { + configure.markdown = o.markdown; + } +} + +module.exports = configure; diff --git a/ponymark/node.js b/ponymark/node.js new file mode 100644 index 0000000..fbf08ff --- /dev/null +++ b/ponymark/node.js @@ -0,0 +1,81 @@ +'use strict'; + +var contra = require('contra'); +var path = require('path'); +var fs = require('fs-extra'); +var mkdirp = require('mkdirp'); +var tmp = require('tmp'); +var imgur = require('imgur-client'); +var imgurClient; +var defaultLocal = path.resolve('./uploads'); +var production = process.env.NODE_ENV === 'production'; + +function defaultLocalUrl (local, file) { + return file.replace(local, '/img/uploads'); +} + +function imageUpload (options, done) { + var o = { + image: options.image, + imgur: options.imgur, + local: options.local || defaultLocal, + localUrl: options.localUrl || defaultLocalUrl, + production: options.production || production + }; + if (o.imgur) { + imgurClient = imgur(o.imgur); + } + if (!o.production) { + mkdirp.sync(o.local); + } + + if (!o.image) { + done(new Error('No image received on the back-end')); + } else if (imgurClient) { + imgurUpload(o, done); + } else if (!o.production) { + fileUpload(o, done); + } else { + done(new Error('Misconfigured ponymark.imageUpload!')); + } +} + +function imgurUpload (o, done) { + imgurClient.upload(o.image.path, function (err, data) { + if (err) { + done(err); return; + } + + done(null, { + alt: o.image.originalname, + url: data.links.original + }); + }); +} + +function fileUpload (o, done) { + var template = path.join(o.local, 'XXXXXX' + o.image.extension); + + contra.waterfall([ + function (next) { + tmp.tmpName({ template: template }, next); + }, + function (temp, next) { + fs.move(o.image.path, temp, function (err) { + next(err, temp); + }); + } + ], function (err, temp) { + if (err) { + done(err); return; + } + done(null, { + alt: o.image.originalname, + url: o.localUrl(o.local, temp) + }); + }); +} + +module.exports = { + imageUpload: imageUpload +}; diff --git a/readme.markdown b/readme.markdown new file mode 100644 index 0000000..3fd7b10 --- /dev/null +++ b/readme.markdown @@ -0,0 +1,167 @@ +# barkup + +> Barking up the DOM tree. A modular, progressive, and beautiful Markdown and HTML editor + +Browser support includes every sane browser and **IE7+**. + +# Features + +- Small and focused +- Progressive, enhance a raw `