diff options
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | README.md | 30 | ||||
| -rwxr-xr-x | js/stmd.js | 19 | ||||
| -rwxr-xr-x | js/test.js | 19 | ||||
| -rw-r--r-- | man/man1/stmd.1 | 2 | ||||
| -rw-r--r-- | man/stmd.1.md | 4 | ||||
| -rw-r--r-- | narrative.md | 4 | ||||
| -rw-r--r-- | spec.txt | 32 | ||||
| -rw-r--r-- | src/html.c | 6 | ||||
| -rw-r--r-- | src/main.c | 2 | 
10 files changed, 64 insertions, 56 deletions
| @@ -66,7 +66,7 @@ update-site: spec.html narrative.html  	cp spec.html _site/  	cp narrative.html _site/index.html  	cp -r js/* _site/js/ -	(cd _site ; git commit -a -m "Updated site for latest spec, narrative, js" ; git push; cd ..) +	(cd _site ; git pull ; git commit -a -m "Updated site for latest spec, narrative, js" ; git push; cd ..)  clean:  	-rm test $(SRCDIR)/*.o $(SRCDIR)/scanners.c @@ -1,14 +1,14 @@ -Standard markdown -================= +CommonMark +========== -Standard markdown is a [specification of markdown syntax][the spec], +CommonMark is a [specification of Markdown syntax][the spec],  together with BSD3-licensed implementations (`stmd`) in C and javascript.  The implementations  -------------------  The C implementation provides both a library and a standalone program -`stmd` that converts markdown to HTML.  It is written in standard C99 +`stmd` that converts Markdown to HTML.  It is written in standard C99  and has no library dependencies.  (However, if you check it out from the  repository, you'll need [`re2c`](http://re2c.org) to generate  `scanners.c` from `scanners.re`.  This is only a build dependency for @@ -30,7 +30,7 @@ this.)  [The spec] contains over 400 embedded examples which serve as conformance  tests.  To run the tests for `stmd`, do `make test`.  To run them for -another markdown program, say `myprog`, do `make test PROG=myprog`.  To +another Markdown program, say `myprog`, do `make test PROG=myprog`.  To  run the tests for `stmd.js`, do `make testjs`.  [The spec]:  http://jgm.github.io/stmd/spec.html @@ -38,11 +38,11 @@ run the tests for `stmd.js`, do `make testjs`.  The spec  -------- -The source of [the spec] is `spec.txt`.  This is basically a markdown +The source of [the spec] is `spec.txt`.  This is basically a Markdown  file, with code examples written in a shorthand form:      . -    markdown source +    Markdown source      .      expected HTML output      . @@ -55,7 +55,7 @@ The spec is written from the point of view of the human writer, not  the computer reader.  It is not an algorithm---an English translation of  a computer program---but a declarative description of what counts as a block  quote, a code block, and each of the other structural elements that can -make up a markdown document. +make up a Markdown document.  Because John Gruber's [canonical syntax  description](http://daringfireball.net/projects/markdown/syntax) leaves @@ -64,13 +64,13 @@ making a large number of decisions, many of them somewhat arbitrary.  In making them, I have appealed to existing conventions and  considerations of simplicity, readability, expressive power, and  consistency.  I have tried to ensure that "normal" documents in the many -incompatible existing implementations of markdown will render, as far as +incompatible existing implementations of Markdown will render, as far as  possible, as their authors intended.  And I have tried to make the rules  for different elements work together harmoniously.  In places where  different decisions could have been made (for example, the rules  governing list indentation), I have explained the rationale for  my choices.  In a few cases, I have departed slightly from the canonical -syntax description, in ways that I think further the goals of markdown +syntax description, in ways that I think further the goals of Markdown  as stated in that description.  For the most part, I have limited myself to the basic elements @@ -80,17 +80,17 @@ right before considering such things. However, I have included a visible  syntax for line breaks and fenced code blocks.  In all of this, I have been guided by eight years experience writing -markdown implementations in several languages, including the first -markdown parser not based on regular expression substitutions +Markdown implementations in several languages, including the first +Markdown parser not based on regular expression substitutions  ([pandoc](http://github.com/jgm/pandoc)) and the first markdown parsers  based on PEG grammars  ([peg-markdown](http://github.com/jgm/peg-markdown),  [lunamark](http://github.com/jgm/lunamark)). Maintaining these projects  and responding to years of user feedback have given me a good sense of -the complexities involved in parsing markdown, and of the various design +the complexities involved in parsing Markdown, and of the various design  decisions that can be made.  I have also explored differences between -markdown implementations extensively using [babelmark +Markdown implementations extensively using [babelmark  2](http://johnmacfarlane.net/babelmark2/).  In the early phases of  working out the spec, I benefited greatly from collaboration with David -Greenspan, and from feedback from several industrial users of markdown, +Greenspan, and from feedback from several industrial users of Markdown,  including Jeff Atwood, Vincent Marti, and Neil Williams. @@ -1,4 +1,4 @@ -// stmd.js - "standard markdown" in javascript +// stmd.js - CommomMark in javascript  // Copyright (C) 2014 John MacFarlane  // License: BSD3. @@ -373,7 +373,7 @@ var parseEmphasis = function(inlines) {      return (this.pos - startpos);    default: -    return result; +    return res;    }    return 0; @@ -382,7 +382,7 @@ var parseEmphasis = function(inlines) {  // Attempt to parse link title (sans quotes), returning the string  // or null if no match.  var parseLinkTitle = function() { -  title = this.match(reLinkTitle); +  var title = this.match(reLinkTitle);    if (title) {      // chop off quotes from title and unescape:      return unescape(title.substr(1, title.length - 2)); @@ -861,7 +861,7 @@ var parseListMarker = function(ln, offset) {    } else {      return null;    } -  blank_item = match[0].length === rest.length; +  var blank_item = match[0].length === rest.length;    if (spaces_after_marker >= 5 ||        spaces_after_marker < 1 ||        blank_item) { @@ -926,7 +926,7 @@ var incorporateLine = function(ln, line_number) {      switch (container.t) {        case 'BlockQuote': -        matched = indent <= 3 && ln[first_nonspace] === '>'; +        var matched = indent <= 3 && ln[first_nonspace] === '>';          if (matched) {            offset = first_nonspace + 1;            if (ln[offset] === ' ') { @@ -1234,7 +1234,7 @@ var finalize = function(block, line_number) {    if (line_number > block.start_line) {      block.end_line = line_number - 1;    } else { -    block_end_line = line_number; +    block.end_line = line_number;    }    switch (block.t) { @@ -1478,9 +1478,10 @@ var renderBlock = function(block, in_tight_list) {      case 'FencedCode':        info_words = block.info.split(/ +/);        attr = info_words.length === 0 || info_words[0].length === 0 ? -                   [] : [['class',this.escape(info_words[0],true)]]; -      return inTags('pre', attr, -              inTags('code', [], this.escape(block.string_content))); +                   [] : [['class','language-' + +                                   this.escape(info_words[0],true)]]; +      return inTags('pre', [], +              inTags('code', attr, this.escape(block.string_content)));      case 'HtmlBlock':        return block.string_content;      case 'ReferenceDef': @@ -1,9 +1,8 @@  #!/usr/bin/env node  var fs = require('fs'); -var util = require('util');  var stmd = require('./stmd'); -var ansi = require('./ansi/ansi') +var ansi = require('./ansi/ansi');  var cursor = ansi(process.stdout);  var writer = new stmd.HtmlRenderer(); @@ -15,19 +14,23 @@ var failed = 0;  var showSpaces = function(s) {    var t = s;    return t.replace(/\t/g,'→') -   .replace(/ /g,'␣'); -} +    .replace(/ /g,'␣'); +};  fs.readFile('spec.txt', 'utf8', function(err, data) {    if (err) {      return console.log(err);    } +  var i;    var examples = [];    var current_section = "";    var example_number = 0; -  tests = data.replace(/^<!-- END TESTS -->(.|[\n])*/m,''); +  var tests = data +    .replace(/\r\n?/g, "\n") // Normalize newlines for platform independence +    .replace(/^<!-- END TESTS -->(.|[\n])*/m, ''); +    tests.replace(/^\.\n([\s\S]*?)^\.\n([\s\S]*?)^\.$|^#{1,6} *(.*)$/gm, -        function(_,x,y,z,w){ +        function(_,x,y,z){            if (z) {              current_section = z;            } else { @@ -45,7 +48,7 @@ fs.readFile('spec.txt', 'utf8', function(err, data) {    for (i = 0; i < examples.length; i++) {      var example = examples[i]; -    if (example.section != current_section) { +    if (example.section !== current_section) {        if (current_section !== '') {          cursor.write('\n');        } @@ -53,7 +56,7 @@ fs.readFile('spec.txt', 'utf8', function(err, data) {        cursor.reset().write(current_section).reset().write('  ');      }      var actual = writer.renderBlock(reader.parse(example.markdown.replace(/→/g, '\t'))); -    if (actual == example.html) { +    if (actual === example.html) {        passed++;        cursor.green().write('✓').reset();      } else { diff --git a/man/man1/stmd.1 b/man/man1/stmd.1 index 913d5a7..6bfdd80 100644 --- a/man/man1/stmd.1 +++ b/man/man1/stmd.1 @@ -10,7 +10,7 @@ stmd [\f[I]options\f[]] [file*]  \f[C]stmd\f[] acts as a pipe, reading from stdin or from the specified  files and writing to stdout.  It converts markdown formatted plain text to HTML, using the conventions -described in the standard markdown spec. +described in the CommonMark spec.  .SH OPTIONS  .TP  .B \f[C]\-\-ast\f[] diff --git a/man/stmd.1.md b/man/stmd.1.md index 6e38afc..3947a79 100644 --- a/man/stmd.1.md +++ b/man/stmd.1.md @@ -17,8 +17,8 @@ stmd [*options*] [file\*]  `stmd` acts as a pipe, reading from stdin or from the specified  files and writing to stdout.  It converts markdown formatted plain -text to HTML, using the conventions described in the standard -markdown spec. +text to HTML, using the conventions described in the CommonMark +spec.  # OPTIONS diff --git a/narrative.md b/narrative.md index 12bf780..315c47b 100644 --- a/narrative.md +++ b/narrative.md @@ -1,8 +1,8 @@  --- -title: Standard markdown +title: CommonMark  ... -Standard markdown is a [specification of markdown +CommonMark is a [specification of markdown  syntax](http://jgm.github.io/stmd/spec.html), together with  BSD3-licensed implementations (`stmd`) in C and javascript. The source  for the spec and the two implementations can be found in [this @@ -1,9 +1,9 @@  --- -title: Standard Markdown Spec +title: CommonMark Spec  author:  - John MacFarlane  version: 1 -date: 2014-07-21 +date: 2014-09-06  ...  # Introduction @@ -203,15 +203,19 @@ to a certain encoding.  Tabs in lines are expanded to spaces, with a tab stop of 4 characters:  . -foo→baz→→bim +→foo→baz→→bim  . -<p>foo baz     bim</p> +<pre><code>foo baz     bim +</code></pre>  .  . -οὐ→χρῆν +    a→a +    ὐ→a  . -<p>οὐ  χρῆν</p> +<pre><code>a   a +ὐ   a +</code></pre>  .  Line endings are replaced by newline characters (LF). @@ -1282,9 +1286,9 @@ bar  .  An [info string](#info-string) can be provided after the opening code fence. -Opening and closing spaces will be stripped, and the first word -is used here to populate the `class` attribute of the enclosing -`pre` tag. +Opening and closing spaces will be stripped, and the first word, prefixed +with `language-`, is used as the value for the `class` attribute of the +`code` element within the enclosing `pre` element.  .  ```ruby @@ -1293,7 +1297,7 @@ def foo(x)  end  ```  . -<pre class="ruby"><code>def foo(x) +<pre><code class="language-ruby">def foo(x)    return 3  end  </code></pre> @@ -1306,7 +1310,7 @@ def foo(x)  end  ~~~~~~~  . -<pre class="ruby"><code>def foo(x) +<pre><code class="language-ruby">def foo(x)    return 3  end  </code></pre> @@ -1316,7 +1320,7 @@ end  ````;  ````  . -<pre class=";"><code></code></pre> +<pre><code class="language-;"></code></pre>  .  Info strings for backtick code blocks cannot contain backticks: @@ -3716,7 +3720,7 @@ blocks](#fenced-code-block):  foo  ```  . -<pre class="foo+bar"><code>foo +<pre><code class="language-foo+bar">foo  </code></pre>  . @@ -3809,7 +3813,7 @@ code blocks, including raw HTML, URLs, [link titles](#link-title), and  foo  ```  . -<pre class="föö"><code>foo +<pre><code class="language-föö">foo  </code></pre>  . @@ -156,15 +156,15 @@ extern int blocks_to_html(block* b, bstring* result, bool tight)      case fenced_code:        escaped = escape_html(b->string_content, false);        cr(html); -      bformata(html, "<pre"); +      bformata(html, "<pre><code");        if (blength(b->attributes.fenced_code_data.info) > 0) {          escaped2 = escape_html(b->attributes.fenced_code_data.info, true);          info_words = bsplit(escaped2, ' '); -        bformata(html, " class=\"%s\"", info_words->entry[0]->data); +        bformata(html, " class=\"language-%s\"", info_words->entry[0]->data);          bdestroy(escaped2);          bstrListDestroy(info_words);        } -      bformata(html, "><code>%s</code></pre>", escaped->data); +      bformata(html, ">%s</code></pre>", escaped->data);        cr(html);        bdestroy(escaped);        break; @@ -22,7 +22,7 @@ int main(int argc, char *argv[]) {    for (i=1; i < argc; i++) {      if (strcmp(argv[i], "--version") == 0) {        printf("stmd %s", VERSION); -      printf(" - standard markdown converter (c) 2014 John MacFarlane\n"); +      printf(" - CommonMark converter (c) 2014 John MacFarlane\n");        exit(0);      } else if ((strcmp(argv[i], "--help") == 0) ||                 (strcmp(argv[i], "-h") == 0)) { | 
