mirror of
https://github.com/grafana/grafana.git
synced 2025-02-10 15:45:43 -06:00
42 lines
755 B
TypeScript
42 lines
755 B
TypeScript
import { Block, Document, Text, Value } from 'slate';
|
|
|
|
const SCHEMA = {
|
|
blocks: {
|
|
paragraph: 'paragraph',
|
|
codeblock: 'code_block',
|
|
codeline: 'code_line',
|
|
},
|
|
inlines: {},
|
|
marks: {},
|
|
};
|
|
|
|
export const makeFragment = (text: string, syntax?: string) => {
|
|
const lines = text.split('\n').map(line =>
|
|
Block.create({
|
|
type: 'code_line',
|
|
nodes: [Text.create(line)],
|
|
})
|
|
);
|
|
|
|
const block = Block.create({
|
|
data: {
|
|
syntax,
|
|
},
|
|
type: 'code_block',
|
|
nodes: lines,
|
|
});
|
|
|
|
return Document.create({
|
|
nodes: [block],
|
|
});
|
|
};
|
|
|
|
export const makeValue = (text: string, syntax?: string) => {
|
|
const fragment = makeFragment(text, syntax);
|
|
|
|
return Value.create({
|
|
document: fragment,
|
|
SCHEMA,
|
|
});
|
|
};
|