Skip to content
This repository was archived by the owner on Aug 24, 2019. It is now read-only.
This repository was archived by the owner on Aug 24, 2019. It is now read-only.

Only a subset of syntax is highlighted #5

Description

@zats

Hi, I was playing around with initial setup of the library.
It seems like the library recognises only a subset of the syntax (while the same file opened in TextMate is showing the full syntax highlight – not sure if it's relevant)

screen shot 2015-06-27 at 3 15 22 pm

This is the code I used (more or less copied from the readme, slightly modified for Swift 2):

letsamplePath= bundle.URLForResource("Sample", withExtension:"swift")!
letsample=try!String(contentsOfURL: samplePath)letlanguagePath= bundle.URLForResource("Swift", withExtension:"tmLanguage")!
letlanguageDictionary=NSDictionary(contentsOfURL: languagePath)as![NSObject:AnyObject]letlanguage=Language(dictionary: languageDictionary)!
letthemeURL= bundle.URLsForResourcesWithExtension("tmTheme", subdirectory:nil)!.first!
letthemeDictioanry=NSDictionary(contentsOfURL: themeURL)as![NSObject:AnyObject]lettheme=Theme(dictionary: themeDictioanry)!
letparse=AttributedParser(language: language, theme: theme)letattributedString= parse.attributedStringForString(sample)

Following is the playground (please rename to .zip and extract).

Is anything I'm doing look obviously wrong?

And a follow up question: is there a smarter way to figure out the language used for a file than the file extension? Extensions might be used by several languages: .h file might be either Objective-C or plain C; while .m is used for both Objective-C and Matlab.

Thanks a lot!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions