{"id":13520,"library":"md-attr-parser","title":"Markdown Attribute Parser","description":"The `md-attr-parser` package, currently at stable version 1.3.0, provides a focused utility for extracting custom HTML attributes embedded within Markdown strings. It parses attribute blocks, typically enclosed in curly braces `{}` immediately following a Markdown element, to retrieve an ID, a list of classes, and arbitrary key-value pairs. The library outputs a structured object containing the parsed properties and the exact substring that was consumed. While there's no stated release cadence, as a specialized parser, updates are typically driven by bug fixes or syntax extensions rather than frequent iterations. Its key differentiators include the ability to start parsing from a specific offset within a string, and a configurable `defaultValue` option for attributes that are present but lack an explicit value, allowing for flexible integration into Markdown processing pipelines.","status":"active","version":"1.3.0","language":"javascript","source_language":"en","source_url":"https://github.com/arobase-che/md-attr-parser","tags":["javascript","markdown","attribute","plugin"],"install":[{"cmd":"npm install md-attr-parser","lang":"bash","label":"npm"},{"cmd":"yarn add md-attr-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add md-attr-parser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Primary CommonJS export as shown in documentation.","symbol":"parseAttr","correct":"const parseAttr = require('md-attr-parser');"},{"note":"Likely default ESM export due to single main function, though CJS is explicitly documented. Named import might fail.","wrong":"import { parseAttr } from 'md-attr-parser';","symbol":"parseAttr","correct":"import parseAttr from 'md-attr-parser';"}],"quickstart":{"code":"const parseAttr = require('md-attr-parser');\n\n// Example 1: Basic parsing of attributes including id, class, and key-value pairs\nconst result1 = parseAttr('{ width=500px editable=true #unicorn .dangerous .cute }');\nconsole.log('Result 1:', result1);\n/* Expected output:\n{\n  prop: {\n    class: ['dangerous', 'cute'],\n    id: 'unicorn',\n    width: '500px',\n    editable: 'true'\n  },\n  eaten: '{ width=500px editable=true #unicorn .dangerous .cute }'\n}\n*/\n\n// Example 2: Parsing with a starting offset and custom default value for keys without explicit values\nconst textWithPrefix = 'START_HERE{ width=500px editable }';\nconst result2 = parseAttr(textWithPrefix, 'START_HERE'.length, { defaultValue: true });\nconsole.log('Result 2:', result2);\n/* Expected output:\n{\n  prop: {\n    width: '500px',\n    editable: true\n  },\n  eaten: '{ width=500px editable }'\n}\n*/","lang":"javascript","description":"Demonstrates basic parsing of markdown attributes and advanced usage with an offset and custom default values for valueless keys."},"warnings":[{"fix":"If using ESM, try 'import parseAttr from \"md-attr-parser\"' or ensure your build system correctly transpiles CJS modules. For Node.js, consider checking if an 'exports' field is present in package.json or using dynamic import().","message":"The library is primarily designed for CommonJS (CJS) environments, and direct usage with ESM 'import' statements might require specific build configurations or Node.js flags for interoperability.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure attribute strings adhere strictly to the documented syntax. For complex values or those containing special characters, consider pre-processing or post-processing the input/output to avoid conflicts.","message":"The parser expects attributes to follow a specific Markdown syntax (e.g., {#id .class key=value}). Malformed attribute strings or unescaped characters within values may lead to incorrect parsing or unexpected results.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Understand the distinction: 'editable' will use 'defaultValue', while 'editable=\"\"' will result in 'editable: \"\"'. Adjust expectations or pre-process input if specific handling for empty string values is required.","message":"The 'defaultValue' configuration option only applies to keys without explicit values (e.g., '{ editable }'). It does not affect keys with empty string values (e.g., '{ editable=\"\" }').","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.3.0':14 'abil':103 'allow':129 'arbitrari':51 'attr':7 'attribut':2,23,30,120,139 'block':31 'brace':36 'bug':89 'cadenc':79 'class':49 'configur':116 'consum':72 'contain':62 'cur':35 'current':10 'custom':21 'defaultvalu':117 'differenti':100 'driven':87 'element':41 'embed':24 'enclos':33 'exact':68 'explicit':127 'extens':93 'extract':20 'fix':90 'flexibl':131 'focus':17 'follow':38 'frequent':96 'html':22 'id':45 'immedi':37 'includ':101 'integr':132 'iter':97 'javascript':137 'key':53,99 'key-valu':52 'lack':125 'librari':57 'list':47 'markdown':1,26,40,134,138 'md':6 'md-attr-pars':5 'object':61 'offset':110 'option':118 'output':58 'packag':9 'pair':55 'pars':29,64,106 'parser':3,8,83 'pipelin':136 'plugin':140 'present':123 'process':135 'properti':65 'provid':15 'rather':94 'releas':78 'retriev':43 'special':82 'specif':109 'stabl':12 'start':105 'state':77 'string':27,113 'structur':60 'substr':69 'syntax':92 'typic':32,86 'updat':84 'util':18 'valu':54,128 'version':13 'within':25,111","created_at":"2026-04-20T01:54:55.803423+00:00","updated_at":"2026-04-20T01:54:55.803423+00:00","problems":[{"fix":"If in CommonJS, use 'const parseAttr = require(\"md-attr-parser\");'. If in ESM, try 'import parseAttr from \"md-attr-parser\";' as it's likely a default export.","cause":"Attempting to import a CommonJS module using a named ESM import, or incorrect destructuring in a CJS context.","error":"TypeError: parseAttr is not a function"},{"fix":"Verify the input string closely matches the documented syntax: '#id .class key=value'. Ensure no leading/trailing spaces within the attribute block unless intended, and proper quotes for values.","cause":"Input markdown attribute string does not conform to the expected syntax for IDs (#id) or classes (.class), or there are general syntax errors within the attribute block.","error":"Output 'prop' object missing expected attributes (e.g., id or class array is empty)"},{"fix":"Provide the correct character offset for the beginning of the attribute string. For example, 'parseAttr(fullString, fullString.indexOf('{'));' if the attribute block is '{...}' and its position is unknown.","cause":"Incorrect usage of the 'offset' parameter, or no offset provided when the attribute block is not at the beginning of the string.","error":"Parsing starts too early or includes unwanted prefix characters in 'eaten' property."}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/arobase-che/md-attr-parser","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/md-attr-parser","openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}