Skip to content

Commit

Permalink
feat(at): support for multiple consecutive append-following-sibling p…
Browse files Browse the repository at this point in the history
…aragraphs. Also improved the class names of the entities so their are better grouped and targetted in the CSS.
  • Loading branch information
geoffroy-noel-ddh committed Jul 26, 2024
1 parent ae5b350 commit a8f015b
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 46 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,4 @@ dist

*.sef.json

tmp
1 change: 1 addition & 0 deletions controllers/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ async function getContentFromDocumentId(documentId) {
let ret = cache.lastRead.content;
if (!ret || cache.lastRead.documentId != documentId) {
ret = await corpus.readItemContent(documentId)
// ret = fs.readFileSync('/home/jeff/src/prj/tmp/alice-thornton/texts/00_book_of_remembrances/book_of_remembrances.xml', {encoding:'utf8', flag:'r'})

if (settings.preTransformPath) {
await downloadResources()
Expand Down
46 changes: 35 additions & 11 deletions responses/at-tei-to-tei.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,38 @@
<!-- remove excluded notes, for internal editing purpose only -->
</xsl:template>

<!-- ===============================
append-following-sibling
Will be merged with the following <p> inside a <div> in the modernised rendering.
Note that append-following-sibling can appear on consecutive <p>s
to merge multiple paras together.
This is why the templates below can work recursively.
-->
<xsl:template match="tei:p[contains(@rend, 'append-following-sibling')]">
<!-- First p with rend="append-following-sibling", wrap up in a div -->
<div type="merged-modern-paras">
<xsl:call-template name="copy-element" />
<xsl:apply-templates select="./following-sibling::tei:p[1]" mode="copy-element" />
<!-- re-process as ith p with rend="append-following-sibling" -->
<xsl:apply-templates select="." mode="copy-element" />
</div>
</xsl:template>

<xsl:template match="tei:p[contains(@rend, 'append-following-sibling')]" mode="copy-element" priority="5">
<!-- ith p with rend="append-following-sibling" -->
<xsl:call-template name="copy-element" />
<!-- Recusive part, this may be the terminal p (without @rend) or the i+1th with @rend -->
<xsl:apply-templates select="./following-sibling::tei:p[1]" mode="copy-element" />
</xsl:template>

<xsl:template match="tei:p[contains(@rend, 'append-following-sibling')]/following-sibling::tei:p[1]" mode="copy-element">
<!-- terminal p without @rend -->
<xsl:call-template name="copy-element" />
</xsl:template>

<xsl:template match="tei:p[contains(@rend, 'append-following-sibling')]/following-sibling::tei:p[1]">
<!-- Already copied above -->
<!-- terminal p without @rend, already copied above, inside the div -->
</xsl:template>

<!-- =============================== -->

<xsl:template match="tei:anchor[@resp='ednote']" priority="10">
<!--
Expand All @@ -59,10 +77,10 @@
<p> Thornton is [...]] </p>
</note>
-->
<anchor>
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="key('notes', @corresp)"/>
</anchor>
</xsl:copy>
</xsl:template>

<xsl:template match="(*[@type='person']|*[@type='group']|tei:persName)[@ref]">
Expand All @@ -89,7 +107,8 @@
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates />
<note type="entity">
<note type="person">
<!-- <note type="entity"> -->
<!-- <xsl:value-of select="key('people', @ref, $people)/tei:persName[@type='label']/text()"/> -->
<xsl:for-each select="tokenize(@ref, ' ')">
<p>
Expand All @@ -105,7 +124,8 @@
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates />
<note type="entity">
<note type="place">
<!-- <note type="entity"> -->
<p>
<xsl:attribute name="ref"><xsl:value-of select="@ref"/></xsl:attribute>
<xsl:value-of select="key('places', @ref, $places)/(tei:placeName|tei:geogName)[@type='label']/text()"/>
Expand All @@ -130,12 +150,15 @@
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates />
<note type="entity"><xsl:apply-templates select="$glosses/key('glosses', current()/@ref)/tei:gloss"/></note>
<note type="term"><xsl:apply-templates select="$glosses/key('glosses', current()/@ref)/tei:gloss"/></note>
<!-- <note type="entity"><xsl:apply-templates select="$glosses/key('glosses', current()/@ref)/tei:gloss"/></note> -->
</xsl:copy>
</xsl:template>

<xsl:template match="tei:g[@ref]">
<!--
TODO: not needed? note seems to have been moved editorial note following glyph
<charDecl>
<glyph xml:id="heart">
<desc>Thornton frequently uses the heart symbol instead of the word 'heart' in her books. See <ref target="https://thornton.kdl.kcl.ac.uk/posts/blog/2023-02-13-AliceThorntonsHeart-Blog/">Cordelia Beattie and Suzanne Trill, ‘Alice Thornton’s Heart: An Early Modern Emoji’, <hi rend="italic">Alice Thornton’s Books</hi>, 17 March 2023</ref></desc>
Expand All @@ -150,7 +173,8 @@
<xsl:apply-templates select="@*"/>
<xsl:apply-templates />
<xsl:if test="$desc">
<note type="entity"><xsl:apply-templates select="$desc"/></note>
<!-- <note type="entity"><xsl:apply-templates select="$desc"/></note> -->
<note type="glyph"><xsl:apply-templates select="$desc"/></note>
</xsl:if>
</xsl:copy>
</xsl:template>
Expand Down Expand Up @@ -181,8 +205,8 @@
<xsl:apply-templates />
<span>
<xsl:choose>
<xsl:when test="name() = 'milestone'">[EVENT: </xsl:when>
<xsl:when test="name() = 'anchor'"> :EVENT]</xsl:when>
<xsl:when test="name() = 'milestone'"></xsl:when>
<xsl:when test="name() = 'anchor'"></xsl:when>
</xsl:choose>
</span>
<xsl:variable name="bookkey">
Expand Down
79 changes: 44 additions & 35 deletions responses/tei-to-html.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,23 @@
<xsl:call-template name="lossless-span"><xsl:with-param name="class" select="'has-info-box'"/></xsl:call-template>
</xsl:template> -->

<xsl:template match="tei:anchor[@resp='ednote']">
<span>
<xsl:call-template name="lossless-attributes"><xsl:with-param name="class" select="'has-info-box'"/></xsl:call-template>
<sup class="note-symbol">[<xsl:number count="//tei:anchor[@resp='ednote']" level="any" format="1"/>]</sup>
<xsl:call-template name="process-children" />
</span>
</xsl:template>

<xsl:template match="tei:note">
<span>
<xsl:call-template name="lossless-attributes"><xsl:with-param name="class" select="'info-box'"/></xsl:call-template>
<span class="banner">
<!-- <xsl:value-of select="concat(upper-case(substring(../@type,1,1)),substring(../@type, 2),' ')" /> -->
<xsl:choose>
<xsl:when test="../@resp='ednote'">Note </xsl:when>
<xsl:when test="../@type='context'">Context </xsl:when>
<xsl:when test="@type='event'">Event </xsl:when>
<xsl:when test="../@type='oed'">Definition </xsl:when>
<xsl:when test="@type='term'">Definition </xsl:when>
<xsl:when test="@type='person'">Person </xsl:when>
<xsl:when test="@type='place'">Place </xsl:when>
<xsl:when test="@type='glyph'">Symbol </xsl:when>
<!-- <xsl:when test="../@type='geog'">Place </xsl:when> -->
<xsl:otherwise>(?)</xsl:otherwise>
</xsl:choose>
<!-- <xsl:choose>
<xsl:when test="../@type='oed_context'">Definition </xsl:when>
<xsl:when test="../@type='oed'">Definition </xsl:when>
<xsl:when test="../@type='context'">Context </xsl:when>
Expand All @@ -159,12 +162,13 @@
<xsl:when test="ends-with(../name(), 'term')">Gloss </xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:comment>LEAVE those empty cases in, they prevent the display of others down the list</xsl:comment>
<xsl:when test="ends-with(../name(), 'term')"></xsl:when>
<xsl:when test="../name() = 'g'"></xsl:when>
<xsl:when test="@type='entity'">(Entity)</xsl:when>
<xsl:when test="ends-with(../name(), 'anchor')">Note</xsl:when>
<xsl:otherwise>(?)</xsl:otherwise>
</xsl:choose>
</xsl:choose> -->
</span>
<span class="body">
<xsl:call-template name="process-children" />
Expand All @@ -185,26 +189,25 @@
<xsl:call-template name="lossless-span"/>
</xsl:template>

<xsl:template match="(tei:term|tei:geogName|tei:placeName|tei:rs|tei:persName)[@ref]">
<xsl:call-template name="lossless-span"><xsl:with-param name="class" select="'has-info-box'"/></xsl:call-template>
</xsl:template>
<!-- INFO BOX (entities, events, notes, ...) -->

<xsl:template match="tei:g[@ref]">
<xsl:call-template name="lossless-span"><xsl:with-param name="class" select="'has-info-box'"/></xsl:call-template>
<xsl:template match="*[tei:note[@type='entity' or @type='glyph' or @type='term' or @type='person' or @type='place']]" priority="2">
<xsl:call-template name="lossless-span">
<xsl:with-param name="class" select="concat('has-info-box is-', ./tei:note/@type)"/>
</xsl:call-template>
</xsl:template>

<!-- <xsl:template match="(tei:geogName|tei:placeName|tei:rs|tei:persName)[@ref]">
<span><xsl:call-template name="lossless-attributes"/><xsl:call-template name="process-children" /><a>
<xsl:attribute name="href">
<xsl:value-of select="concat('/entities/?q=', translate(@ref, ':', ':'))" />
</xsl:attribute>
<xsl:template match="tei:anchor[@resp='ednote']" priority="4">
<span>
<xsl:call-template name="lossless-attributes"><xsl:with-param name="class" select="'has-info-box is-note'"/></xsl:call-template>
<sup class="note-symbol">[<xsl:number count="//tei:anchor[@resp='ednote']" level="any" format="1"/>]</sup>
<xsl:call-template name="process-children" />
</a></span>
</xsl:template> -->
</span>
</xsl:template>

<xsl:template match="tei:quote">
<span>
<xsl:call-template name="lossless-attributes"><xsl:with-param name="class" select="'has-info-box'"/></xsl:call-template>
<xsl:call-template name="lossless-attributes"><xsl:with-param name="class" select="'has-info-box is-quote'"/></xsl:call-template>
<xsl:call-template name="process-children" />
<span class="info-box">
<span class="banner">Biblical reference</span>
Expand All @@ -219,6 +222,24 @@
</span>
</xsl:template>

<!-- <xsl:template match="(tei:term|tei:geogName|tei:placeName|tei:rs|tei:persName)[@ref]">
<xsl:call-template name="lossless-span"><xsl:with-param name="class" select="'has-info-box'"/></xsl:call-template>
</xsl:template>
<xsl:template match="tei:g[@ref]">
<xsl:call-template name="lossless-span"><xsl:with-param name="class" select="'has-info-box'"/></xsl:call-template>
</xsl:template> -->

<xsl:template match="tei:milestone[@unit='event']" priority="4">
<xsl:call-template name="lossless-span"><xsl:with-param name="class" select="'has-info-box is-event event-start'"/></xsl:call-template>
</xsl:template>

<xsl:template match="tei:anchor[@type='event']" priority="4">
<xsl:call-template name="lossless-span"><xsl:with-param name="class" select="'has-info-box is-event event-end'"/></xsl:call-template>
</xsl:template>

<!-- =============================== -->

<xsl:template match="tei:figure">
<div class="tei-figure-wrapper">
<a href="#" class="btn-figure"><i class="fas fa-image"></i><span class="is-sr-only">Photograph of the manuscript page</span></a>
Expand Down Expand Up @@ -275,16 +296,4 @@
</span>
</xsl:template>

<!-- EVENTS -->

<xsl:template match="tei:milestone[@unit='event']">
<xsl:call-template name="lossless-span"><xsl:with-param name="class" select="'event event-start has-info-box'"/></xsl:call-template>
</xsl:template>

<xsl:template match="tei:anchor[@type='event']">
<xsl:call-template name="lossless-span"><xsl:with-param name="class" select="'event event-end has-info-box'"/></xsl:call-template>
</xsl:template>

<!-- ============================================ -->

</xsl:stylesheet>

0 comments on commit a8f015b

Please sign in to comment.