Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | 1x 1x 1x 1x 1x 91x 91x 91x 70x 70x 15x 15x 4x 4x 1x 1x 1x 1x 91x | import { createMarkdownBlockGroup } from './createMarkdownBlockGroup';
import { createMarkdownParagraph } from './createMarkdownParagraph';
import { createMarkdownTable } from './createMarkdownTable';
import type { ParagraphContext } from './createMarkdownParagraph';
import type { ContentModelBlock } from 'roosterjs-content-model-types';
import type { ListCounter } from './createMarkdownBlockGroup';
import type { MarkdownLineBreaks } from '../../constants/markdownLineBreaks';
/**
* @internal
*/
export interface MarkdownLineBreaksByBlockType {
table: string;
paragraph: string;
divider: string;
}
const DEFAULT_NEW_LINE: MarkdownLineBreaksByBlockType = {
table: '',
paragraph: '',
divider: '\n\n',
};
/**
* @internal
*/
export function createMarkdownBlock(
block: ContentModelBlock,
newLinePattern: MarkdownLineBreaks,
listCounter: ListCounter,
newLines?: Partial<MarkdownLineBreaksByBlockType>,
paragraphContext?: ParagraphContext
): string {
let markdownString = '';
const lines = { ...DEFAULT_NEW_LINE, ...newLines };
switch (block.blockType) {
case 'Paragraph':
markdownString += createMarkdownParagraph(block, paragraphContext) + lines.paragraph;
break;
case 'BlockGroup':
markdownString += createMarkdownBlockGroup(block, newLinePattern, listCounter);
break;
case 'Table':
markdownString += createMarkdownTable(block, newLinePattern, listCounter) + lines.table;
break;
case 'Divider':
Eif (!paragraphContext?.ignoreLineBreaks) {
markdownString += '---' + lines.divider;
}
break;
case 'Entity':
break;
default:
break;
}
return markdownString;
}
|