diff --git a/src/javascript/models/ElementType.jsx b/src/javascript/models/markdown/BlockType.jsx similarity index 82% rename from src/javascript/models/ElementType.jsx rename to src/javascript/models/markdown/BlockType.jsx index b29dddc..911fb70 100644 --- a/src/javascript/models/ElementType.jsx +++ b/src/javascript/models/markdown/BlockType.jsx @@ -1,14 +1,14 @@ import { Enum } from 'enumify'; -import { linesToText } from './markdown/WordType.jsx'; -import LineItemBlock from './LineItemBlock.jsx'; +import { linesToText } from './WordType.jsx'; +import LineItemBlock from '../LineItemBlock.jsx'; -// An Markdown element -export default class ElementType extends Enum { +// An Markdown block +export default class BlockType extends Enum { } //TODO rename to BlockType -ElementType.initEnum({ +BlockType.initEnum({ H1: { headline: true, headlineLevel: 1, @@ -84,8 +84,8 @@ ElementType.initEnum({ } }); -export function isHeadline(elementType: ElementType) { - return elementType && elementType.name.length == 2 && elementType.name[0] === 'H' +export function isHeadline(type: BlockType) { + return type && type.name.length == 2 && type.name[0] === 'H' } export function blockToText(block: LineItemBlock) { @@ -97,17 +97,17 @@ export function blockToText(block: LineItemBlock) { export function headlineByLevel(level) { if (level == 1) { - return ElementType.H1; + return BlockType.H1; } else if (level == 2) { - return ElementType.H2; + return BlockType.H2; } else if (level == 3) { - return ElementType.H3; + return BlockType.H3; } else if (level == 4) { - return ElementType.H4; + return BlockType.H4; } else if (level == 5) { - return ElementType.H5; + return BlockType.H5; } else if (level == 6) { - return ElementType.H6; + return BlockType.H6; } throw "Unsupported headline level: " + level + " (supported are 1-6)"; } \ No newline at end of file diff --git a/src/javascript/models/transformations/ToTextBlocks.jsx b/src/javascript/models/transformations/ToTextBlocks.jsx index 4d090ee..69237ed 100644 --- a/src/javascript/models/transformations/ToTextBlocks.jsx +++ b/src/javascript/models/transformations/ToTextBlocks.jsx @@ -2,7 +2,7 @@ import React from 'react'; import Transformation from './Transformation.jsx'; import TextPageView from '../../components/debug/TextPageView.jsx'; import ParseResult from '../ParseResult.jsx'; -import { blockToText } from '../ElementType.jsx'; +import { blockToText } from '../markdown/BlockType.jsx'; export default class ToTextBlocks extends Transformation { diff --git a/src/javascript/models/transformations/textitem/CompactLines.jsx b/src/javascript/models/transformations/textitem/CompactLines.jsx index f19781e..b4f3350 100644 --- a/src/javascript/models/transformations/textitem/CompactLines.jsx +++ b/src/javascript/models/transformations/textitem/CompactLines.jsx @@ -5,7 +5,7 @@ import ParseResult from '../../ParseResult.jsx'; import LineItem from '../../LineItem.jsx'; import TextItemLineGrouper from '../../TextItemLineGrouper.jsx'; import LineConverter from '../../LineConverter.jsx'; -import ElementType from '../../ElementType.jsx'; +import BlockType from '../../markdown/BlockType.jsx'; import { REMOVED_ANNOTATION, ADDED_ANNOTATION } from '../../Annotation.jsx'; @@ -59,7 +59,7 @@ export default class CompactLines extends ToLineItemTransformation { foundFootnoteLinks.push.apply(foundFootnoteLinks, footnoteLinks); } if (lineItem.parsedElements.footnotes.length > 0) { - lineItem.type = ElementType.FOOTNOTES; + lineItem.type = BlockType.FOOTNOTES; const footnotes = lineItem.parsedElements.footnotes.map(footnote => { footnote },); foundFootnotes.push.apply(foundFootnotes, footnotes); } diff --git a/src/javascript/models/transformations/textitem/DetectHeaders.jsx b/src/javascript/models/transformations/textitem/DetectHeaders.jsx index 11a0631..58d283b 100644 --- a/src/javascript/models/transformations/textitem/DetectHeaders.jsx +++ b/src/javascript/models/transformations/textitem/DetectHeaders.jsx @@ -1,8 +1,8 @@ import ToLineItemTransformation from '../ToLineItemTransformation.jsx'; import ParseResult from '../../ParseResult.jsx'; import { DETECTED_ANNOTATION } from '../../Annotation.jsx'; -import ElementType from '../../ElementType.jsx'; -import { headlineByLevel } from '../../ElementType.jsx'; +import BlockType from '../../markdown/BlockType.jsx'; +import { headlineByLevel } from '../../markdown/BlockType.jsx'; import { isListItem } from '../../../stringFunctions.jsx'; //Detect headlines based on heights @@ -25,9 +25,9 @@ export default class DetectHeaders extends ToLineItemTransformation { const height = item.height; if (!item.type && height > min2ndLevelHeaderHeigthOnMaxPage) { if (height == maxHeight) { - item.type = ElementType.H1; + item.type = BlockType.H1; } else { - item.type = ElementType.H2; + item.type = BlockType.H2; } item.annotation = DETECTED_ANNOTATION; detectedHeaders++; @@ -44,7 +44,7 @@ export default class DetectHeaders extends ToLineItemTransformation { page.items.forEach(item => { if (!item.type && item.height == range.max) { item.annotation = DETECTED_ANNOTATION; - item.type = ElementType.enumValueOf(headlineType); + item.type = BlockType.enumValueOf(headlineType); detectedHeaders++ } }); diff --git a/src/javascript/models/transformations/textitem/DetectListItems.jsx b/src/javascript/models/transformations/textitem/DetectListItems.jsx index 8ff0856..fde4d09 100644 --- a/src/javascript/models/transformations/textitem/DetectListItems.jsx +++ b/src/javascript/models/transformations/textitem/DetectListItems.jsx @@ -3,7 +3,7 @@ import ParseResult from '../../ParseResult.jsx'; import LineItem from '../../LineItem.jsx'; import Word from '../../Word.jsx'; import { REMOVED_ANNOTATION, ADDED_ANNOTATION, DETECTED_ANNOTATION } from '../../Annotation.jsx'; -import ElementType from '../../ElementType.jsx'; +import BlockType from '../../markdown/BlockType.jsx'; import { isListItemCharacter, isNumberedListItem } from '../../../stringFunctions.jsx'; //Detect items starting with -, •, etc... @@ -26,7 +26,7 @@ export default class DetectListItems extends ToLineItemTransformation { foundListItems++ if (item.words[0].string === '-') { item.annotation = DETECTED_ANNOTATION; - item.type = ElementType.LIST; + item.type = BlockType.LIST; } else { item.annotation = REMOVED_ANNOTATION; const newWords = item.words.map(word => new Word({ @@ -37,13 +37,13 @@ export default class DetectListItems extends ToLineItemTransformation { ...item, words: newWords, annotation: ADDED_ANNOTATION, - type: ElementType.LIST + type: BlockType.LIST })); } } else if (isNumberedListItem(text)) { //TODO check that starts with 1 (kala chakra) foundNumberedItems++; item.annotation = DETECTED_ANNOTATION; - item.type = ElementType.LIST; + item.type = BlockType.LIST; } } }); diff --git a/src/javascript/models/transformations/textitem/DetectTOC.jsx b/src/javascript/models/transformations/textitem/DetectTOC.jsx index f81e5d8..46525f5 100644 --- a/src/javascript/models/transformations/textitem/DetectTOC.jsx +++ b/src/javascript/models/transformations/textitem/DetectTOC.jsx @@ -4,8 +4,8 @@ import LineItem from '../../LineItem.jsx'; import Word from '../../Word.jsx'; import HeadlineFinder from '../../HeadlineFinder.jsx'; import { REMOVED_ANNOTATION, ADDED_ANNOTATION } from '../../Annotation.jsx'; -import ElementType from '../../ElementType.jsx'; -import { headlineByLevel } from '../../ElementType.jsx'; +import BlockType from '../../markdown/BlockType.jsx'; +import { headlineByLevel } from '../../markdown/BlockType.jsx'; import { isDigit, isNumber, wordMatch, hasOnly } from '../../../stringFunctions.jsx' //Detect table of contents pages plus linked headlines @@ -90,7 +90,7 @@ export default class DetectTOC extends ToLineItemTransformation { if (line === headlineItem) { newBlocks.push(new LineItem({ ...line, - type: ElementType.H2, + type: BlockType.H2, annotation: ADDED_ANNOTATION })); } @@ -114,7 +114,7 @@ export default class DetectTOC extends ToLineItemTransformation { words: [new Word({ string: ' '.repeat(tocLink.level * 3) + '-' })].concat(tocLink.lineItem.words), - type: ElementType.TOC, + type: BlockType.TOC, annotation: ADDED_ANNOTATION })); }); diff --git a/src/javascript/models/transformations/textitemblock/DetectCodeQuoteBlocks.jsx b/src/javascript/models/transformations/textitemblock/DetectCodeQuoteBlocks.jsx index 6b0dd45..f8217b6 100644 --- a/src/javascript/models/transformations/textitemblock/DetectCodeQuoteBlocks.jsx +++ b/src/javascript/models/transformations/textitemblock/DetectCodeQuoteBlocks.jsx @@ -1,7 +1,7 @@ import ToLineItemBlockTransformation from '../ToLineItemBlockTransformation.jsx'; import ParseResult from '../../ParseResult.jsx'; import { DETECTED_ANNOTATION } from '../../Annotation.jsx'; -import ElementType from '../../ElementType.jsx'; +import BlockType from '../../markdown/BlockType.jsx'; import { minXFromBlocks } from '../../../pageItemFunctions.jsx'; //Detect items which are code/quote blocks @@ -19,7 +19,7 @@ export default class DetectCodeQuoteBlocks extends ToLineItemBlockTransformation page.items.forEach(block => { if (!block.type && looksLikeCodeBlock(minX, block.items, mostUsedHeight)) { block.annotation = DETECTED_ANNOTATION; - block.type = ElementType.CODE; + block.type = BlockType.CODE; foundCodeItems++; } }); diff --git a/src/javascript/models/transformations/textitemblock/DetectListLevels.jsx b/src/javascript/models/transformations/textitemblock/DetectListLevels.jsx index eb766d5..bc31c4b 100644 --- a/src/javascript/models/transformations/textitemblock/DetectListLevels.jsx +++ b/src/javascript/models/transformations/textitemblock/DetectListLevels.jsx @@ -2,7 +2,7 @@ import ToLineItemBlockTransformation from '../ToLineItemBlockTransformation.jsx' import ParseResult from '../../ParseResult.jsx'; import Word from '../../Word.jsx'; import { MODIFIED_ANNOTATION, UNCHANGED_ANNOTATION } from '../../Annotation.jsx'; -import ElementType from '../../ElementType.jsx'; +import BlockType from '../../markdown/BlockType.jsx'; // Cares for proper sub-item spacing/leveling export default class DetectListLevels extends ToLineItemBlockTransformation { @@ -17,7 +17,7 @@ export default class DetectListLevels extends ToLineItemBlockTransformation { var modifiedBlocks = 0; parseResult.pages.forEach(page => { - page.items.filter(block => block.type === ElementType.LIST).forEach(listBlock => { + page.items.filter(block => block.type === BlockType.LIST).forEach(listBlock => { var lastItemX; var currentLevel = 0; const xByLevel = {};