blob: df79ddbf3d51e12844ce15609a6d45b855b45ae7 [file] [log] [blame]
import loaderUtils from 'loader-utils'
import {
extractBlocks
} from './parser'
module.exports = function (source) {
this.cacheable && this.cacheable()
const callback = this.async()
const loaderQuery = loaderUtils.parseQuery(this.query)
const type = loaderQuery.type
let index = loaderQuery.index
if (index != null && index.match(/^\d+$/)) {
index = parseInt(index)
}
extractBlocks(source, type)
.then(result => {
if (index != null) {
result = result[index]
}
return result.content
}).then(content => {
callback(null, content)
}).catch(e => {
callback(e, '')
})
}