jason-fox / fox.jason.prismjs

An integration of PrismJS into the DITA Open Toolkit engine, enabling static HTML and PDF syntax highlighting.
https://jason-fox.github.io/dita-ot-plugins/prismjs
Apache License 2.0
5 stars 3 forks source link

Leading `..` is removed from relative paths #3

Closed 0xfeedface closed 3 years ago

0xfeedface commented 3 years ago

This seems to have been introduced with b404f8a. We keep all our dita files in subdirs, so URLs when linking a stylesheet or xref-ing another dita file will always start with ../. As of b404f8a, these seem to be removed on pages containing code (other pages are fine).

jason-fox commented 3 years ago

Could you provide a failing test case which demonstrates this so I can investigate further? I have tried to replicate this with the dita files in a new test case found here

I am running DITA-OT 3.6. as shown:

./dita -i ../plugins/fox.jason.prismjs/test/structure/ditamap/document.ditamap -o ../out -f pdf

Raises multiple warnings:

 [gen-list] file:/Users/jasonfox/Workspace/dita/dita-ot-3.6/plugins/fox.jason.prismjs/test/structure/ditamap/document.ditamap:9:65: [DOTJ036W][WARN] The file "file:/Users/jasonfox/Workspace/dita/dita-ot-3.6/plugins/fox.jason.prismjs/test/structure/topics/examples.dita" is outside the scope of the input dita/map directory.

But still highlights correctly. I can't see how the relative path would effect highlighting.

0xfeedface commented 3 years ago

Sorry, I should have mentioned that this is about the html5 trans type. If you run

./dita -i ../plugins/fox.jason.prismjs/test/structure/ditamap/document.ditamap -o ../out -f html5

the code on the example page is not highlighted and the CSS includes are commonltr.css and common-extended.css, instead of ../commonltr.css and ../common-extended.css, respectively.

skulle commented 3 years ago

Hi,

I am running in the same issue. Is there a workaround or a fix I could apply locally?

jason-fox commented 3 years ago

I've not found time to look at this yet, but it is probably an issue in the dependent plugin fox.jason.extend.css

jason-fox commented 3 years ago

It looks like the urltest function has been amended from a boolean to a string, so the check is failing - something like this may work:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">

  <xsl:param name="EXTENDED-CSS" select="'common-extended.css'"/>

  <xsl:template match="/|node()|@*" mode="gen-common-extended-style">
    <xsl:variable name="urltest">
      <xsl:call-template name="url-string">
        <xsl:with-param name="urltext">
          <xsl:value-of select="concat($CSSPATH,$EXTENDED-CSS)"/>
        </xsl:with-param>
      </xsl:call-template>
    </xsl:variable>

    <xsl:variable name="relpath">
     <xsl:value-of select=" replace($FILEDIR,'[^/]+','..')"/>
   </xsl:variable>

   <xsl:choose>
      <xsl:when test="$urltest = 'url'">
        <link rel="stylesheet" type="text/css" href="{$CSSPATH}{$EXTENDED-CSS}" />
      </xsl:when>
      <xsl:otherwise>
        <link rel="stylesheet" type="text/css" href="{$relpath}/{$CSSPATH}{$EXTENDED-CSS}" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>
skulle commented 3 years ago

Hi @jason-fox,

thanks for the quick response. I will try to use the templates tomorrow...

skulle commented 3 years ago

Just re-tested my content with the stylesheet from above and it worked. Thanks ;)

jason-fox commented 3 years ago

Fixed with updating extend.css plugin

dita install https://github.com/jason-fox/fox.jason.extend.css/archive/v1.0.3.zip