Closed emmanueltouzery closed 5 years ago
(there's also a typescript-react file which could be useful although i don't need it myself right now)
emmanueltouzery notifications@github.com writes:
so, KDE has a syntax highlight file for typescript:
https://github.com/KDE/syntax-highlighting/blob/master/data/syntax/typescript.xml
But skylighting doesn't include it. I think typescript is popular enough to warrant it, but if it's not, I'm interested how could I still fulfill my use-case...
I'd be happy to add it.
My use-case is a hakyll blog in which I would add typescript samples. Now.. I see that pandoc has the
--syntax-definition
command-line option, so I could use the XML file directly by hand, and as far as I can tell this is reachable through the pandoc API throughoptSyntaxDefinitions
. However I think that hakyll calls pandoc another way. I see a callpandocCompilerWith defaultHakyllReaderOptions defaultHakyllWriterOptions
which I could customize but I don't see where I could plugoptSyntaxDefinitions
there. Also I'm not sure the extra syntax definitions would only active for typescript blocks..
You need to ask hakyll people about that.
I tried to clone
skylighting
and add typescript.xml and addSkylighting.Syntax.Typescript
in the skylighting cabal file and put my modified skylighting-core as a dependency, but the pandoc I got still didn't know about typescript.Then I added also my modified skylighting as a dependency, but it fails to build:
Preprocessing library for skylighting-0.7.4.. Cabal-simple_mPHDZzAJ_2.2.0.1_ghc-8.4.4: can't find source for Skylighting/Syntax in src,
I think the issue is that stack doesn't know to do a "bootstrap build." To solve this, after you've built your modified skylighting-core, do a cabal sdist to create a distribution tarball, and give stack the path to that...
thank you for the feedback! I've now tried to run stack test
in skylighting-core after adding typescript.xml
and I noticed this test failure:
TypeScript: FAIL
test/test-skylighting.hs:188:
Unexpected error: IncludeRules in TypeScript requires undefined context FindStrings##JavaScript
input = "let characters = \"BO XK DQ CP NA GT RE TG QD FS JW HU VI AN OB ER FS LY PC ZM\";\nlet blocks = characters.split(\" \").map(pair => pair.split(\"\"));\n \nfunction isWordPossible(word) {\n var letters = [...word.toUpperCase()];\n var length = letter"
Indeed I see this in typescript.xml from KDE =>
<context name="FindStrings" attribute="Normal Text" lineEndContext="#stay">
<DetectChar context="Template" attribute="Template" char="`" />
<IncludeRules context="FindStrings##JavaScript" />
</context>
I have no idea what this means :-(
I'll contact the hakyll developers regarding exposing this syntax-definition option for hakyll users. I was under the impression that hakyll offers like two APIs and one one exported the syntax-definition option. All the Ext_
options for instance are reachable from hakyll already. Anyway, I'll open a bug there too, but I'm still interested in getting typescript in pandoc if it's not too hard.
I'm adding typescript now. The error is because the javascript definition also needs updating.
emmanueltouzery notifications@github.com writes:
thank you for the feedback! I've now tried to run
stack test
in skylighting-core after addingtypescript.xml
and I noticed this test failure:TypeScript: FAIL test/test-skylighting.hs:188: Unexpected error: IncludeRules in TypeScript requires undefined context FindStrings##JavaScript input = "let characters = \"BO XK DQ CP NA GT RE TG QD FS JW HU VI AN OB ER FS LY PC ZM\";\nlet blocks = characters.split(\" \").map(pair => pair.split(\"\"));\n \nfunction isWordPossible(word) {\n var letters = [...word.toUpperCase()];\n var length = letter"
Indeed I see this in typescript.xml from KDE =>
<context name="FindStrings" attribute="Normal Text" lineEndContext="#stay"> <DetectChar context="Template" attribute="Template" char="`" /> <IncludeRules context="FindStrings##JavaScript" /> </context>
I have no idea what this means :-(
I'll contact the hakyll developers regarding exposing this syntax-definition option for hakyll users. I was under the impression that hakyll offers like two APIs and one one exported the syntax-definition option. All the
Ext_
options for instance are reachable from hakyll already. Anyway, I'll open a bug there too, but I'm still interested in getting typescript in pandoc if it's not too hard.-- You are receiving this because you commented. Reply to this email directly or view it on GitHub: https://github.com/jgm/skylighting/issues/57#issuecomment-443455257
I'm using this feature now, and it seems to be out of date (maybe it's the KDE definitions that are old)?
Here's how the syntax highlighting looks in GitHub:
// sample1.ts
export interface StringValidator {
isAcceptable(s: string): boolean;
}
// sample2.ts
import { StringValidator } from 'sample1'
Here's how it looks in LaTeX/PDF:
It seems like import
and interface
are not recognized as keywords in https://github.com/KDE/syntax-highlighting/blob/master/data/syntax/typescript.xml, yet they're in the https://github.com/KDE/syntax-highlighting/blob/master/data/syntax/javascript.xml version (as strict or reserved/future words). I get the impression the typescript.xml file didn't get the love it needs, but KDE syntax highlighting is not something I've done before.
I am trying to link to this description from the bug (issue) at KDE.org.
Looking more at this, I see that the typescript.xml is supposed to (in KDE) extend the keywords from javascript.xml:
<!-- Include all JavaScript keywords! -->
<list name="controlflow">
<include>controlflow##JavaScript</include>
<item>goto</item>
</list>
<list name="keywords">
<include>keywords##JavaScript</include>
</list>
Is it possible that the include isn't working via skylighter?
That's it! We never did support the include element in list contexts. Why don't you open up a new issue for this?
As a workaround you can just copy the list into typescript.xml and use it with --syntax-definition
.
Looks like typescript.xml uses include extensively. Less extensively than typescript: raku, tcsh, scala, fortran-free, zsh, groovy.
As a workaround you can just copy the list into typescript.xml and use it with
--syntax-definition
.
I'm attaching the result in case someone wants to use it (maybe you must rename it to a .xml
file -- GitHub wouldn't accept a .xml
file, so I renamed it to .txt
).
so, KDE has a syntax highlight file for typescript:
https://github.com/KDE/syntax-highlighting/blob/master/data/syntax/typescript.xml
But skylighting doesn't include it. I think typescript is popular enough to warrant it, but if it's not, I'm interested how could I still fulfill my use-case...
My use-case is a hakyll blog in which I would add typescript samples. Now.. I see that pandoc has the
--syntax-definition
command-line option, so I could use the XML file directly by hand, and as far as I can tell this is reachable through the pandoc API throughoptSyntaxDefinitions
. However I think that hakyll calls pandoc another way. I see a callpandocCompilerWith defaultHakyllReaderOptions defaultHakyllWriterOptions
which I could customize but I don't see where I could plugoptSyntaxDefinitions
there. Also I'm not sure the extra syntax definitions would only active for typescript blocks..I tried to clone
skylighting
and add typescript.xml and addSkylighting.Syntax.Typescript
in the skylighting cabal file and put my modified skylighting-core as a dependency, but the pandoc I got still didn't know about typescript.Then I added also my modified skylighting as a dependency, but it fails to build:
So I'm stuck right now :-(