Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syntax highlighting support for typescript #57

Closed
emmanueltouzery opened this issue Dec 1, 2018 · 10 comments
Closed

syntax highlighting support for typescript #57

emmanueltouzery opened this issue Dec 1, 2018 · 10 comments

Comments

@emmanueltouzery
Copy link

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 through optSyntaxDefinitions. However I think that hakyll calls pandoc another way. I see a call pandocCompilerWith defaultHakyllReaderOptions defaultHakyllWriterOptions which I could customize but I don't see where I could plug optSyntaxDefinitions 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 add Skylighting.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,

So I'm stuck right now :-(

@emmanueltouzery emmanueltouzery changed the title syntax highliighting support for typescript syntax highlighting support for typescript Dec 1, 2018
@emmanueltouzery
Copy link
Author

(there's also a typescript-react file which could be useful although i don't need it myself right now)

@jgm
Copy link
Owner

jgm commented Dec 1, 2018 via email

@emmanueltouzery
Copy link
Author

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.

@jgm
Copy link
Owner

jgm commented Dec 1, 2018 via email

@jgm jgm closed this as completed in 9d5cbda Dec 1, 2018
@fuhrmanator
Copy link

fuhrmanator commented Jun 11, 2021

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:

image

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.

@fuhrmanator
Copy link

Looking more at this, I see that the typescript.xml is supposed to (in KDE) extend the keywords from javascript.xml:

https://github.com/KDE/syntax-highlighting/blob/4e1203e2d985e84e8016ca3211c1f33ce71299e0/data/syntax/typescript.xml#L76-L83

<!-- 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?

@jgm
Copy link
Owner

jgm commented Jun 11, 2021

That's it! We never did support the include element in list contexts.
Why don't you open up a new issue for this?

@jgm
Copy link
Owner

jgm commented Jun 11, 2021

As a workaround you can just copy the list into typescript.xml and use it with --syntax-definition.

@jgm
Copy link
Owner

jgm commented Jun 11, 2021

Looks like typescript.xml uses include extensively.
Less extensively than typescript: raku, tcsh, scala, fortran-free, zsh, groovy.

@fuhrmanator
Copy link

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).

typescript_javascript.xml.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants