Skip to content

Commit

Permalink
Adjustments to pattern-matching for comment indentation; replaced Mar…
Browse files Browse the repository at this point in the history
…kdown plugin with marked plugin (enable support for gfm)
  • Loading branch information
winstromming committed Nov 12, 2013
1 parent 3970ec6 commit 4e874dd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sassdown",
"description": "Generates a documentation styleguide from Markdown comments in sass/scss directories using Handlebars",
"version": "0.1.02",
"version": "0.1.03",
"author": {
"name": "Jesper Hills",
"email": "jay@nopr.co",
Expand Down Expand Up @@ -35,7 +35,7 @@
"grunt": "~0.4.0"
},
"dependencies": {
"markdown": "~0.5.0",
"marked": "~0.2.10",
"handlebars": "~1.0.12"
}
}
2 changes: 1 addition & 1 deletion tasks/data/partials/includes.hbs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<link rel="stylesheet" href="/assets/css/screen.css" />
<link rel="stylesheet" href="/test/example/assets/css/screen.css" />
25 changes: 15 additions & 10 deletions tasks/libs/sassdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
var grunt;
var fs = require('fs');
var path = require('path');
var Markdown = require('markdown').markdown;
var markdown = require('marked');
var Handlebars = require('handlebars');

// Quick utility functions
Expand Down Expand Up @@ -162,7 +162,7 @@ exports.files = function (config) {
var page = {};
page._path = path.relative(config.cwd, file.src[0]);
page._src = grunt.file.read(file.src);
page._name = (Markdown.toHTML(unindent(uncomment(page._src))).match('<h1>')) ? Markdown.toHTML(unindent(uncomment(page._src))).split('<h1>')[1].split('</h1>')[0] : null;
page._name = (markdown(unindent(uncomment(page._src))).match('<h1')) ? markdown(unindent(uncomment(page._src))).split('</h1>')[0].split('>')[1] : null;
// Add properties to file and use node path on
// page object for consistent file system resolving
file = exports.metadata(file, page);
Expand Down Expand Up @@ -204,20 +204,25 @@ exports.sections = function (file) {
// indentation
section = uncomment(section);
section = unindent(section);
// If previously four-spaced indents (code blocks) exist
if (section.match(' ')) {
section = section.replace(' ','[html]\n ');
// See if any ```-marked or 4-space indented code blocks exist
if (section.match(/ |```/)) {
// Encapsulate and mark the code block
if(section.match(/```/)) {
section = section.replace(/```/, '[html]\n```');
} else {
section = section.replace(/ /g,' ').replace(/ /, '[html]\n ');
}
// Return our sections object
file.sections[index] = {
id: Math.random().toString(36).substr(2,5),
comment: Markdown.toHTML(section.split('[html]')[0]),
source: Markdown.toHTML(section.split('[html]')[1]),
result: section.split('[html]')[1].replace(/ /g,'').replace(/(\r\n|\n|\r)/gm,'')
comment: markdown(section.split('[html]')[0]),
source: markdown(section.split('[html]\n')[1]),
result: section.split('[html]\n')[1].replace(/ | |```/g, '').replace(/(\r\n|\n|\r)/gm,'')
};
} else {
// Without code, it is just a comment
file.sections[index] = {
comment: Markdown.toHTML(section)
comment: markdown(section)
};
}
});
Expand Down Expand Up @@ -245,7 +250,7 @@ exports.readme = function (config) {
file.original = readme;
file.site = {};
file.sections = [{
comment: Markdown.toHTML(grunt.file.read(readme))
comment: markdown(grunt.file.read(readme))
}];
// Output the file
exports.output(config, file);
Expand Down

1 comment on commit 4e874dd

@winstromming
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes #6

Please sign in to comment.