<commit_before><?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
  xmlns:c="http://www.w3.org/ns/xproc-step" 
  xmlns:cx="http://xmlcalabash.com/ns/extensions" 
  xmlns:tr="http://transpect.io" 
  xmlns:css="http://www.w3.org/1996/css" 
  xmlns:epub="http://transpect.io/epubtools"
  version="1.0" 
  name="insert-amzn-region-magnification"
  type="epub:insert-amzn-region-magnification">
  
  <p:documentation xmlns="http://www.w3.org/1999/xhtml">
    If the option <code>amzn-region-magnification</code> has the value <code>true</code>, 
    this option inserts in each HTML file the markup for Amazon's Region Magnification featue. 
    Since
  </p:documentation>
  
  <p:input port="source" sequence="true">
    <p:documentation>
      A sequence of documents with certain base URIs
    </p:documentation>
  </p:input>
  
  <p:output port="result" sequence="true">
    <p:documentation>
      Sequence of HTML chunks, optionally with Amazon region-magnification markup.
    </p:documentation>
  </p:output>
  
  <p:option name="amzn-region-magnification" select="'false'">
    <p:documentation xmlns="http://www.w3.org/1999/xhtml">
      Declare this option in your epubtools configuration file as attribute of the root element.
    <pre><code>&lt;epub-config format="EPUB3" 
  layout="fixed" 
  indent="selective" 
  page-map-xml="false"
  css-handling="unchanged"
  amzn-region-magnification="true">
  &lt;!-- ... -->
  &lt;/epub-config></code></pre>
    </p:documentation>
  </p:option>
  
  <p:option name="debug" select="'no'"/>
  <p:option name="debug-dir-uri" select="'debug'"/>
  
  <p:for-each>
    <p:output port="result" sequence="true"/>
    <p:iteration-source>
      <p:pipe port="source" step="insert-amzn-region-magnification"/>
    </p:iteration-source>
    
    <cx:message>
      <p:with-option name="message" select="'[info] insert Amazon Region Magnification markup to file: ', replace(base-uri(), '^.+/', '')"/>
    </cx:message>
    
    <p:choose>
      <p:when test="$amzn-region-magnification eq 'true' and matches(base-uri(), '\.xhtml$') and not(matches(base-uri(), '(cover|nav)\.xhtml$'))">
        
        <cx:message>
          <p:with-option name="message" select="'[info] insert Amazon Region Magnification markup to file: ', replace(base-uri(), '^.+/', '')"/>
        </cx:message>
        
        <p:xslt>
          <p:input port="stylesheet">
            <p:document href="../xsl/insert-amzn-region-magnification.xsl"/>
          </p:input>
          <p:input port="parameters">
            <p:empty/>
          </p:input>
        </p:xslt>
        
      </p:when>
      <p:otherwise>
        <p:identity/>     
      </p:otherwise>
    </p:choose>
    
  </p:for-each>
  
</p:declare-step><commit_msg>output generated css files for Region Magnification<commit_after><?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" 
  xmlns:c="http://www.w3.org/ns/xproc-step"
  xmlns:cx="http://xmlcalabash.com/ns/extensions" 
  xmlns:tr="http://transpect.io" 
  xmlns:epub="http://transpect.io/epubtools"
  version="1.0" name="insert-amzn-region-magnification" type="epub:insert-amzn-region-magnification">

  <p:documentation xmlns="http://www.w3.org/1999/xhtml"> This pipeline adds Amazon's Region Magnification markup to each
    <code>div</code> which includes the <code>magnification</code> class:
    <pre><code>&lt;div class="magnification">
  &lt;p id="p-1-02">A quick brown fox jumps over a lazy dog.&lt;/p>
&lt;/div></code></pre>
    <p>The script adds Region Magnification markup according to <a href="https://kindlegen.s3.amazonaws.com/AmazonKindlePublishingGuidelines.pdf" target="_blank">Amazon's Kindle Publishing Guidelines</a>.
    </p>
    <pre><code>&lt;div id="amzn-id-myBook-1-txt" class="source-mag">&lt;a class="app-amzn-magnify" data-app-amzn-magnify="{&#34;targetId&#34;:&#34;magTarget-amzn-id-myBook\
      _000019-1&#34;,&#34;sourceId&#34;:&#34;magSource-amzn-id-myBook-1&#34;,&#34;ordinal&#34;:1}">
  &lt;p id="p-1-02">A quick brown fox jumps over a lazy dog.&lt;/p>
&lt;/a>&lt;/div>&lt;div id="amzn-id-myBook-1-magTarget" class="target-mag">
  &lt;p>A quick brown fox jumps over a lazy dog.&lt;/p>
&lt;/div></code></pre>
    <p>Please note that you later need to execute a bash script which escapes the quotes. The script can be found here: <code>scripts/escape-for-amzn-region-magnification.sh</code></p>
  </p:documentation>

  <p:input port="source" sequence="true">
    <p:documentation> A sequence of documents with certain base URIs </p:documentation>
  </p:input>

  <p:output port="result" sequence="true">
    <p:documentation> Sequence of HTML chunks, optionally with Amazon region-magnification markup. </p:documentation>
  </p:output>

  <p:option name="amzn-region-magnification" select="'false'">
    <p:documentation xmlns="http://www.w3.org/1999/xhtml"> Declare this meta tag in your epubtools configuration file
      to apply Region Magnification Markup.
      <pre><code>&lt;metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf"> 
  &lt;meta name="RegionMagnification" content="true"/>
  &lt;!-- ... -->
&lt;/metadata></code></pre>
    </p:documentation>
  </p:option>

  <p:option name="debug" select="'no'"/>
  <p:option name="debug-dir-uri" select="'debug'"/>

  <p:for-each name="file-iteration">
    
    <p:iteration-source>
      <p:pipe port="source" step="insert-amzn-region-magnification"/>
    </p:iteration-source>

    <p:choose name="choose">
      <p:when test="$amzn-region-magnification eq 'true' and not(contains(base-uri(), $debug-dir-uri))">
        <p:output port="result" sequence="true" primary="true">
          <p:pipe port="result" step="xslt"/>
          <p:pipe port="secondary" step="xslt"/>
        </p:output>

        <cx:message>
          <p:with-option name="message"
            select="'[info] add Region Magnification markup to file: ', replace(base-uri(), '^.+/', '')"/>
        </cx:message>

        <p:xslt name="xslt">
          <p:input port="stylesheet">
            <p:document href="../xsl/insert-amzn-region-magnification.xsl"/>
          </p:input>
          <p:input port="parameters">
            <p:empty/>
          </p:input>
        </p:xslt>

      </p:when>
      <p:otherwise>
        <p:output port="result" sequence="true" primary="true"/>

        <p:identity/>

      </p:otherwise>
    </p:choose>

  </p:for-each>

</p:declare-step>
{'fraction_non_alphanumeric': 0.1891642296444513, 'fraction_numerical': 0.012929044174234261, 'mean_word_length': 3.4294478527607364, 'pattern_counts': {'":': 0, '<': 128, '<?xml version=': 2, '>': 149, 'https://': 1, 'lorem ipsum': 0, 'www.': 10, 'xml': 22}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2891075', 'n_tokens_mistral': 2385, 'n_tokens_neox': 2193, 'n_words': 408}