This repository has been archived by the owner on Aug 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from curvenote/feat/ref
New reference node and inline content
- Loading branch information
Showing
9 changed files
with
74 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { NodeSpec } from 'prosemirror-model'; | ||
import { NodeGroups, FormatSerialize } from './types'; | ||
|
||
const ref: NodeSpec = { | ||
attrs: { | ||
kind: { default: null }, | ||
key: { default: null }, | ||
}, | ||
inline: true, | ||
marks: '', | ||
group: NodeGroups.inline, | ||
draggable: true, | ||
parseDOM: [{ | ||
tag: 'cite.ref', | ||
getAttrs(dom: any) { | ||
return { | ||
kind: dom.getAttribute('kind'), | ||
key: dom.getAttribute('key') ?? dom.getAttribute('data-key') ?? dom.getAttribute('data-cite') ?? dom.getAttribute('data-ref'), | ||
}; | ||
}, | ||
// cite is also parsed, and this is higher priority | ||
priority: 60, | ||
}], | ||
toDOM(node) { | ||
const { key, kind } = node.attrs; | ||
return ['cite', { class: 'ref', kind, key }]; | ||
}, | ||
}; | ||
|
||
|
||
export const toMarkdown: FormatSerialize = (state, node) => { | ||
state.write(`{ref}\`${node.attrs.key}\``); | ||
}; | ||
|
||
export const toTex: FormatSerialize = (state, node) => { | ||
state.write(`\\ref{${node.attrs.key}}`); | ||
}; | ||
|
||
export default ref; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
import { LinkAttrs } from './marks'; | ||
|
||
export type Parser = { | ||
new(): DOMParser; | ||
prototype: DOMParser; | ||
}; | ||
|
||
export type { LinkAttrs }; |