Changeset 391c90a


Ignore:
Timestamp:
08/10/10 23:19:47 (4 years ago)
Author:
Aurélien Bompard <aurelien@…>
Branches:
master
Children:
07f45f5
Parents:
d577fa9
git-author:
Aurélien Bompard <aurelien@…> (08/10/10 23:19:47)
git-committer:
Aurélien Bompard <aurelien@…> (08/10/10 23:19:47)
Message:

More syntax coloration

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • tests/data/1.xml

    r6734727 r391c90a  
    603603Perl: 
    604604</text:p> 
    605 <text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" text:style-name="Preformatted_20_Text"><text:span text:style-name="strong">my</text:span> ($test) <text:span text:style-name="strong">=</text:span> <text:span text:style-name="syntax-highlight.int">0</text:span>;<text:line-break/><text:span text:style-name="strong">if</text:span> ($test <text:span text:style-name="strong">&gt;</text:span> <text:span text:style-name="syntax-highlight.int">0</text:span>) {<text:line-break/>    <text:span text:style-name="strong">print</text:span> <text:span text:style-name="syntax-highlight.string">"hello"</text:span>;<text:line-break/>}</text:p><text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" text:style-name="Text_20_body"> 
     605<text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" text:style-name="Preformatted_20_Text"><text:span text:style-name="strong">my</text:span> ($test) <text:span text:style-name="strong">=</text:span> <text:span text:style-name="syntax-highlight.number">0</text:span>;<text:line-break/><text:span text:style-name="strong">if</text:span> ($test <text:span text:style-name="strong">&gt;</text:span> <text:span text:style-name="syntax-highlight.number">0</text:span>) {<text:line-break/>    <text:span text:style-name="strong">print</text:span> <text:span text:style-name="syntax-highlight.string">"hello"</text:span>;<text:line-break/>}</text:p><text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" text:style-name="Text_20_body"> 
    606606See <text:a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="/wiki/WikiProcessors">WikiProcessors</text:a> for more information. 
    607607</text:p> 
  • tests/test_specific.py

    r6734727 r391c90a  
    2424        self.assertEquals(str(odt),"") 
    2525 
    26     def test_highlight_k(self): 
    27         html = '<html xmlns="http://www.w3.org/1999/xhtml"><div class="code"><pre><span class="k">Test</span></pre></div></html>' 
     26 
     27class SpecificPygments(unittest.TestCase): 
     28 
     29    def _test_mapping(self, css, odtstyle): 
     30        html = '<html xmlns="http://www.w3.org/1999/xhtml"><div class="code"><pre><span class="%s">Test</span></pre></div></html>' % css 
    2831        odt = xhtml2odt(html) 
    2932        print odt 
    3033        self.assertEquals(str(odt), """<?xml version="1.0" encoding="utf-8"?> 
    3134<text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" text:style-name="Preformatted_20_Text"> 
    32   <text:span text:style-name="strong">Test</text:span> 
     35  <text:span text:style-name="%s">Test</text:span> 
    3336</text:p> 
    34 """) 
     37""" % odtstyle) 
     38 
     39    def test_highlight_k(self): 
     40        self._test_mapping("k", "strong") 
     41 
     42    def test_highlight_kn(self): 
     43        self._test_mapping("kn", "strong") 
    3544 
    3645    def test_highlight_nc(self): 
    37         html = '<html xmlns="http://www.w3.org/1999/xhtml"><div class="code"><pre><span class="nc">Test</span></pre></div></html>' 
    38         odt = xhtml2odt(html) 
    39         print odt 
    40         self.assertEquals(str(odt), """<?xml version="1.0" encoding="utf-8"?> 
    41 <text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" text:style-name="Preformatted_20_Text"> 
    42   <text:span text:style-name="syntax-highlight.class">Test</text:span> 
    43 </text:p> 
    44 """) 
     46        self._test_mapping("nc", "syntax-highlight.class") 
     47 
     48    def test_highlight_nf(self): 
     49        self._test_mapping("nf", "syntax-highlight.function") 
     50 
     51    def test_highlight_nt(self): 
     52        self._test_mapping("nt", "syntax-highlight.tag") 
     53 
     54    def test_highlight_na(self): 
     55        self._test_mapping("na", "syntax-highlight.attr") 
     56 
     57    def test_highlight_nb(self): 
     58        self._test_mapping("nb", "syntax-highlight.builtin") 
     59 
     60    def test_highlight_nn(self): 
     61        self._test_mapping("nn", "syntax-highlight.namespace") 
     62 
     63    def test_highlight_ne(self): 
     64        self._test_mapping("ne", "syntax-highlight.exception") 
    4565 
    4666    def test_highlight_p(self): 
     
    5272""") 
    5373 
    54     def test_highlight_nf(self): 
    55         html = '<html xmlns="http://www.w3.org/1999/xhtml"><div class="code"><pre><span class="nf">Test</span></pre></div></html>' 
    56         odt = xhtml2odt(html) 
    57         print odt 
    58         self.assertEquals(str(odt), """<?xml version="1.0" encoding="utf-8"?> 
    59 <text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" text:style-name="Preformatted_20_Text"> 
    60   <text:span text:style-name="syntax-highlight.function">Test</text:span> 
    61 </text:p> 
    62 """) 
    63  
    6474    def test_highlight_bp(self): 
    65         html = '<html xmlns="http://www.w3.org/1999/xhtml"><div class="code"><pre><span class="bp">Test</span></pre></div></html>' 
    66         odt = xhtml2odt(html) 
    67         print odt 
    68         self.assertEquals(str(odt), """<?xml version="1.0" encoding="utf-8"?> 
    69 <text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" text:style-name="Preformatted_20_Text"> 
    70   <text:span text:style-name="syntax-highlight.builtin.pseudo">Test</text:span> 
    71 </text:p> 
    72 """) 
     75        self._test_mapping("bp", "syntax-highlight.builtin.pseudo") 
    7376 
    7477    def test_highlight_s(self): 
    75         html = '<html xmlns="http://www.w3.org/1999/xhtml"><div class="code"><pre><span class="s">Test</span></pre></div></html>' 
    76         odt = xhtml2odt(html) 
    77         print odt 
    78         self.assertEquals(str(odt), """<?xml version="1.0" encoding="utf-8"?> 
    79 <text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" text:style-name="Preformatted_20_Text"> 
    80   <text:span text:style-name="syntax-highlight.string">Test</text:span> 
    81 </text:p> 
    82 """) 
     78        self._test_mapping("s", "syntax-highlight.string") 
     79 
     80    def test_highlight_sd(self): 
     81        self._test_mapping("sd", "syntax-highlight.string") 
     82 
     83    def test_highlight_si(self): 
     84        self._test_mapping("si", "syntax-highlight.string") 
     85 
     86    def test_highlight_se(self): 
     87        self._test_mapping("se", "syntax-highlight.string") 
    8388 
    8489    def test_highlight_o(self): 
    85         html = '<html xmlns="http://www.w3.org/1999/xhtml"><div class="code"><pre><span class="o">Test</span></pre></div></html>' 
    86         odt = xhtml2odt(html) 
    87         print odt 
    88         self.assertEquals(str(odt), """<?xml version="1.0" encoding="utf-8"?> 
    89 <text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" text:style-name="Preformatted_20_Text"> 
    90   <text:span text:style-name="strong">Test</text:span> 
    91 </text:p> 
    92 """) 
     90        self._test_mapping("o", "strong") 
     91 
     92    def test_highlight_ow(self): 
     93        self._test_mapping("ow", "strong") 
     94 
     95    def test_highlight_c(self): 
     96        self._test_mapping("c", "syntax-highlight.comment") 
     97 
     98    def test_highlight_err(self): 
     99        self._test_mapping("err", "syntax-highlight.error") 
     100 
     101    def test_highlight_mi(self): 
     102        self._test_mapping("mi", "syntax-highlight.number") 
     103 
     104    def test_highlight_mf(self): 
     105        self._test_mapping("mf", "syntax-highlight.number") 
    93106 
    94107 
  • xsl/specific/pygments.xsl

    r6734727 r391c90a  
    113113</xsl:template> 
    114114 
     115<!-- Name.Exception --> 
     116<xsl:template match="h:div[@class='code']/h:pre/h:span[@class='ne']" mode="inparagraph"> 
     117    <text:span text:style-name="syntax-highlight.exception"> 
     118        <xsl:apply-templates mode="inparagraph"/> 
     119    </text:span> 
     120</xsl:template> 
     121 
    115122<!-- Punctuation --> 
    116123<xsl:template match="h:div[@class='code']/h:pre/h:span[@class='p']" mode="inparagraph"> 
     
    132139</xsl:template> 
    133140 
     141<!-- String.Double --> 
     142<xsl:template match="h:div[@class='code']/h:pre/h:span[@class='sd']" mode="inparagraph"> 
     143    <text:span text:style-name="syntax-highlight.string"> 
     144        <xsl:apply-templates mode="inparagraph"/> 
     145    </text:span> 
     146</xsl:template> 
     147 
     148<!-- String.Interpol --> 
     149<xsl:template match="h:div[@class='code']/h:pre/h:span[@class='si']" mode="inparagraph"> 
     150    <text:span text:style-name="syntax-highlight.string"> 
     151        <xsl:apply-templates mode="inparagraph"/> 
     152    </text:span> 
     153</xsl:template> 
     154 
     155<!-- String.Escape --> 
     156<xsl:template match="h:div[@class='code']/h:pre/h:span[@class='se']" mode="inparagraph"> 
     157    <text:span text:style-name="syntax-highlight.string"> 
     158        <xsl:apply-templates mode="inparagraph"/> 
     159    </text:span> 
     160</xsl:template> 
     161 
    134162<!-- Operator --> 
    135163<xsl:template match="h:div[@class='code']/h:pre/h:span[@class='o']" mode="inparagraph"> 
     164    <text:span text:style-name="strong"> 
     165        <xsl:apply-templates mode="inparagraph"/> 
     166    </text:span> 
     167</xsl:template> 
     168 
     169<!-- Operator.Word --> 
     170<xsl:template match="h:div[@class='code']/h:pre/h:span[@class='ow']" mode="inparagraph"> 
    136171    <text:span text:style-name="strong"> 
    137172        <xsl:apply-templates mode="inparagraph"/> 
     
    155190<!-- Number.Integer --> 
    156191<xsl:template match="h:div[@class='code']/h:pre/h:span[@class='mi']" mode="inparagraph"> 
    157     <text:span text:style-name="syntax-highlight.int"> 
     192    <text:span text:style-name="syntax-highlight.number"> 
    158193        <xsl:apply-templates mode="inparagraph"/> 
    159194    </text:span> 
     
    162197<!-- Number.Float --> 
    163198<xsl:template match="h:div[@class='code']/h:pre/h:span[@class='mf']" mode="inparagraph"> 
    164     <text:span text:style-name="syntax-highlight.float"> 
     199    <text:span text:style-name="syntax-highlight.number"> 
    165200        <xsl:apply-templates mode="inparagraph"/> 
    166201    </text:span> 
  • xsl/styles/highlight.xsl

    r6734727 r391c90a  
    9090    </xsl:if> 
    9191 
     92    <xsl:if test="count(//office:automatic-styles/style:style[@style:name = 'syntax-highlight.exception']) = 0"> 
     93        <style:style style:name="syntax-highlight.exception" style:family="text"> 
     94            <style:text-properties fo:color="#990000" 
     95                                   fo:font-weight="bold"/> 
     96        </style:style> 
     97    </xsl:if> 
     98 
    9299    <xsl:if test="count(//office:automatic-styles/style:style[@style:name = 'syntax-highlight.builtin.pseudo']) = 0"> 
    93100        <style:style style:name="syntax-highlight.builtin.pseudo" style:family="text"> 
     
    116123    </xsl:if> 
    117124 
    118     <xsl:if test="count(//office:automatic-styles/style:style[@style:name = 'syntax-highlight.int']) = 0"> 
    119         <style:style style:name="syntax-highlight.int" style:family="text"> 
    120             <style:text-properties fo:color="#009999"/> 
    121         </style:style> 
    122     </xsl:if> 
    123  
    124     <xsl:if test="count(//office:automatic-styles/style:style[@style:name = 'syntax-highlight.float']) = 0"> 
    125         <style:style style:name="syntax-highlight.float" style:family="text"> 
     125    <xsl:if test="count(//office:automatic-styles/style:style[@style:name = 'syntax-highlight.number']) = 0"> 
     126        <style:style style:name="syntax-highlight.number" style:family="text"> 
    126127            <style:text-properties fo:color="#009999"/> 
    127128        </style:style> 
Note: See TracChangeset for help on using the changeset viewer.