New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

asciidoc-loader

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asciidoc-loader - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

36

index.js

@@ -0,1 +1,3 @@

var loaderUtils = require('loader-utils');
// Works similarly to html-loader to cause React to pack adoc includes into the distribution

@@ -5,13 +7,37 @@ // and replacing the include link with the packed file.

module.exports = function(content) {
return "module.exports = " + JSON.stringify(content)
var params = loaderUtils.getOptions(this) || {};
var contentAffectedByIncludeParameters = content;
var leveloffset = eval(params['leveloffset'] || 0);
if (leveloffset !== 0) {
contentAffectedByIncludeParameters = content.split('\n').map(function (line) {
return line.replace(/^(=+)/g, function (_, offset) {
return leveloffset > 0 ?
offset + ''.padStart(leveloffset, '=') :
offset.substring(-1 * offset);
});
}).join('\n');
}
return 'module.exports = ' + JSON.stringify(contentAffectedByIncludeParameters)
.split('\\n')
.map(function(line) {
.map(function (line) {
return line.replace(/(image|include)::([^.]+).([^\[]+)\[(.*)\]/g,
function (_, type, name, ext, importProps) {
var loader = type === 'image' ? 'file-loader' : 'asciidoc-loader';
return type + '::' + '" + require("!' + loader + '!./' + name + '.' + ext + '") + "[' +
importProps + ']';
})
// combine the level offset coming to us from the parent adoc with the level offset specified on this include (if any)
var childLeveloffset = leveloffset + eval(loaderUtils.parseQuery('?' + importProps.replace(/,/g, '&'))['leveloffset'] || 0);
var query = type === 'include' ?
(childLeveloffset === 0 ? '' : '?leveloffset=' + (childLeveloffset > 0 ? '+' + childLeveloffset : childLeveloffset)) :
'';
var require = '" + require("!' + loader + query + '!./' + name + '.' + ext + '") + "';
return type === 'image' ?
'image::' + require + '[' + importProps + ']' :
require;
});
})
.join('\\n');
};

5

package.json
{
"name": "asciidoc-loader",
"version": "0.1.0",
"version": "0.2.0",
"description": "Compiles asciidoc with asciidoctor.js",

@@ -12,3 +12,4 @@ "author": "Jon Schneider @jkschneider",

"dependencies": {
"file-loader": "^0.11.2"
"file-loader": "^0.11.2",
"loader-utils": "^1.1.0"
},

@@ -15,0 +16,0 @@ "devDependencies": {

@@ -7,2 +7,6 @@ # asciidoc-loader

Currently, the `lineoffset` parameter of the include directive is supported, but
lines, tag, and indent are not. All parameters of the image directive are passed
through to asciidoctor unchanged.
```javascript

@@ -9,0 +13,0 @@ import index from '!asciidoc-loader!../../docs/index.adoc';

@@ -8,7 +8,7 @@ var should = require("should");

"include::part1.adoc[leveloffset=+1]\n" +
"include::part2.adoc[leveloffset=+1]\n" +
"include::part2.adoc[indent=+1]\n" +
"image::sunset.jpg[Sunset,300,200]\n" +
"image::img/sunrise.jpg[]\n");
loaded.should.containEql('require("!asciidoc-loader!./part1.adoc")');
loaded.should.containEql('require("!asciidoc-loader?leveloffset=+1!./part1.adoc")');
loaded.should.containEql('require("!asciidoc-loader!./part2.adoc")');

@@ -18,1 +18,11 @@ loaded.should.containEql('require("!file-loader!./sunset.jpg")');

});
it('supports positive line offset', function() {
var loaded = loader.bind({query: '?leveloffset=+1'})('Some text\n= My Doc');
loaded.should.containEql('== My Doc');
});
it('supports negative line offset', function() {
var loaded = loader.bind({query: '?leveloffset=-1'})('Some text\n== My Doc');
loaded.should.containEql('= My Doc');
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc