@antora/asciidoc-loader
Advanced tools
Comparing version 2.0.0-rc.2 to 2.0.0-rc.3
@@ -5,6 +5,7 @@ 'use strict' | ||
const CIRCUMFIX_COMMENT_SUFFIX_RX = / (?:\*[/)]|--%?>)$/ | ||
const DBL_COLON = '::' | ||
const DBL_SQUARE = '[]' | ||
const NEWLINE_RX = /\r\n?|\n/ | ||
const TAG_DELIMITER_RX = /[,;]/ | ||
const TAG_DIRECTIVE_RX = /\b(?:tag|(end))::(\S+)\[\]$/ | ||
const TAG_DIRECTIVE_RX = /\b(?:tag|(e)nd)::(\S+?)\[\](?=$|[ \r])/m | ||
@@ -27,8 +28,19 @@ const IncludeProcessor = (() => { | ||
Opal.defn(scope, '$process', function (doc, reader, target, attrs) { | ||
const resolvedFile = this[$callback](doc, target, doc.getReader().getCursor()) | ||
if (reader.include_stack.length >= Opal.hash_get(reader.maxdepth, 'abs')) { | ||
if (Opal.hash_get(reader.maxdepth, 'abs')) { | ||
log('error', `maximum include depth of ${Opal.hash_get(reader.maxdepth, 'rel')} exceeded`, reader) | ||
} | ||
return | ||
} | ||
const resolvedFile = this[$callback](doc, target, reader.getCursor()) | ||
if (resolvedFile) { | ||
let includeContents = resolvedFile.contents | ||
let startLineNum = 1 | ||
const tags = getTags(attrs) | ||
if (tags) [includeContents, startLineNum] = applyTagFiltering(includeContents, tags) | ||
let includeContents | ||
let tags | ||
let startLineNum | ||
if ((tags = getTags(attrs))) { | ||
;[includeContents, startLineNum] = applyTagFiltering(reader, target, resolvedFile, tags) | ||
} else { | ||
includeContents = resolvedFile.contents | ||
startLineNum = 1 | ||
} | ||
Opal.hash_put(attrs, 'partial-option', true) | ||
@@ -56,3 +68,3 @@ reader.pushInclude(includeContents, resolvedFile.file, resolvedFile.path, startLineNum, attrs) | ||
let any = false | ||
tags.split(TAG_DELIMITER_RX).forEach((tag) => { | ||
tags.split(~tags.indexOf(',') ? ',' : ';').forEach((tag) => { | ||
if (tag && tag !== '!') { | ||
@@ -68,3 +80,3 @@ any = true | ||
function applyTagFiltering (contents, tags) { | ||
function applyTagFiltering (reader, target, file, tags) { | ||
let selecting, selectingDefault, wildcard | ||
@@ -90,17 +102,11 @@ if (tags.has('**')) { | ||
const tagStack = [] | ||
const usedTags = [] | ||
const foundTags = [] | ||
let activeTag | ||
let lineNum = 0 | ||
let startLineNum | ||
contents.split(NEWLINE_RX).forEach((line) => { | ||
file.contents.split(NEWLINE_RX).forEach((line) => { | ||
lineNum++ | ||
let m | ||
let l = line | ||
if ( | ||
(l.endsWith('[]') || | ||
(~l.indexOf('[] ') && | ||
(m = l.match(CIRCUMFIX_COMMENT_SUFFIX_RX)) && | ||
(l = l.substr(0, m.index)).endsWith('[]'))) && | ||
(m = l.match(TAG_DIRECTIVE_RX)) | ||
) { | ||
if (~l.indexOf(DBL_COLON) && ~l.indexOf(DBL_SQUARE) && (m = l.match(TAG_DIRECTIVE_RX))) { | ||
const thisTag = m[2] | ||
@@ -115,14 +121,24 @@ if (m[1]) { | ||
tagStack.splice(idx, 1) | ||
//console.warn(`line ${lineNum}: mismatched end tag in include: expected ${activeTag}, found ${thisTag}`) | ||
log( | ||
'warn', | ||
`mismatched end tag (expected '${activeTag}' but found '${thisTag}') ` + | ||
`at line ${lineNum} of include file: ${file.file})`, | ||
reader, | ||
reader.$create_include_cursor(file.file, target, lineNum) | ||
) | ||
} else { | ||
log( | ||
'warn', | ||
`unexpected end tag '${thisTag}' at line ${lineNum} of include file: ${file.file}`, | ||
reader, | ||
reader.$create_include_cursor(file.file, target, lineNum) | ||
) | ||
} | ||
//} else { | ||
// //console.warn(`line ${lineNum}: unexpected end tag in include: ${thisTag}`) | ||
//} | ||
} | ||
} else if (tags.has(thisTag)) { | ||
usedTags.push(thisTag) | ||
tagStack.unshift([(activeTag = thisTag), (selecting = tags.get(thisTag))]) | ||
foundTags.push(thisTag) | ||
tagStack.unshift([(activeTag = thisTag), (selecting = tags.get(thisTag)), lineNum]) | ||
} else if (wildcard !== undefined) { | ||
selecting = activeTag && !selecting ? false : wildcard | ||
tagStack.unshift([(activeTag = thisTag), selecting]) | ||
tagStack.unshift([(activeTag = thisTag), selecting, lineNum]) | ||
} | ||
@@ -134,10 +150,31 @@ } else if (selecting) { | ||
}) | ||
// Q: use _.difference(Object.keys(tags), usedTags)? | ||
//const missingTags = Object.keys(tags).filter((e) => !usedTags.includes(e)) | ||
//if (missingTags.length) { | ||
// console.warn(`tag${missingTags.length > 1 ? 's' : ''} '${missingTags.join(',')}' not found in include`) | ||
//} | ||
if (tagStack.length) { | ||
tagStack.forEach(([tagName, _, tagLineNum]) => | ||
log( | ||
'warn', | ||
`detected unclosed tag '${tagName}' starting at line ${tagLineNum} of include file: ${file.file}`, | ||
reader, | ||
reader.$create_include_cursor(file.file, target, tagLineNum) | ||
) | ||
) | ||
} | ||
if (foundTags.length) foundTags.forEach((name) => tags.delete(name)) | ||
if (tags.size) { | ||
const missingTagNames = Array.from(tags.keys()) | ||
log( | ||
'warn', | ||
`tag${tags.size > 1 ? 's' : ''} '${missingTagNames.join(', ')}' not found in include file: ${file.file}`, | ||
reader | ||
) | ||
} | ||
return [lines, startLineNum || 1] | ||
} | ||
function log (severity, message, reader, includeCursor = undefined) { | ||
const opts = includeCursor | ||
? { source_location: reader.getCursor(), include_location: includeCursor } | ||
: { source_location: reader.getCursor() } | ||
reader.$logger()['$' + severity](reader.$message_with_context(message, Opal.hash(opts))) | ||
} | ||
module.exports = IncludeProcessor |
@@ -57,3 +57,3 @@ 'use strict' | ||
} | ||
const pageAttrs = fileSrc.family === 'page' ? computePageAttrs(fileSrc, contentCatalog) : {} | ||
const pageAttrs = fileSrc.family === 'page' ? computePageAttrs(fileSrc, contentCatalog) : undefined | ||
const attributes = Object.assign({}, config.attributes, intrinsicAttrs, pageAttrs) | ||
@@ -71,8 +71,5 @@ const relativizePageRefs = config.relativizePageRefs !== false | ||
} | ||
const doc = asciidoctor.load(file.contents.toString(), { | ||
attributes, | ||
converter, | ||
extension_registry: extensionRegistry, | ||
safe: 'safe', | ||
}) | ||
const opts = { attributes, converter, extension_registry: extensionRegistry, safe: 'safe' } | ||
if (config.doctype) opts.doctype = config.doctype | ||
const doc = asciidoctor.load(file.contents.toString(), opts) | ||
if (extensions.length) freeExtensions() | ||
@@ -79,0 +76,0 @@ return doc |
{ | ||
"name": "@antora/asciidoc-loader", | ||
"version": "2.0.0-rc.2", | ||
"version": "2.0.0-rc.3", | ||
"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
26641
594