Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7da9b48

Browse files
committed
feat: 🎸 extract definitions in structured document
1 parent27c76a4 commit7da9b48

File tree

2 files changed

+69
-7
lines changed

2 files changed

+69
-7
lines changed

‎src/__tests__/structure.spec.ts‎

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ describe('structure', () => {
3838
],
3939
contents:[],
4040
definitions:{},
41-
definitionOrder:[],
4241
footnotes:{},
4342
footnoteOrder:[],
4443
});
@@ -95,7 +94,70 @@ describe('structure', () => {
9594
],
9695
contents:[1,3],
9796
definitions:{},
98-
definitionOrder:[],
97+
footnotes:{},
98+
footnoteOrder:[],
99+
});
100+
});
101+
102+
it('structure link definitions',()=>{
103+
constparser=create();
104+
constmdast=parser.tokenizeBlock('[Click me][click]\n'+'\n'+'[click]: https://github.com/');
105+
constdoc=structure(mdast!);
106+
107+
expect(mdast).toMatchObject({
108+
type:'root',
109+
children:[
110+
{
111+
type:'paragraph',
112+
children:{
113+
type:'linkReference',
114+
children:{
115+
type:'text',
116+
value:'Click me',
117+
},
118+
identifier:'click',
119+
referenceType:'full',
120+
},
121+
},
122+
{
123+
type:'definition',
124+
identifier:'click',
125+
title:null,
126+
url:'https://github.com/',
127+
},
128+
],
129+
});
130+
expect(doc).toMatchObject({
131+
nodes:[
132+
{
133+
type:'root',
134+
children:[1,4],
135+
},
136+
{
137+
type:'paragraph',
138+
children:2,
139+
},
140+
{
141+
type:'linkReference',
142+
children:3,
143+
identifier:'click',
144+
referenceType:'full',
145+
},
146+
{
147+
type:'text',
148+
value:'Click me',
149+
},
150+
{
151+
type:'definition',
152+
identifier:'click',
153+
title:null,
154+
url:'https://github.com/',
155+
},
156+
],
157+
contents:[],
158+
definitions:{
159+
click:4,
160+
},
99161
footnotes:{},
100162
footnoteOrder:[],
101163
});

‎src/structure.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import{IRoot,IDefinition,IFootnoteDefinition,TAnyToken}from'./types';
1+
import{IRoot,IFootnoteDefinition,TAnyToken}from'./types';
22

33
exportinterfaceDocumentDefinitions{
4-
[id:string]:IDefinition;
4+
[id:string]:number;
55
}
66

77
exportinterfaceDocumentFootnotes{
@@ -14,7 +14,6 @@ export interface Document {
1414
nodes:TNode[];
1515
contents:number[];
1616
definitions:DocumentDefinitions;
17-
definitionOrder:string[];
1817
footnotes:DocumentFootnotes;
1918
footnoteOrder:string[];
2019
}
@@ -25,14 +24,12 @@ export const structure: Structure = mdast => {
2524
constnodes:TNode[]=[];
2625
constcontents:number[]=[];
2726
constdefinitions:DocumentDefinitions={};
28-
constdefinitionOrder:string[]=[];
2927
constfootnotes:DocumentFootnotes={};
3028
constfootnoteOrder:string[]=[];
3129
constdoc={
3230
nodes,
3331
contents,
3432
definitions,
35-
definitionOrder,
3633
footnotes,
3734
footnoteOrder,
3835
};
@@ -50,6 +47,9 @@ export const structure: Structure = mdast => {
5047
case'heading':
5148
contents.push(index);
5249
break;
50+
case'definition':
51+
definitions[node.identifier]=index;
52+
break;
5353
}
5454

5555
returnindex;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp