-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.mjs
27 lines (16 loc) · 7.07 KB
/
test.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import python from "./lib"
const create_doc = python.create_doc
const transform_doc = python.transform_doc
const spec_data = JSON.parse('{"nodes":{"content":["doc",{"content":"article","selectable":false},"article",{"defining":true,"content":"title subtitle authors abstract keywords body","selectable":false,"allowGapCursor":false,"attrs":{"papersize":{"default":"A4"},"citationstyle":{"default":""},"documentstyle":{"default":""},"language":{"default":"en-US"},"tracked":{"default":false}},"parseDOM":[{"tag":"div.article"}]},"title",{"content":"text*","marks":"annotation track","group":"part","defining":true,"parseDOM":[{"tag":"div.article-title"}]},"subtitle",{"content":"text*","marks":"annotation track","group":"part","defining":true,"attrs":{"hidden":{"default":true}},"parseDOM":[{"tag":"div.article-subtitle"}]},"authors",{"content":"author*","marks":"annotation track","group":"part","defining":true,"attrs":{"hidden":{"default":true}},"parseDOM":[{"tag":"div.article-authors"}]},"author",{"inline":true,"draggable":true,"attrs":{"firstname":{"default":false},"lastname":{"default":false},"email":{"default":false},"institution":{"default":false}},"parseDOM":[{"tag":"span.author"}]},"abstract",{"content":"(block | table_block)+","group":"part","marks":"annotation","defining":true,"attrs":{"hidden":{"default":true}},"parseDOM":[{"tag":"div.article-abstract"}]},"keywords",{"content":"keyword*","marks":"annotation track","group":"part","defining":true,"attrs":{"hidden":{"default":true}},"parseDOM":[{"tag":"div.article-keywords"}]},"keyword",{"inline":true,"draggable":true,"attrs":{"keyword":{"default":""}},"parseDOM":[{"tag":"span.keyword"}]},"body",{"content":"(block | table_block)+","group":"part","marks":"annotation track","defining":true,"parseDOM":[{"tag":"div.article-body"}]},"paragraph",{"group":"block","content":"inline*","attrs":{"track":{"default":[]}},"parseDOM":[{"tag":"p"}]},"blockquote",{"content":"block+","group":"block","attrs":{"track":{"default":[]}},"marks":"annotation","defining":true,"parseDOM":[{"tag":"blockquote"}]},"horizontal_rule",{"group":"block","attrs":{"track":{"default":[]}},"parseDOM":[{"tag":"hr"}]},"figure",{"group":"block","attrs":{"equation":{"default":""},"image":{"default":false},"figureCategory":{"default":""},"caption":{"default":""},"id":{"default":false},"track":{"default":[]}},"parseDOM":[{"tag":"figure"}]},"heading",{"group":"block","content":"inline*","marks":"_","defining":true,"attrs":{"level":{"default":1},"id":{"default":false},"track":{"default":[]}},"parseDOM":[{"tag":"h1"},{"tag":"h2"},{"tag":"h3"},{"tag":"h4"},{"tag":"h5"},{"tag":"h6"}]},"code_block",{"content":"text*","marks":"annotation track","group":"block","code":true,"defining":true,"attrs":{"track":{"default":[]}},"parseDOM":[{"tag":"pre","preserveWhitespace":"full"}]},"text",{"group":"inline"},"hard_break",{"inline":true,"group":"inline","selectable":false,"parseDOM":[{"tag":"br"}]},"citation",{"inline":true,"group":"inline","attrs":{"format":{"default":"autocite"},"references":{"default":[]}},"parseDOM":[{"tag":"span.citation"}]},"equation",{"inline":true,"group":"inline","attrs":{"equation":{"default":""}},"parseDOM":[{"tag":"span.equation"}]},"footnote",{"inline":true,"group":"inline","attrs":{"footnote":{"default":[{"type":"paragraph"}]}},"parseDOM":[{"tag":"span.footnote-marker[data-footnote]"}]},"ordered_list",{"group":"block","content":"list_item+","attrs":{"order":{"default":1},"track":{"default":[]}},"parseDOM":[{"tag":"ol"}]},"bullet_list",{"group":"block","content":"list_item+","attrs":{"track":{"default":[]}},"parseDOM":[{"tag":"ul"}]},"list_item",{"content":"block+","marks":"annotation","attrs":{"track":{"default":[]}},"parseDOM":[{"tag":"li"}],"defining":true},"table",{"content":"table_row+","tableRole":"table","isolating":true,"group":"table_block","parseDOM":[{"tag":"table"}],"attrs":{"track":{"default":[]}}},"table_row",{"content":"(table_cell | table_header)*","tableRole":"row","parseDOM":[{"tag":"tr"}]},"table_cell",{"marks":"annotation","content":"block+","attrs":{"colspan":{"default":1},"rowspan":{"default":1},"colwidth":{"default":null}},"tableRole":"cell","isolating":true,"parseDOM":[{"tag":"td"}]},"table_header",{"content":"block+","attrs":{"colspan":{"default":1},"rowspan":{"default":1},"colwidth":{"default":null}},"tableRole":"header_cell","isolating":true,"parseDOM":[{"tag":"th"}]}]},"marks":{"content":["em",{"parseDOM":[{"tag":"i"},{"tag":"em"},{"style":"font-style=italic"}]},"strong",{"parseDOM":[{"tag":"strong"},{"tag":"b"},{"style":"font-weight"}]},"link",{"attrs":{"href":{},"title":{"default":null}},"inclusive":false,"parseDOM":[{"tag":"a[href]"}]},"code",{"parseDOM":[{"tag":"code"}]},"comment",{"attrs":{"id":{}},"inclusive":false,"excludes":"","group":"annotation","parseDOM":[{"tag":"span.comment[data-id]"}]},"annotation_tag",{"attrs":{"type":{"default":""},"key":{"default":""},"value":{"default":""}},"inclusive":false,"excludes":"","group":"annotation","parseDOM":[{"tag":"span.annotation-tag[data-type]"}]},"anchor",{"attrs":{"id":{"default":false}},"inclusive":false,"group":"annotation","parseDOM":[{"tag":"span.anchor[data-id]"}]},"deletion",{"attrs":{"user":{"default":0},"username":{"default":""},"date":{"default":0}},"inclusive":false,"group":"track","parseDOM":[{"tag":"span.deletion"}]},"insertion",{"attrs":{"user":{"default":0},"username":{"default":""},"date":{"default":0},"approved":{"default":true}},"inclusive":false,"group":"track","parseDOM":[{"tag":"span.insertion"},{"tag":"span.approved-insertion"}]},"format_change",{"attrs":{"user":{"default":0},"username":{"default":""},"date":{"default":0},"before":{"default":[]},"after":{"default":[]}},"inclusive":false,"group":"track","parseDOM":[{"tag":"span.format-change"}]}]}}')
const doc_data = JSON.parse('{"type":"doc","content":[{"type":"article","attrs":{"papersize":"A4","citationstyle":"apa","documentstyle":"elephant","language":"en-US","tracked":false},"content":[{"type":"title","content":[{"type":"text","marks":[{"type":"insertion","attrs":{"user":1,"username":"johanneswilm","date":25710790,"approved":true}}],"text":"testing"}]},{"type":"subtitle","attrs":{"hidden":true}},{"type":"authors","attrs":{"hidden":true}},{"type":"abstract","attrs":{"hidden":true},"content":[{"type":"paragraph","attrs":{"track":[]}}]},{"type":"keywords","attrs":{"hidden":true}},{"type":"body","content":[{"type":"paragraph","attrs":{"track":[]},"content":[{"type":"text","marks":[{"type":"insertion","attrs":{"user":1,"username":"johanneswilm","date":25710790,"approved":true}}],"text":"the body"}]}]}]}]}')
const doc = create_doc(doc_data, spec_data)
const step_data = JSON.parse('[{"stepType":"replace","from":27,"to":27,"slice":{"content":[{"type":"text","marks":[{"type":"insertion","attrs":{"user":1,"username":"johanneswilm","date":25710790,"approved":true}}],"text":"X"}]}},{"stepType":"addMark","mark":{"type":"insertion","attrs":{"user":1,"username":"johanneswilm","date":25716230,"approved":true}},"from":27,"to":28}]')
const start = process.hrtime()
let new_doc, i = 0
while(i < 100) {
new_doc = transform_doc(step_data, doc)
i++
}
new_doc.toJSON()
const stop = process.hrtime(start)
console.log((stop[1] / 1000000)/100000)