Commit 6ae9602d authored by pestov's avatar pestov
Browse files

Move renditions handling to CommonTransformService

parent 03b1f651
Pipeline #243456 passed with stages
in 6 minutes and 14 seconds
......@@ -21,7 +21,24 @@ class CommonTransformService
* ‹XXX <span class="italic">Erg.</span>›
* and so we don't need to transform the children again.
*/
public array $ignoreChildrenList = [];
protected array $ignoreChildrenList = [];
/** @var array|string[]
* A map of rendition styles.
* The key represents occurrence in TEI and the value the assigned HTML class name.
* Services that inherit from this class can override this map and style the renditions in their own way.
*/
protected array $renditions = [
'centre' => 'centre',
'doubleunderline' => 'doubleunderline',
'italic' => 'italic',
'letterspace' => 'letterspace',
'right' => 'right',
'subscript' => 'subscript',
'smallcaps' => 'smallcaps',
'superscript' => 'superscript',
'underline' => 'underline',
];
public function setGraphics(array $graphics): void
{
......@@ -161,4 +178,18 @@ class CommonTransformService
return $htmlEl;
}
protected function handleRenditions(string $value, DOMNode $htmlEl): DOMNode
{
$valueArr = explode(':', $value);
$style = isset($valueArr[1]) ? $valueArr[1] : '';
if (!empty($style)) {
$className = $this->renditions[$style];
if ($className) {
$htmlEl->setAttribute('class', $className);
}
}
return $htmlEl;
}
}
......@@ -26,6 +26,18 @@ class EditedTextService extends CommonTransformService
public array $ignoreChildrenList = [];
protected array $renditions = [
'centre' => 'left',
'doubleunderline' => 'letterspace',
'italic' => 'normal',
'letterspace' => 'letterspace',
'right' => 'left',
'subscript' => 'subscript',
'smallcaps' => 'letterspace',
'superscript' => 'superscript',
'underline' => 'letterspace',
];
public function clear()
{
$this->gndsUuids = [];
......@@ -239,6 +251,19 @@ class EditedTextService extends CommonTransformService
return null;
}
protected function handleHi(DOMElement $teiEl, HTMLDocument $doc): DOMNode
{
$htmlEl = $doc->span();
if ($teiEl->hasAttributes()) {
foreach ($teiEl->attributes as $attribute) {
if ($attribute->nodeName === 'rendition') {
$htmlEl = $this->handleRenditions($attribute->value, $htmlEl);
}
}
}
return $htmlEl;
}
private function setUuid(DOMNode $el, ?string $uuid = null): DOMNode
{
if (null === $uuid) {
......
......@@ -18,6 +18,18 @@ class TranscriptionService extends CommonTransformService
'del'
];
protected array $renditions = [
'centre' => 'left',
'doubleunderline' => 'doubleunderline',
'italic' => 'italic',
'letterspace' => 'letterspace',
'right' => 'left',
'subscript' => 'subscript',
'smallcaps' => 'smallcaps',
'superscript' => 'superscript',
'underline' => 'underline',
];
protected function handleDiv(DOMElement $teiEl, HTMLDocument $doc): DOMNode
{
return $doc->section();
......@@ -110,35 +122,13 @@ class TranscriptionService extends CommonTransformService
return $italic;
}
protected function handleHi(DOMElement $teiEl, HTMLDocument $doc): DOMNode
protected function handleHi(DOMElement $teiEl, HTMLDocument $doc): DOMNode
{
$htmlEl = $doc->span();
if ('hi' === $teiEl->nodeName && isset($teiEl->attributes[0])) {
if ($teiEl->hasAttributes()) {
foreach ($teiEl->attributes as $attribute) {
$hi = explode(':', $attribute->value);
if (isset($hi[1]) && !empty($hi[1]) && 'italic' === $hi[1]) {
$htmlEl->setAttribute('class', 'italic');
}
elseif (isset($hi[1]) && !empty($hi[1]) && 'underline' === $hi[1]) {
$htmlEl->setAttribute('class', 'underline');
}
elseif (isset($hi[1]) && !empty($hi[1]) && 'doubleunderline' === $hi[1]) {
$htmlEl->setAttribute('class', 'doubleunderline');
}
elseif (isset($hi[1]) && !empty($hi[1]) && 'letterspace' === $hi[1]) {
$htmlEl->setAttribute('class', 'letterspace');
}
elseif (isset($hi[1]) && !empty($hi[1]) && 'subscript' === $hi[1]) {
$htmlEl->setAttribute('class', 'subscript');
}
elseif (isset($hi[1]) && !empty($hi[1]) && 'superscript' === $hi[1]) {
$htmlEl->setAttribute('class', 'superscript');
}
elseif (isset($hi[1]) && !empty($hi[1]) && 'centre' === $hi[1]) {
$htmlEl = $doc->p();
$htmlEl->setAttribute('class', 'left');
if ($attribute->nodeName === 'rendition') {
$htmlEl = $this->handleRenditions($attribute->value, $htmlEl);
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment