joshdholtz / DeckUI

Swift DSL for writing slide decks in Xcode
MIT License
601 stars 27 forks source link

Syntax highlighting for Swift code #16

Closed yonomitt closed 1 year ago

yonomitt commented 1 year ago

This PR adds support for syntax highlighting for Swift code. There is a new parameter on Code.init() called language. This is an enum, which can currently be set to .swift and .none for no syntax highlighting.

This closes issue #8

I'm not 100% happy with the API, as the language parameter is currently at the end of the parameter list for Code.init(), which if you have a large string of code before that, it can be kind of "lost".

Additionally, I think there are two different functions with similar names: enableHighlight, which allows you to select single lines of code to go through and syntax highlighting, which is to make colorful code. This may be something that should be looked into.

I'm 100% open to suggestions to either of these two deficiencies (in my view). If no one else thinks they're problematic, I'm happy to go with the group on this one.

https://user-images.githubusercontent.com/8521453/189717086-c5c0d26d-b0b0-4a8f-aa65-14e5438d9373.mov

DanielSincere commented 1 year ago

Love it! 💜

DanielSincere commented 1 year ago

For anyone trying out this branch, remember to update your theme! code: .xcodeDark,

yonomitt commented 1 year ago

I think I added a code theme to the default .dark, but I didn't touch any of the other themes.

This definitely needs to be documented at some point 😀

DanielSincere commented 1 year ago

@yonomitt 'CodeTheme' initializer is inaccessible due to 'internal' protection level 🙈

Could you kindly add a public member-wise initializer?

 public init(font: SwiftUI.Font, plainTextColor: SwiftUI.Color, backgroundColor: SwiftUI.Color, tokenColors: [TokenType : SwiftUI.Color]) {
    self.font = font
    self.plainTextColor = plainTextColor
    self.backgroundColor = backgroundColor
    self.tokenColors = tokenColors
  }
DanielSincere commented 1 year ago

Just presented a talk using this code and it went great! +1 to merge

joshdholtz commented 1 year ago

@FullQueueDeveloper Did you really give a talk with DeckUI?! I would love to link to it from the README if you would like to share it in any form 😊😊😊😊😊😊😊

yonomitt commented 1 year ago

@yonomitt 'CodeTheme' initializer is inaccessible due to 'internal' protection level 🙈

Could you kindly add a public member-wise initializer?

 public init(font: SwiftUI.Font, plainTextColor: SwiftUI.Color, backgroundColor: SwiftUI.Color, tokenColors: [TokenType : SwiftUI.Color]) {
    self.font = font
    self.plainTextColor = plainTextColor
    self.backgroundColor = backgroundColor
    self.tokenColors = tokenColors
  }

Good point! I'll add this shortly

DanielSincere commented 1 year ago

@FullQueueDeveloper Did you really give a talk with DeckUI?! I would love to link to it from the README if you would like to share it in any form 😊😊😊😊😊😊😊

@joshdholtz yes I did! I'll ping you when the meetup organizers post the recording 😍 And I would be honored for a link in your README ✨

DanielSincere commented 1 year ago

@FullQueueDeveloper Did you really give a talk with DeckUI?! I would love to link to it from the README if you would like to share it in any form 😊😊😊😊😊😊😊

Yes, would love a link in your README!

The video is up! https://www.youtube.com/watch?v=SxozYjWMhgU

Also, I published my deck as well! https://github.com/FullQueueDeveloper/Deck-2022-09-13