hello world
+``` + +Usage: `textile [-o outputfile] [inputfile]` + +If no input file is provided, the program will listen to data on `stdin`. + + +## License + +Copyright © 2012, Borgar Þorsteinsson (MIT License). + +See [LICENSE](./LICENSE) diff --git a/README.textile b/README.textile deleted file mode 100644 index 7f85852..0000000 --- a/README.textile +++ /dev/null @@ -1,43 +0,0 @@ -h1. textile.js - -Attempt at an implementation of fully featured Textile parser in JavaScript that runs reasonably fast and mostly avoids outputting broken HTML. - -Give it a go in "a live textile web editor":http://borgar.github.com/textile-js/. - - -h2. Install - -bc. $ npm install textile-js - - -h2. Options - -The basic interface mimics "marked":https://github.com/chjj/marked, the popular markdown parser. So if you use that in your project then you can support Textile as well with minimal effort. - -Currently, the only supported option is @breaks@ which can be used to enable/disable the default behavior of line-breaking single newlines within blocks. - - -h2. Usage - -bc. console.log( textile( "I am using __textile__." ) ); - -You can also get to the syntax tree, which uses "JsonML":http://www.jsonml.org/. - -bc. var jsonml = textile.parse( text ); -console.log( jsonml ); - - -h2. CLI - -bc. $ textile -o hello.html -hello world -^D -$ cat hello.html -hello world
- - -h2. License - -Copyright (c) 2012, Borgar Þorsteinsson (MIT License). - -See LICENSE. diff --git a/bin/textile b/bin/textile deleted file mode 100755 index eccd0e3..0000000 --- a/bin/textile +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env node - -var fs = require( 'fs' ); - -var textile; -var nodeVersion = process && process.versions && process.versions.node; -// is this node version mostly ES6 complete -if ( parseInt( nodeVersion || 0, 10 ) > 5 ) { - // serve code from src dir - textile = require( '../src' ); -} -else { - // serve transpiled code - textile = require( '../dist/textile' ); -} - -// clean arguments -var args = []; -process.argv.slice( 2 ).forEach( function ( m, i, s ) { - if ( ( s = /^([^=]+)=(.*)$/.exec( m ) ) ) { - args.push( s[1], s[2] ); - } - else { - args.push( m ); - } -}); - -// parse arguments -var options = {}; -while ( args.length ) { - var arg = args.shift(); - if ( arg === '-t' || arg === '--tokens' ) { - options.tokens = true; - } - else if ( arg === '-i' || arg === '--input' ) { - options.input = args.shift(); - } - else if ( arg === '-o' || arg === '--output' ) { - options.output = args.shift(); - } - else { - if ( !options.files ) { options.files = []; } - options.files.shift( arg ); - } -} - -// input overrides file arguments -if ( options.input ) { - options.files = [ options.input ]; -} - -// writer -var data = ''; -function writeData () { - data = options.tokens ? JSON.stringify( textile.jsonml( data ), null, 2 ) - : textile( data ); - if ( options.output ) { - fs.writeFileSync( options.output, data ); - } - else { - process.stdout.write( data + '\n' ); - } -} - -// file or stdin? -if ( options.files ) { - data = fs.readFileSync( options.files[0], 'utf8' ); - writeData(); -} -else { - const stdin = process.stdin; - stdin.setEncoding( 'utf8' ); - stdin.on( 'data', function ( text ) { - data += text; - }); - stdin.on( 'end', writeData ); - stdin.resume(); -} diff --git a/bin/textile.js b/bin/textile.js new file mode 100755 index 0000000..3acef8a --- /dev/null +++ b/bin/textile.js @@ -0,0 +1,58 @@ +#!/usr/bin/env node +/* globals process */ +import fs from 'fs'; +import textile from '../src/index.js'; + +// clean arguments +const args = []; +process.argv.slice(2).forEach(function (m, i, s) { + if ((s = /^([^=]+)=(.*)$/.exec(m))) { + args.push(s[1], s[2]); + } + else { + args.push(m); + } +}); + +// parse arguments +const options = {}; +while (args.length) { + const arg = args.shift(); + if (arg === '-o' || arg === '--output') { + options.output = args.shift(); + } + else { + if (!options.files) { options.files = []; } + options.files.push(arg); + } +} + +// input overrides file arguments +if (options.input) { + options.files = [ options.input ]; +} + +// writer +let data = ''; +function writeData () { + const output = textile(data); + if (options.output) { + fs.writeFileSync(options.output, output); + } + else { + process.stdout.write(output + '\n'); + } +} + +// file or stdin? +if (options.files) { + data = fs.readFileSync(options.files[0], 'utf8'); + writeData(); +} +else { + const stdin = process.stdin; + stdin.setEncoding('utf8'); + stdin.on('data', text => (data += text)); + stdin.on('end', writeData); + stdin.resume(); +} diff --git a/docs/app.css b/docs/app.css index 8f8af8d..90492ce 100644 --- a/docs/app.css +++ b/docs/app.css @@ -11,15 +11,14 @@ body { padding: 0; height: 100%; - display: flex; - flex-direction: column; - align-content: stretch; - -} - -body > * { - flex: 0 1 auto; - align-self: auto; + display: grid; + grid-template-columns: 1fr 1fr; + grid-template-rows: 55px 25px 1fr; + gap: 0px 6px; + grid-template-areas: + "header header" + "txHead oHead" + "txBody oBody"; } body > h1 { @@ -27,86 +26,59 @@ body > h1 { margin: 0; font-size: 20px; color: #444; + grid-area: header; } -textarea { - font-family: "andale mono", "lucida console", monospace; - font-size: 12px; - display: block; - resize: none; -} - -.row { - margin: 0 0; - - flex: 1 1 auto; - align-self: stretch; - - display: flex; - flex-direction: row; - flex-wrap: nowrap; - align-items: stretch; -} - -.col { - position: relative; - box-sizing: border-box; - margin: 0 1rem 0 0; - padding: 0; - width: 50%; - - flex: 1 1 auto; - align-self: stretch; -} -.col:first-child { - margin: 0 1rem 0 1rem; +#tx_hd { + grid-area: txHead; } -.col { - display: flex; - flex-direction: column; - align-content: stretch; +#tx_body { + grid-area: txBody; + margin-top: -1px; + border-top: 1px solid #aaa; } -.col .hd { - flex: 0 1 auto; - align-self: auto; +#o_hd { + grid-area: oHead; } -.col > div, .col textarea { - flex: 1 1 auto; - align-self: stretch; +#o_body { + grid-area: oBody; + overflow: auto; + margin-top: -1px; + border-top: 1px solid #aaa; } - -label { - display: block; - padding: 4px 0; - font-weight: bold; - color: #777; -} -.tools { - position: absolute; - top: 0; - right: 0; - padding: 0; +#tx_body > * { + height: 100%; + box-sizing: border-box; + background: white; + font-family: consolas, "andale mono", "lucida console", monospace; + resize: none; + padding: 1rem; + width: 100%; + border: 0; + line-height: 1.25; + font-size: 14px; + outline: none; } - -.panel { - background: #fff; - border: 1px solid #aaaaaa; - outline: none; - display: block; - margin: 0; - padding: 4px; +#o_body > * { box-sizing: border-box; -} -#text_preview { - overflow: auto; + background: white; + padding: 1rem; + width: 100%; + border: 0; + color: #444; + min-height: 100%; } -#md_input { - background: #f6f6f6; +#syntax_guide, +#html_output { + white-space: pre-wrap; + font-size: 14px; + font-family: consolas, "andale mono", "lucida console", monospace; + line-height: 1.25; } #syntax_guide, @@ -114,22 +86,23 @@ label { display: none; } - -#credit1 { - background: url(http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png) -27px -15px no-repeat; +.td_hd { + position: relative; +} +.tools { position: absolute; - top: 0; - right: 0; - text-indent: -999em; - display: block; - overflow: hidden; - height: 108px; - width: 108px; - zoom: .8; + bottom: 2px; + right: 16px; + padding: 0; } - -#foot { - min-height: 1rem; +.tools button { + border: 0; + background: white; + color: #444; + padding: 2px 10px; + border-radius: 12px; + border-bottom: 1px solid #aaa; + cursor: pointer; } @@ -137,34 +110,47 @@ label { padding: 0; margin: 0; list-style: none; + height: 100%; + box-sizing: border-box; + padding-left: 10px; } .tab li { display: inline-block; + height: 100%; + box-sizing: border-box; } +.tab li label, .tab li a { + height: 100%; display: block; + box-sizing: border-box; padding: 4px 10px; text-decoration: none; color: #999; background: #eee; margin: 0 1px; } +.tab .current label, .tab .current a { color: #555; background: #fff; padding-bottom: 5px; - margin: -1px 0; + margin: 0; border: 1px solid #aaa; + border-bottom: 1px solid #fff; + z-index: 213; + position: relative; } #text_preview { - padding: 0 1em 4px 1em; - color: #444; - font-size: 13px; + font-size: 16px; line-height: 1.4; } +#text_preview > *:first-child { + margin-top: 0; +} #text_preview h1 { line-height: 1.1; font-size: 2em; @@ -195,10 +181,15 @@ label { #text_preview table { border-collapse : collapse; } +#text_preview th { + text-align: left; +} #text_preview table th, #text_preview table td { padding : 4px 8px; border : 1px solid #aaa; + text-align: left; + vertical-align : top; } #text_preview ul { margin-left: 0; @@ -222,3 +213,4 @@ label { text-transform: lowercase; letter-spacing: .1em; } + diff --git a/docs/app.js b/docs/app.js index a7d084c..138bb95 100644 --- a/docs/app.js +++ b/docs/app.js @@ -1,6 +1,5 @@ /* globals document fetch textile localStorage setTimeout clearTimeout */ (function () { - function getElm (selector) { return document.querySelector(selector); } @@ -47,7 +46,7 @@ processing_time = endTime - startTime; text_preview.innerHTML = html; - html_output.value = html; + html_output.textContent = html; // save last output text to storage if we have it if (!input.value || input.value === help_text) { @@ -59,7 +58,6 @@ } - // $('.tab').minitabs(); const tabs = Array.from(document.querySelectorAll('.tab a')); tabs.forEach(d => { d.addEventListener('click', e => { @@ -76,7 +74,7 @@ let convertTextTimer; - attach('#tx_input', 'keyup', e => { + attach('#tx_input', 'keyup', () => { clearTimeout(convertTextTimer); const defer_time = Math.min(processing_time, max_delay); convertTextTimer = setTimeout(convert_text, defer_time); @@ -92,7 +90,7 @@ // load syntax guide loadText('syntax.txt', txt => { - getElm('#syntax_guide').value = txt; + getElm('#syntax_guide').textContent = txt; }); // load help text @@ -103,10 +101,9 @@ } }); - attach('button.clear', 'click', e => { + attach('button.clear', 'click', () => { convert_text(''); }); convert_text(); - })(); diff --git a/docs/index.html b/docs/index.html index d2ffc59..135c965 100644 --- a/docs/index.html +++ b/docs/index.html @@ -10,31 +10,30 @@ - user can still create nonsensical but "well-formed" markup
-function parse (tokens, lazy) {
- const root = [];
+// No steps are taken however to prevent things like
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||