Skip to content

Commit

Permalink
fix(to-markdown): link reference attributes
Browse files Browse the repository at this point in the history
resolves #77
  • Loading branch information
farnabaz committed Nov 18, 2024
1 parent f0f168c commit 1ac6c7e
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/to-markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ export default (opts: RemarkMDCOptions = {}) => {
link: (node: Parents, _: any, state: State, info: Info) => {
return defaultHandlers.link(node as any, _, state, info) + attributes(node, state)
},
linkReference: (node: Parents, _: any, state: State, info: Info) => {
return defaultHandlers.linkReference(node as any, _, state, info) + attributes(node, state)
},
strong: (node: Parents, _: any, state: State, info: Info) => {
return defaultHandlers.strong(node as any, _, state, info) + attributes(node, state)
},
Expand Down
96 changes: 96 additions & 0 deletions test/__snapshots__/attributes.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,102 @@ exports[`Attributes > link 1`] = `
}
`;

exports[`Attributes > linkReference 1`] = `
{
"children": [
{
"children": [
{
"attributes": {
"class": "class",
"id": "id",
},
"children": [
{
"position": {
"end": {
"column": 6,
"line": 1,
"offset": 5,
},
"start": {
"column": 2,
"line": 1,
"offset": 1,
},
},
"type": "text",
"value": "Nuxt",
},
],
"identifier": "nuxt",
"label": "nuxt",
"position": {
"end": {
"column": 13,
"line": 1,
"offset": 12,
},
"start": {
"column": 1,
"line": 1,
"offset": 0,
},
},
"referenceType": "full",
"type": "linkReference",
},
],
"position": {
"end": {
"column": 25,
"line": 1,
"offset": 24,
},
"start": {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "paragraph",
},
{
"identifier": "nuxt",
"label": "nuxt",
"position": {
"end": {
"column": 25,
"line": 3,
"offset": 50,
},
"start": {
"column": 1,
"line": 3,
"offset": 26,
},
},
"title": null,
"type": "definition",
"url": "https://nuxt.com",
},
],
"position": {
"end": {
"column": 25,
"line": 3,
"offset": 50,
},
"start": {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "root",
}
`;

exports[`Attributes > nested 1`] = `
{
"children": [
Expand Down
3 changes: 3 additions & 0 deletions test/attributes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ describe('Attributes', () => {
link: {
markdown: '[Nuxt](https://nuxtjs.org){#id .class}'
},
linkReference: {
markdown: '[Nuxt][nuxt]{#id .class}\n\n[nuxt]: https://nuxt.com'
},
emphasis: {
markdown: '_emphasis_{#id .class}'
},
Expand Down

0 comments on commit 1ac6c7e

Please sign in to comment.