Skip to content

Commit

Permalink
added handShift
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Romphf authored and Josh Romphf committed Nov 16, 2017
1 parent 28a3d9e commit 29d4d3d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
27 changes: 25 additions & 2 deletions src/components/FZTextView.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,25 @@ const formatDiplomaticText = (diplomatic: Array) => {
});
}

const formatHandShift = (element) => {
return(
<span className="tei-instr-pencil">
{element.map((node, index) => {
if (typeof node === 'string') return <span key={index}>{node}</span>
if (typeof node === 'object') {
if (node.nodeType === 'unclear') {
return <span key={index} className="tei-unclear-hi">{node["#text"]}</span>
}
if (node.nodeType === 'del') {
let delClass = getDelType(node);
return <span key={index} className={delClass + ' tei-instr-pencil'}>{node["#text"]}</span>
}
}
})}
</span>
);
}

diplomatic.forEach((element, index) => {
let key = shortid.generate();
if ( element instanceof Object) {
Expand All @@ -220,6 +239,10 @@ const formatDiplomaticText = (diplomatic: Array) => {
doDeletion(element, formatted);
break;

case 'handShift':
formatted.push(formatHandShift(element));
break;

case 'subst':
let subst = [];
if (element.del) {
Expand All @@ -232,9 +255,9 @@ const formatDiplomaticText = (diplomatic: Array) => {
formatted.push(<span key={key} className="tei-subst">{subst}</span>);
break;

case 'handShift':
/*case 'handShift':
formatted.push(<span key={key} className="tei-instr-pencil">{element["text"]}</span>);
break;
break;*/

default:
break;
Expand Down
20 changes: 15 additions & 5 deletions src/middleware/file-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@

function xmlToJson(xml) {
// Handshift and unclear as objects with #text instead of arrays of text

// Create the return object
var obj = {};
if (xml.nodeType == 1) { // element
if (xml.nodeType === 1) { // element
// do attributes
let nodeName = xml.nodeName;
obj.nodeType = nodeName;
if (xml.hasChildNodes()) {
if (xml.attributes.length > 0) {
obj["attributes"] = {};
if (nodeName === 'handShift') {
let elements = [];
xml.childNodes.forEach((child) => {
elements.push(xmlToJson(child));
});
obj[nodeName] = elements;
}
else if (xml.attributes.length > 0) {
obj["attributes"] = {};
for (var j = 0; j < xml.attributes.length; j++) {
var attribute = xml.attributes.item(j);
obj["attributes"][attribute.nodeName] = attribute.nodeValue;
Expand All @@ -33,7 +40,6 @@ function xmlToJson(xml) {
} else if (xml.nodeType === 3) { // text
obj = xml.nodeValue;
}
/* TODO change stage and diplomatic from { elementName: Array } to Array<Object(element)> */
// do children
if (xml.hasChildNodes()) {
let stages = [];
Expand Down Expand Up @@ -78,6 +84,10 @@ function xmlToJson(xml) {
}
}
}
if (obj.nodeType === 'handShift') {
obj = obj.handShift;
obj.nodeType = 'handShift';
}
return obj;
};

Expand Down
3 changes: 1 addition & 2 deletions src/utils/data-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ export const normalizeZone = (zone: Object): Object => {
return undefined;
}
}

return {
// Need to somehow put vspace into linegroups array
// Need to somehow put vspace into linegroups array
id: shortid.generate(),
points: zone.attributes.points,
type: zone.attributes.type,
Expand Down

0 comments on commit 29d4d3d

Please sign in to comment.