Overview

This is a memo on developing a TEI/XML viewer combining Next.js, CETEIcean, and React TEI Router.

Background

CETEIcean is a JavaScript library that converts TEI/XML to HTML5.

https://github.com/TEIC/CETEIcean

React TEI Router is a library that enables structured display of TEI/XML using React components, based on CETEIcean. It is described as follows:

https://github.com/pfefferniels/react-teirouter

TEI for React using CETEIcean and routes

By combining these, I created a viewer that can customize and display TEI/XML in Next.js.

Repository

The sample repository is below.

https://github.com/nakamura196/next-ceteicean-router

A working demo is also available.

https://next-ceteicean-router.vercel.app/

Implementation

Next.js Page Component (page.tsx)

Uses CETEIcean to convert XML and render it with custom components.

iie}mmxpppcrooooerrrn<ttttsT/utE<TrRRdIt/Eneeexe<tIanfmxxb/e><cdalmto<<bx`RteuCl>dd/d/ot;erlonyidi<<dd>nftns>vivpp/iydrft=v>pv>eorfe"t>ss>>rmounhyttmnttp<yyx"ctepllmr"t=p=eeele@i:"r==Ca/o`/os""occn</rNccnto?wiaoot"mAxwgmlle;ppmwieoonopl.nrrtn(tac::=e)velo{nei"rggxt{r->rrrmssceeel/i.seeCtoopnnoenr=;;ni=g"""t""/#>>e;1nin.sdt0/1}"1".>e0<>n"/<;c>pso>ed<gi/npsget=ry"slUNeTa=Fm"-ec8>o"l?o>r:blue;">xxx</seg>

TEI Rendering Component

  • Uses CETEIcean to convert XML to HTML5.
  • Uses TEIRender + TEIRoute to apply custom components for each TEI element.

Components are prepared for each element using import { TEIRender, TEIRoute } from "react-teirouter";.

"iiiiiiie}ummmmmmmxsppppppppcR}i}r)eoooooooooe,fe;rrrrrrrrnac}fci}t<cttttttttsco;e[(ofud/lttnccstxtnr)ris}<diRC{{{{{d.sooecmes(e;nvt}h/ieeEe[utnnthlittt<ydjah1s}LhvnaTTDPPSftsCssTDCDeud/(liulet}o1>tcEEieeaeefEtteaootirics<dessiiyfcfa>"tIIvr}guiEeTitnceEnvltT/i=ptggloood;RslDftECdDat)ilayE<<<<Tv{linhenlniffe}Nf}tofcIEao(eEe(slITTTTE>{afIt=totnrrnarcehcTtc)n{lmseREEEEIyyt:{FrSgoodfmoff,cDeEa(;teeN=eIIIIR:Ce{a:immeremrutaaId]mna{nRRRReom"mzTroons(tnc=a)etm{doooon"nsci"eE"",m}"mce(aet;n)eeuuuudft:al#:IrC@tt)aaat=wrttttelely3.eET"f/"iT=nw){"reeeeren"c:3".aTE@rc@e=a;="id>xtc(32.cEI/ooni>a=itaeeee":e1""4tIRcmmcDsttitllll,n0A,p"coopoRo{ynena===="t0rx;eum"omecneCig=""""cevi"atp@npn]cwEDM{tttterha,neo/eodTooteeeen"l"ncnne=CEcdeiiiit,-,;}eoterEI.ei----enmsn(RTcq:Edppsr1sftpt{e=Eeuli"ee"2arstsa>Iae"evrg,8none/xc(nrvm"cs"psmteitmt{).yeeonx-en/el.;mSrncmac)s"iteiCuaettopmo"er/sl/oskli}moem,ree/eeneeec>pn"pialtmltSHcaoeofceeeeetTtlnncn"tminmnaMo-etoe,-e/tettLrrn=mntne/ne5(lt{ptetlpt}<(""=Po=i/e"/:Dxt,{}n{rdm;someDeSoiee{clihineuvnguC-etgt"t"xmoti}=}e;/;meneg{rplntihP"eCte"te;ron):rsn|t;snt)"Naen;camnuametlle":lc};>(s(1tn0ru0ilvnlhg);-})12{8px)"}}

Custom Component (Example of p.tsx)

Here is an example for the p tag. By using <TEINodes teiNodes={props.teiNode.childNodes} {...props} />, recursive tag processing was possible.

iie}mmxpppccr)oooooe;rrrnnt<tttssup/ttr<p{{fnsT>utstETgnet(yIEeciylNIttNleoNSioe=dotod{edyne=sseltseP=gyt(ele}}ppteirrS}Nffootorrppycdoossllemm:.east(s=""{ets{r@ieNpe/tNiaraueoNmoctidoeptiNed=s-lo;e".tsd)mte"e;-ei;:1ir"NoC>ouhdtieel.rdc"Nh;oidledN}o)de{s}{...props}

Additional Notes

As a project using this approach, there is “Astro TEI - React,” which utilizes CETEIcean as a React component and maps custom elements to TEI.

https://github.com/raffazizzi/astro-tei/tree/main/packages/react#readme

An Astro component for publishing TEI as Custom Elements powered by CETEIcean.

This utility provides the React version of CETEIcean’s default behaviors and provides a way of mapping your own React components to TEI elements via React TEI Router.

However, for large TEI/XML files, rendering with React TEI Router can lead to excessive recursive processing and performance degradation.

In such cases, it may be better to use CETEIcean alone without using it as a React component.

vC}aE)rTdEoCIcEcuTemEaeInnc.teg.aegnteHt=TEMlnLee5mw(e"nCUtERBTLyE_IITd(O()_"YTOEUIR"_)T.EaIp.pxemnld"C,hifludn(cdtaitoan)(data){

https://next-ceteicean-router.vercel.app/simple/

https://github.com/nakamura196/next-ceteicean-router/blob/main/src/app/simple/page.tsx

Summary

We hope this serves as a useful reference for using TEI/XML with React.