commonmark / commonmark/commonmark.js
Sourcepos not defined for inline elements
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.6k
- Forks
- 231
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 3
Description
Trying to parse this file with commonmark as follows:
const parser = new commonmark.Parser({ sourcepos: true });
const result = parser.parse(source);
Where source is:
# API name
# Group Users
## User [/users/{id}]
+ Parameters
+ id: 23 (enum[number], optional) - Database ID
Additional description
+ Default: 1
+ Members
+ 37 - Testing value
+ 1
+ 23
### Retrieve User [GET]
+ Response 200 (application/json)
{}
The node with Additional description literal ends up having undefined sourcepos. According to the description, sourcepos property is listed under "The following public properties are defined".
The resulting node is:
Node {
_type: 'text',
_parent:
Node {
_type: 'paragraph',
_parent:
Node {
_type: 'item',
_parent: [Object],
_firstChild: [Object],
_lastChild: [Object],
_prev: null,
_next: null,
_sourcepos: [Array],
_lastLineBlank: true,
_open: false,
_string_content: '',
_literal: null,
_listData: [Object],
_info: null,
_destination: null,
_title: null,
_isFenced: false,
_fenceChar: null,
_fenceLength: 0,
_fenceOffset: null,
_level: null,
_onEnter: null,
_onExit: null },
_firstChild: [Circular],
_lastChild: [Circular],
_prev:
Node {
_type: 'paragraph',
_parent: [Object],
_firstChild: [Object],
_lastChild: [Object],
_prev: null,
_next: [Circular],
_sourcepos: [Array],
_lastLineBlank: true,
_open: false,
_string_content: null,
_literal: null,
_listData: {},
_info: null,
_destination: null,
_title: null,
_isFenced: false,
_fenceChar: null,
_fenceLength: 0,
_fenceOffset: null,
_level: null,
_onEnter: null,
_onExit: null },
_next:
Node {
_type: 'list',
_parent: [Object],
_firstChild: [Object],
_lastChild: [Object],
_prev: [Circular],
_next: null,
_sourcepos: [Array],
_lastLineBlank: true,
_open: false,
_string_content: '',
_literal: null,
_listData: [Object],
_info: null,
_destination: null,
_title: null,
_isFenced: false,
_fenceChar: null,
_fenceLength: 0,
_fenceOffset: null,
_level: null,
_onEnter: null,
_onExit: null },
_sourcepos: [ [Array], [Array] ],
_lastLineBlank: true,
_open: false,
_string_content: null,
_literal: null,
_listData: {},
_info: null,
_destination: null,
_title: null,
_isFenced: false,
_fenceChar: null,
_fenceLength: 0,
_fenceOffset: null,
_level: null,
_onEnter: null,
_onExit: null },
_firstChild: null,
_lastChild: null,
_prev: null,
_next: null,
_sourcepos: undefined,
_lastLineBlank: false,
_open: true,
_string_content: null,
_literal: 'Additional description',
_listData: {},
_info: null,
_destination: null,
_title: null,
_isFenced: false,
_fenceChar: null,
_fenceLength: 0,
_fenceOffset: null,
_level: null,
_onEnter: null,
_onExit: null }
Expected: node.sourcepos contains an array
Actual: node.sourcepos is undefined
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the provided parser example with sourcepos enabled and inspect how the inline text node for “Additional description” is created. Trace the sourcepos handling for that node and add a regression test; done means node.sourcepos is an array containing the expected position.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100