@antora/asciidoc-loader
Advanced tools
Comparing version 2.1.2 to 2.2.0
@@ -32,6 +32,9 @@ 'use strict' | ||
let includeContents | ||
let linenums | ||
let tags | ||
let startLineNum | ||
if ((tags = getTags(attrs))) { | ||
;[includeContents, startLineNum] = applyTagFiltering(reader, target, resolvedFile, tags) | ||
if ((linenums = getLines(attrs))) { | ||
;[includeContents, startLineNum] = filterLinesByLineNumbers(reader, target, resolvedFile, linenums) | ||
} else if ((tags = getTags(attrs))) { | ||
;[includeContents, startLineNum] = filterLinesByTags(reader, target, resolvedFile, tags) | ||
} else { | ||
@@ -53,2 +56,34 @@ includeContents = resolvedFile.contents | ||
function getLines (attrs) { | ||
if (attrs['$key?']('lines')) { | ||
const lines = attrs['$[]']('lines') | ||
if (lines) { | ||
const linenums = [] | ||
let filtered | ||
;(~lines.indexOf(',') ? lines.split(',') : lines.split(';')) | ||
.filter((it) => it) | ||
.forEach((linedef) => { | ||
filtered = true | ||
let delim | ||
let from | ||
if (~(delim = linedef.indexOf('..'))) { | ||
from = linedef.substr(0, delim) | ||
let to = linedef.substr(delim + 2) | ||
if ((to = parseInt(to) || -1) > 0) { | ||
if ((from = parseInt(from) || -1) > 0) { | ||
linenums.push(...Array.from({ length: to - from + 1 }, (_, i) => i + from)) | ||
} | ||
} else if (to === -1 && (from = parseInt(from) || -1) > 0) { | ||
linenums.push(from, Infinity) | ||
} | ||
} else if ((from = parseInt(linedef) || -1) > 0) { | ||
linenums.push(from) | ||
} | ||
}) | ||
if (linenums.length) return [...new Set(linenums.sort((a, b) => a - b))] | ||
if (filtered) return [] | ||
} | ||
} | ||
} | ||
function getTags (attrs) { | ||
@@ -76,3 +111,25 @@ if (attrs['$key?']('tag')) { | ||
function applyTagFiltering (reader, target, file, tags) { | ||
function filterLinesByLineNumbers (reader, target, file, linenums) { | ||
let lineNum = 0 | ||
let startLineNum | ||
let selectRest | ||
const lines = [] | ||
file.contents.split(NEWLINE_RX).some((line) => { | ||
lineNum++ | ||
if (selectRest || (selectRest = linenums[0] === Infinity)) { | ||
if (!startLineNum) startLineNum = lineNum | ||
lines.push(line) | ||
} else { | ||
if (linenums[0] === lineNum) { | ||
if (!startLineNum) startLineNum = lineNum | ||
linenums.shift() | ||
lines.push(line) | ||
} | ||
if (!linenums.length) return true | ||
} | ||
}) | ||
return [lines, startLineNum || 1] | ||
} | ||
function filterLinesByTags (reader, target, file, tags) { | ||
let selecting, selectingDefault, wildcard | ||
@@ -79,0 +136,0 @@ if (tags.has('**')) { |
@@ -58,4 +58,4 @@ 'use strict' | ||
} | ||
const pageAttrs = computePageAttrs(fileSrc, contentCatalog) | ||
const attributes = Object.assign({}, config.attributes, intrinsicAttrs, pageAttrs) | ||
const attributes = fileSrc.family === 'page' ? { 'page-partial': '@' } : {} | ||
Object.assign(attributes, config.attributes, intrinsicAttrs, computePageAttrs(fileSrc, contentCatalog)) | ||
const relativizePageRefs = config.relativizePageRefs !== false | ||
@@ -62,0 +62,0 @@ const converter = createConverter({ |
{ | ||
"name": "@antora/asciidoc-loader", | ||
"version": "2.1.2", | ||
"version": "2.2.0", | ||
"description": "Loads AsciiDoc content into an Asciidoctor Document object (AST) for use in an Antora documentation pipeline.", | ||
@@ -5,0 +5,0 @@ "license": "MPL-2.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30808
676