So hear me out on this one, I'm creating my own jsdoc template and one of the things I'm adding is the ability to have my CHANGELOG be put below the README in the start page. The CHANGELOG file is in a debian format (and must remain so since I have a Cordova project that uses the changelog file in the Ubuntu build).
The generation of the documentation is run using Node.js. Currently I'm using readFileSync to get the contents of the changelog to a string. I can also readFileSync to parse each line separately.
Once the end result string is produced it's run through a markdown parser to turn the string into html.
Here's the problem: I need to identify each new entry's first line and add to the line so that each new entry gets a larger heading. Using just readfilesync I can get the contents parsed properly by markdown but when I start to parse it line by line and insert it for some reason is parsed incorrectly by markdown.
I've tried for a while to get this all to work but I can't seem to make it work like I want, it seems to be getting parsed by markdown into an em entry instead of a list entry.
Below is one of the many variants I've tried without success.
function readChangelogtwo(path) {
var content = '';
fs.readFileSync(path, env.opts.encoding).split('\n').forEach(function (line) {
if (/(?=.*\w)(?=.*^\s)/.test(line)) {
content = content + line + '\n ';
} else {
content = content + '<h4>' + line + '</h4>\n ';
}
});
var parse = markdown.getParser();
return parse(content.toString());
}
Here's a sample CHANGELOG entry:
my.project.name (1.2.3) UNRELEASED; urgency=medium
* Something I did for this release.
-- Simon <email@domain.com> Sat, 11 Apr 2017 10:00:00 +0100
One of the things that I've been trying to use to identify a new entry is the fact that only the new entries have a letter at char 0 of their line. And yes, I've used other versions of the code above that does not involve regex, but as part of one of my attempts I tried it and I figured I'd stick to it since I need to get better at it anyway.
I've tagged this as a regex issue because I'm not very good at regex and while to my knowledge the above is working to identify a new changelog entry I can't guarantee it, so having a regex expert look at it would be nice.
via Simon Hyll
No comments:
Post a Comment