Skip to content

Commit b448484

Browse files
teviostevemartin
authored andcommitted
fix for issue #385 - support foo.md inside _annotations
* read in *.md files ( not recursive ) * clobber annotations and write * satisfies existing tests
1 parent d38101e commit b448484

File tree

4 files changed

+32
-27
lines changed

4 files changed

+32
-27
lines changed

core/lib/annotation_exporter.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict";
22

33
var path = require('path'),
4+
readDir = require('readdir'),
45
fs = require('fs-extra'),
56
JSON5 = require('json5'),
67
_ = require('lodash'),
@@ -42,32 +43,35 @@ var annotations_exporter = function (pl) {
4243
function parseAnnotationsMD() {
4344
var markdown_parser = new mp();
4445
var annotations = [];
45-
46-
//attempt to read the file
47-
var annotationsMD = '';
48-
try {
49-
annotationsMD = fs.readFileSync(path.resolve(paths.source.annotations, 'annotations.md'), 'utf8');
50-
} catch (ex) {
51-
if (pl.config.debug) {
52-
console.log('annotations.md file missing from ' + paths.source.annotations + '. This may be expected.');
46+
var mdFiles = readDir.readSync(paths.source.annotations, ['*.md'])
47+
48+
mdFiles.forEach(function (file) {
49+
var annotationsMD = '';
50+
try {
51+
annotationsMD = fs.readFileSync(path.resolve(paths.source.annotations, file), 'utf8');
52+
} catch (ex) {
53+
if (pl.config.debug) {
54+
console.log('annotations.md file missing from ' + paths.source.annotations + '. This may be expected.');
55+
}
56+
return [];
5357
}
54-
return [];
55-
}
5658

5759
//take the annotation snippets and split them on our custom delimiter
58-
var annotationsYAML = annotationsMD.split('~*~');
60+
var annotationsYAML = annotationsMD.split('~*~');
5961

60-
for (var i = 0; i < annotationsYAML.length; i++) {
61-
var annotation = {};
62+
for (var i = 0; i < annotationsYAML.length; i++) {
63+
var annotation = {};
6264

63-
var markdownObj = markdown_parser.parse(annotationsYAML[i]);
65+
var markdownObj = markdown_parser.parse(annotationsYAML[i]);
6466

65-
annotation.el = markdownObj.el || markdownObj.selector;
66-
annotation.title = markdownObj.title;
67-
annotation.comment = markdownObj.markdown;
67+
annotation.el = markdownObj.el || markdownObj.selector;
68+
annotation.title = markdownObj.title;
69+
annotation.comment = markdownObj.markdown;
6870

69-
annotations.push(annotation);
70-
}
71+
annotations.push(annotation);
72+
}
73+
return false;
74+
})
7175
return annotations;
7276
}
7377

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"grunt": "~1.0.1",
1818
"grunt-contrib-concat": "^1.0.1",
1919
"grunt-contrib-nodeunit": "^1.0.0",
20-
"grunt-eslint": "^18.0.0"
20+
"grunt-eslint": "^18.0.0",
21+
"readdir": "0.0.13"
2122
},
2223
"keywords": [
2324
"Pattern Lab",
@@ -37,7 +38,7 @@
3738
},
3839
"contributors": [
3940
{
40-
"name" : "Geoff Pursell"
41+
"name": "Geoff Pursell"
4142
}
4243
],
4344
"license": "MIT",

test/files/annotations.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,3 @@ selector: .logo
1010
title: Logo
1111
---
1212
The _logo image_ is an SVG file.
13-
~*~
14-
---
15-
el: #nav
16-
title : Navigation
17-
---
18-
Navigation for adaptive web experiences can be tricky. Refer to [these repsonsive patterns](https://bradfrost.github.io/this-is-responsive/patterns.html#navigation) when evaluating solutions.

test/files/nav.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
el: #nav
3+
title : Navigation
4+
---
5+
Navigation for adaptive web experiences can be tricky. Refer to [these repsonsive patterns](https://bradfrost.github.io/this-is-responsive/patterns.html#navigation) when evaluating solutions.
6+

0 commit comments

Comments
 (0)