@@ -13,12 +13,18 @@ import { closeTables } from './table.ts'
1313 * @param options - `frontmatter` completes an unclosed leading frontmatter block.
1414 * `syntax: false` disables Comark component-fence handling (`::` closers and
1515 * props braces), for input parsed without the components plugin.
16+ * `attributes: true` still treats `{...}` as an attribute scope (so `_` / `*`
17+ * inside values are not closed) without enabling component fences.
1618 * @returns The markdown with unclosed syntax closed
1719 */
18- export function autoCloseMarkdown ( markdown : string , options : { frontmatter ?: boolean ; syntax ?: boolean } = { } ) : string {
20+ export function autoCloseMarkdown (
21+ markdown : string ,
22+ options : { frontmatter ?: boolean ; syntax ?: boolean ; attributes ?: boolean } = { }
23+ ) : string {
1924 if ( ! markdown || markdown === '' ) return markdown
2025
2126 const syntaxEnabled = options . syntax !== false
27+ const attributesEnabled = options . attributes ?? syntaxEnabled
2228
2329 const lines = markdown . split ( '\n' )
2430 const n = lines . length
@@ -152,7 +158,7 @@ export function autoCloseMarkdown(markdown: string, options: { frontmatter?: boo
152158 // Fix inline markers on last line (skip inside block-level structures)
153159 const lastIdx = n - 1
154160 if ( ! inFrontmatter && ! inBlockMath && lines [ lastIdx ] . trim ( ) !== '$$' ) {
155- lines [ lastIdx ] = closeInlineMarkersLinear ( lines [ lastIdx ] , syntaxEnabled )
161+ lines [ lastIdx ] = closeInlineMarkersLinear ( lines [ lastIdx ] , attributesEnabled )
156162 }
157163
158164 let result = lines . join ( '\n' )
@@ -256,9 +262,9 @@ function scanDelimiterRun(line: string, start: number, marker: string) {
256262 * Closes inline markers (*, **, ***, ~~, `, $, $$, [, () on the last line
257263 * without using regex - pure character scanning in O(n) time
258264 *
259- * With `syntax ` false, `{...}` is literal text instead of an attribute scope.
265+ * With `attributesEnabled ` false, `{...}` is literal text instead of an attribute scope.
260266 */
261- function closeInlineMarkersLinear ( line : string , syntax : boolean ) : string {
267+ function closeInlineMarkersLinear ( line : string , attributesEnabled : boolean ) : string {
262268 const len = line . length
263269 if ( len === 0 ) return line
264270
@@ -318,11 +324,11 @@ function closeInlineMarkersLinear(line: string, syntax: boolean): string {
318324 continue
319325 }
320326
321- if ( syntax && ch === '{' && prevCh !== ' ' ) {
327+ if ( attributesEnabled && ch === '{' && prevCh !== ' ' ) {
322328 inAttributes ++
323329 continue
324330 }
325- if ( syntax && ch === '}' ) {
331+ if ( attributesEnabled && ch === '}' ) {
326332 if ( inAttributes > 0 ) inAttributes --
327333 continue
328334 }
0 commit comments