mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
[CS2] Fix handling of tabbed code blocks in .litcoffee files (#4485)
* Add tabbed literate test; modernize Markdown title heading * Better parsing of Literate CoffeeScript files, including now correct parsing of tabbed .litcoffee files; and more accurate stack traces (assuming you don’t do your own word wrapping within list items) * Swap Marked for MarkdownIt for parsing the Markdown of Literate CoffeeScript files; use MarkdownIt’s `map` property to preserve correct line numbers * Literate CoffeeScript tests: remove trailing whitespace, fix spelling * Literate CoffeeScript tests: add block quote test * Literate CoffeeScript (tabbed, at least) seems to need a consistent starting indentation * Restore test * Reference links work now in MarkdownIt * Breaking change in Literate CoffeeScript: code blocks within HTML tags must be unindented * Breaking change in Literate CoffeeScript: code blocks within lists need a blank line separating them from the list item text
This commit is contained in:
parent
57c0b16eeb
commit
5e1d978946
5 changed files with 227 additions and 93 deletions
|
@ -1,8 +1,8 @@
|
|||
// Generated by CoffeeScript 2.0.0-alpha1
|
||||
(function() {
|
||||
var buildLocationData, extend, flatten, marked, ref, repeat, syntaxErrorToString;
|
||||
var buildLocationData, extend, flatten, md, ref, repeat, syntaxErrorToString;
|
||||
|
||||
marked = require('marked');
|
||||
md = require('markdown-it')();
|
||||
|
||||
exports.starts = function(string, literal, start) {
|
||||
return literal === string.substr(start, literal.length);
|
||||
|
@ -28,10 +28,10 @@
|
|||
};
|
||||
|
||||
exports.compact = function(array) {
|
||||
var i, item, len1, results;
|
||||
var item, j, len1, results;
|
||||
results = [];
|
||||
for (i = 0, len1 = array.length; i < len1; i++) {
|
||||
item = array[i];
|
||||
for (j = 0, len1 = array.length; j < len1; j++) {
|
||||
item = array[j];
|
||||
if (item) {
|
||||
results.push(item);
|
||||
}
|
||||
|
@ -65,10 +65,10 @@
|
|||
};
|
||||
|
||||
exports.flatten = flatten = function(array) {
|
||||
var element, flattened, i, len1;
|
||||
var element, flattened, j, len1;
|
||||
flattened = [];
|
||||
for (i = 0, len1 = array.length; i < len1; i++) {
|
||||
element = array[i];
|
||||
for (j = 0, len1 = array.length; j < len1; j++) {
|
||||
element = array[j];
|
||||
if ('[object Array]' === Object.prototype.toString.call(element)) {
|
||||
flattened = flattened.concat(flatten(element));
|
||||
} else {
|
||||
|
@ -86,10 +86,10 @@
|
|||
};
|
||||
|
||||
exports.some = (ref = Array.prototype.some) != null ? ref : function(fn) {
|
||||
var e, i, len1, ref1;
|
||||
var e, j, len1, ref1;
|
||||
ref1 = this;
|
||||
for (i = 0, len1 = ref1.length; i < len1; i++) {
|
||||
e = ref1[i];
|
||||
for (j = 0, len1 = ref1.length; j < len1; j++) {
|
||||
e = ref1[j];
|
||||
if (fn(e)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -98,24 +98,23 @@
|
|||
};
|
||||
|
||||
exports.invertLiterate = function(code) {
|
||||
var generateRandomToken, i, item, len1, out, ref1, token;
|
||||
generateRandomToken = function() {
|
||||
return `${Math.random() * Date.now()}`;
|
||||
};
|
||||
while (token === void 0 || code.indexOf(token) !== -1) {
|
||||
token = generateRandomToken();
|
||||
}
|
||||
code = code.replace("\t", token);
|
||||
out = "";
|
||||
ref1 = marked.lexer(code, {});
|
||||
for (i = 0, len1 = ref1.length; i < len1; i++) {
|
||||
item = ref1[i];
|
||||
if (item.type === 'code') {
|
||||
out += `${item.text}\n`;
|
||||
var out;
|
||||
out = [];
|
||||
md.renderer.rules = {
|
||||
code_block: function(tokens, idx) {
|
||||
var i, j, len1, line, lines, results, startLine;
|
||||
startLine = tokens[idx].map[0];
|
||||
lines = tokens[idx].content.split('\n');
|
||||
results = [];
|
||||
for (i = j = 0, len1 = lines.length; j < len1; i = ++j) {
|
||||
line = lines[i];
|
||||
results.push(out[startLine + i] = line);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
||||
out.replace(token, "\t");
|
||||
return out;
|
||||
};
|
||||
md.render(code);
|
||||
return out.join('\n');
|
||||
};
|
||||
|
||||
buildLocationData = function(first, last) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue