Skip to content

Commit

Permalink
promote posattrs mapping to constant
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed Feb 24, 2024
1 parent b4d312e commit 7ecc6e1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions grammar/asciidoc-block.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const { parse: parseAttrlist } = require('#attrlist-parser')
const ADMONITION_STYLES = { CAUTION: 'caution', IMPORTANT: 'important', NOTE: 'note', TIP: 'tip', WARNING: 'warning' }
const MAX_ADMONITION_STYLE_LENGTH = Object.keys(ADMONITION_STYLES).reduce((max, it) => it.length > max ? it.length : max, 0)
const MIN_ADMONITION_STYLE_LENGTH = Object.keys(ADMONITION_STYLES).reduce((min, it) => it.length < min ? it.length : min, Infinity)
const POSATTRS = {
image: ['alt', 'width', 'height'],
source: [, 'language'],
}
}}
{
const { attributes: initialDocumentAttributes = {}, locations } = options
Expand Down Expand Up @@ -359,11 +363,11 @@ listing = (openingDelim:listing_delimiter_line { enterBlock(context, openingDeli
let metadata = getBlockMetadata()
const style = metadata?.attributes.style
if (style === 'source') {
processBlockMetadata(metadata, [, 'language'])
processBlockMetadata(metadata, POSATTRS.source)
let language = metadata.attributes.language
if (!language && (language = documentAttributes['source-language']?.value)) metadata.attributes.language = language
} else {
processBlockMetadata(metadata, style ? undefined : [, 'language'])
processBlockMetadata(metadata, style ? undefined : POSATTRS.source)
const language = !style && (metadata?.attributes.language || documentAttributes['source-language']?.value)
if (language) Object.assign((metadata ??= { attributes: {}, options: [], roles: [] }).attributes, { style: 'source', language })
}
Expand All @@ -387,7 +391,7 @@ literal = (openingDelim:literal_delimiter_line { enterBlock(context, openingDeli
const metadata = getBlockMetadata()
const style = metadata?.attributes.style
if (style === 'source') {
processBlockMetadata(metadata, [, 'language'])
processBlockMetadata(metadata, POSATTRS.source)
let language = metadata.attributes.language
if (!language && (language = documentAttributes['source-language']?.value)) metadata.attributes.language = language
} else {
Expand Down Expand Up @@ -544,7 +548,7 @@ image = 'i' 'mage::' !space target:$(!(lf / '[') .)+ '[' attrlistOffset:offset a
{
let metadata
if (attrlist) parseAttrlist(attrlist, { attributes: documentAttributes, initial: (metadata = getBlockMetadata(undefined, true)).attributes, inlineParser: { parse: parseInline }, locations: { 1: toSourceLocation(getLocation({ start: attrlistOffset, text: attrlist }))[0] } })
metadata = processBlockMetadata(metadata, ['alt', 'width', 'height'])
metadata = processBlockMetadata(metadata, POSATTRS.image)
target = inlinePreprocessor(target, { attributes: documentAttributes, mode: 'attributes', sourceMapping: false }).input
return applyBlockMetadata({ name: 'image', type: 'block', form: 'macro', target, location: toSourceLocation(getLocation()) }, metadata)
}
Expand Down

0 comments on commit 7ecc6e1

Please sign in to comment.