Skip to content
This repository has been archived by the owner on Feb 5, 2020. It is now read-only.

Commit

Permalink
added asciidoc
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorah committed Jan 26, 2015
1 parent dad4df4 commit 3239dc1
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
29 changes: 29 additions & 0 deletions lib/asciidoc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* jshint node:true */
"use strict";

function badger(content, imgUrl, linkUrl, altText) {
var lines = content.split('\n');
var idealLine = findIdealLineForInsert(lines);
var badgeContent = '\nimage:' + imgUrl + '[link="' + linkUrl + '"]';

lines.splice(idealLine, 0, badgeContent);

return lines.join('\n');
}

function findIdealLineForInsert(lines) {
var i = 0;
var seenHeader = false;

for(;i < lines.length;i++) {
if(/^\s*(\=+|={3,}|-{3,})/.test(lines[i])) {
seenHeader = true;
} else {
if(seenHeader) break;
}
}

return i;
}

module.exports = badger;
7 changes: 6 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var orgmodeBadger = require('./orgmode');
var creoleBadger = require('./creole');
var mediawikiBadger = require('./mediawiki');
var rstBadger = require('./rst');
var asciidocBadger = require('./asciidoc');
var plaintextBadger = require('./plaintext');
var assert = require('assert');

Expand All @@ -28,7 +29,11 @@ var markupBadgers = {
mediawiki: mediawikiBadger,
wiki: mediawikiBadger,

rst: rstBadger
rst: rstBadger,

asciidoc: asciidocBadger,
adoc: asciidocBadger,
asc: asciidocBadger
};

var addBadge = function(content, fileExt, imageUrl, linkUrl, altText) {
Expand Down
9 changes: 9 additions & 0 deletions test/examples/asciidoc-after.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
My Amazing Library
==================

image:https://badges.gitter.im/Join%20Chat.svg[link="https://gitter.im/myorg/myrepo?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"]

Features
--------

It does amazing things!
7 changes: 7 additions & 0 deletions test/examples/asciidoc-before.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
My Amazing Library
==================

Features
--------

It does amazing things!
9 changes: 9 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ describe('readme-badger', function() {
assert.equal(result, after);
});

it('inserts into asciidoc', function() {
var before = fs.readFileSync(__dirname + '/examples/asciidoc-before.asciidoc', { encoding: 'utf8' });
var after = fs.readFileSync(__dirname + '/examples/asciidoc-after.asciidoc', { encoding: 'utf8' });

var result = badger.addBadge(before, 'asciidoc', imageUrl, linkUrl, altText);

assert.equal(result, after);
});

it('inserts into unsupported filetypes', function() {
var before = fs.readFileSync(__dirname + '/examples/plaintext-before.txt', { encoding: 'utf8' });
var after = fs.readFileSync(__dirname + '/examples/plaintext-after.txt', { encoding: 'utf8' });
Expand Down

0 comments on commit 3239dc1

Please sign in to comment.