Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

Commit

Permalink
Fix regex for code and whitelist the annotations.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel O'Connor committed Nov 30, 2015
1 parent 6711b1e commit c0d1c08
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
13 changes: 10 additions & 3 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ var removeInitialSlashes = function(str) {
return str;
};

/**
* Check to see if an annotation is valid.
*/
var isValidAnnotation = function(line) {
return line.match(/^@(?:name|description|group|example)/);
}

/**
* Turn an array of AST nodes into JSON.
*/
Expand Down Expand Up @@ -113,8 +120,8 @@ var parseCommentNodes = function(nodes) {
var parseExampleAnnotation = function(value) {
var obj = {};

// http://rubular.com/r/GvvRdqa556
var re = /(?:\[(.*)\])?\s?(.*?)\n(.*)/m;
// http://rubular.com/r/dc1UWZGEJ3
var re = /(?:\[(.*)\])?[ \t]?(.*?)\n(.*)/m;
var result = re.exec(value);

obj['language'] = result[1] || null;
Expand Down Expand Up @@ -143,7 +150,7 @@ var parseCommentLines = function(lines, start, end) {
lines.map(function(lineObj) {
var annotation = null;

if (lineObj.content.match('^@')) {
if (isValidAnnotation(lineObj.content)) {
// New annotation is starting
annotation = parseAnnotationLabel(lineObj['content']);
obj[annotation[0]] = annotation[1];
Expand Down
29 changes: 14 additions & 15 deletions test/test.scss
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
////
/// Core
/// @description Root file compiling only Core CSS.
/// @group Main
/// Prefixer
/// @description A mixin for generating vendor prefixes on non-standardized
/// properties.
/// @example[scss]
/// .element {
/// @include prefixer(border-radius, 10px, webkit ms spec);
/// }
/// @group Polyfills & Mixins
////

/// Colors
/// @example[html] Description
/// Code Sample
$base-black : #000;
$base-white : #FFF;

/// ---

/// ROOT COLOR
$root-color: (
grey-85 : tint($base-black, 15%),
);
/// Charset
/// @example[scss]
/// .element {
/// @include prefixer(border-radius, 10px, webkit ms spec);
/// }
@charset 'UTF-8';

0 comments on commit c0d1c08

Please sign in to comment.