-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ func RegisterAll() { | |
SketchDrawing{}, | ||
Slim{}, | ||
XAML{}, | ||
XSLT{}, | ||
} | ||
|
||
// Register all lexers. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0"?> | ||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | ||
|
||
<xsl:output method="text"/> | ||
|
||
<xsl:template match="/"> | ||
Article - <xsl:value-of select="/Article/Title"/> | ||
Authors: <xsl:apply-templates select="/Article/Authors/Author"/> | ||
</xsl:template> | ||
|
||
<xsl:template match="Author"> | ||
- <xsl:value-of select="." /> | ||
</xsl:template> | ||
|
||
</xsl:stylesheet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package chroma | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/wakatime/wakatime-cli/pkg/xml" | ||
|
||
"github.com/alecthomas/chroma/v2" | ||
"github.com/alecthomas/chroma/v2/lexers" | ||
) | ||
|
||
// XSLT lexer. | ||
type XSLT struct{} | ||
|
||
// Register the lexer. | ||
func (XSLT) Register() { | ||
_ = lexers.Register(chroma.MustNewLexer( | ||
&chroma.Config{ | ||
Name: "XSLT", | ||
Aliases: []string{"xslt"}, | ||
// xpl is XProc | ||
Filenames: []string{"*.xsl", "*.xslt", "*.xpl"}, | ||
MimeTypes: []string{"application/xsl+xml", "application/xslt+xml"}, | ||
}, | ||
func() chroma.Rules { | ||
return chroma.Rules{ | ||
"root": {}, | ||
} | ||
}, | ||
)).SetAnalyser(func(text string) float32 { | ||
if xml.MatchString(text) && strings.Contains(text, "<xsl") { | ||
return 0.8 | ||
} | ||
|
||
return 0 | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package chroma_test | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/wakatime/wakatime-cli/pkg/language/chroma" | ||
|
||
c "github.com/alecthomas/chroma/v2" | ||
"github.com/alecthomas/chroma/v2/lexers" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func init() { | ||
chroma.XSLT{}.Register() | ||
} | ||
|
||
func TestXSLT_AnalyseText(t *testing.T) { | ||
data, err := os.ReadFile("testdata/xslt.xsl") | ||
assert.NoError(t, err) | ||
|
||
l := lexers.Get("XSLT") | ||
|
||
analyser, ok := l.(c.Analyser) | ||
assert.True(t, ok) | ||
|
||
assert.Equal(t, float32(0.8), analyser.AnalyseText(string(data))) | ||
} |