Skip to content

Commit

Permalink
Merge pull request evt-project#100 from evt-project/feature/multiple-…
Browse files Browse the repository at this point in the history
…lines-words

Feature/multiple lines words
  • Loading branch information
giuliac89 authored Nov 26, 2020
2 parents a11a563 + cd52618 commit 6ce2da1
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Updated to Angular 9

### Added
- Multiple line words normalization in interpretative and critical edition
- Word visualization
- Incurable corruptions visualization
- Verses/Prose toggler
- Addition vizualization
Expand Down
2 changes: 2 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import { SuppliedComponent } from './components/supplied/supplied.component';
import { SurplusComponent } from './components/surplus/surplus.component';
import { TextComponent } from './components/text/text.component';
import { VerseComponent } from './components/verse/verse.component';
import { WordComponent } from './components/word/word.component';
import { EditorialConventionLayoutDirective } from './directives/editorial-convention-layout.directive';
import { HighlightDirective } from './directives/highlight.directive';
import { HtmlAttributesDirective } from './directives/html-attributes.directive';
Expand Down Expand Up @@ -148,6 +149,7 @@ export function initializeApp(appConfig: AppConfig) {
VerseComponent,
VersionPanelComponent,
WitnessPanelComponent,
WordComponent,
XmlBeautifyPipe,
],
imports: [
Expand Down
5 changes: 5 additions & 0 deletions src/app/components/word/word.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<span class="word {{data.class}}" [evtHtmlAttributes]="data.attributes">
<evt-content-viewer *ngFor="let el of word" [content]="el" [editionLevel]="editionLevel"
[itemsToHighlight]="itemsToHighlight" [evtHighlight]="highlightData">
</evt-content-viewer>
</span>
Empty file.
25 changes: 25 additions & 0 deletions src/app/components/word/word.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { WordComponent } from './word.component';

describe('WordComponent', () => {
let component: WordComponent;
let fixture: ComponentFixture<WordComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ WordComponent ],
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(WordComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
34 changes: 34 additions & 0 deletions src/app/components/word/word.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Component, Input } from '@angular/core';

import { GenericElement, Lb, Word } from '../../models/evt-models';
import { register } from '../../services/component-register.service';
import { EditionlevelSusceptible, Highlightable } from '../components-mixins';

export interface WordComponent extends EditionlevelSusceptible, Highlightable { }

@Component({
selector: 'evt-word',
templateUrl: './word.component.html',
styleUrls: ['./word.component.scss'],
})
@register(Word)
export class WordComponent {
@Input() data: Word;

get word() {
if (this.editionLevel === 'diplomatic') {
return this.data.content;
}

const lbIndex = this.data.content.findIndex((el: GenericElement) => el.type === Lb);
if (lbIndex >= 0) {
const wordContent = [...this.data.content];
wordContent.splice(lbIndex, 1);
wordContent.push(this.data.content[lbIndex]);

return wordContent;
}

return this.data.content;
}
}
4 changes: 4 additions & 0 deletions src/app/models/evt-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,7 @@ export type SicType = 'crux'; // sic types supported in specific ways
export class Sic extends GenericElement {
sicType?: SicType | string;
}

export class Word extends GenericElement {
lemma?: string;
}
18 changes: 17 additions & 1 deletion src/app/services/xml-parsers/basic-parsers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AttributesMap } from 'ng-dynamic-component';
import {
Addition, Attributes, Damage, Gap, GenericElement, Lb, Note, NoteLayout,
Paragraph, PlacementType, Supplied, Text, Verse, XMLElement,
Paragraph, PlacementType, Supplied, Text, Verse, Word, XMLElement,
} from '../../models/evt-models';
import { isNestedInElem, xpath } from '../../utils/dom-utils';
import { replaceMultispaces } from '../../utils/xml-utils';
Expand Down Expand Up @@ -223,3 +223,19 @@ export class AdditionParser extends EmptyParser implements Parser<XMLElement> {
};
}
}

export class WordParser extends EmptyParser implements Parser<XMLElement> {
attributeParser = createParser(AttributeParser, this.genericParse);
parse(xml: XMLElement): Word {
const attributes = this.attributeParser.parse(xml);
const { lemma } = attributes;

return {
type: Word,
lemma,
class: getClass(xml),
content: parseChildren(xml, this.genericParse),
attributes: this.attributeParser.parse(xml),
};
}
}
5 changes: 3 additions & 2 deletions src/app/services/xml-parsers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Comment, GenericElement, HTML, XMLElement } from '../../models/evt-mode
import { AppParser, RdgParser } from './app-parser';
import {
AdditionParser, DamageParser, ElementParser, GapParser, LBParser, NoteParser, ParagraphParser,
PtrParser, SuppliedParser, TextParser, VerseParser,
PtrParser, SuppliedParser, TextParser, VerseParser, WordParser,
} from './basic-parsers';
import { CharParser, GlyphParser, GParser } from './character-declarations-parser';
import { ChoiceParser } from './choice-parser';
Expand All @@ -16,7 +16,7 @@ import { createParser, Parser, ParseResult } from './parser-models';

type SupportedTagNames = 'add' | 'app' | 'char' | 'choice' | 'damage' | 'event' | 'g' | 'gap' | 'geogname' | 'glyph' | 'graphic' | 'l' | 'lb' |
'lem' | 'note' | 'orgname' | 'p' | 'persname' | 'placename' | 'ptr' | 'person' | 'personGrp' | 'place' | 'org' | 'rdg' | 'sic' | 'surface' |
'supplied' | 'surplus' | 'zone';
'supplied' | 'surplus' | 'w' | 'zone';

export const parseF: { [T in SupportedTagNames]: Parser<XMLElement> } = {
add: createParser(AdditionParser, parse),
Expand Down Expand Up @@ -49,6 +49,7 @@ export const parseF: { [T in SupportedTagNames]: Parser<XMLElement> } = {
surface: createParser(SurfaceParser, parse),
supplied: createParser(SuppliedParser, parse),
surplus: createParser(SurplusParser, parse),
w: createParser(WordParser, parse),
zone: createParser(ZoneParser, parse),
};

Expand Down

0 comments on commit 6ce2da1

Please sign in to comment.