Skip to content

Commit

Permalink
Add untested code block highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
vocksel committed Dec 19, 2024
1 parent 914535b commit d130e11
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Common/CodeBlock.luau
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local Highlighter = require("@pkg/Highlighter")
local React = require("@pkg/React")
local Sift = require("@pkg/Sift")

Expand All @@ -6,6 +7,8 @@ local nextLayoutOrder = require("@root/Common/nextLayoutOrder")
local useTheme = require("@root/Common/useTheme")

local useMemo = React.useMemo
local useRef = React.useRef
local useEffect = React.useEffect

local function getLineNumbers(str: string): string
return Sift.List.reduce(str:split("\n"), function(accumulator, _item, index)
Expand All @@ -21,11 +24,20 @@ export type Props = {

local function StoryError(props: Props)
local theme = useTheme()
local ref = useRef(nil :: TextBox?)

local sourceColor = useMemo(function()
return if props.sourceColor then props.sourceColor else theme.text
end, { props.sourceColor })

useEffect(function()
Highlighter.matchStudioSettings()

Highlighter.highlight({
textObject = ref.current,
})
end, {})

return React.createElement("Frame", {
AutomaticSize = Enum.AutomaticSize.XY,
BackgroundTransparency = 0.5,
Expand Down Expand Up @@ -72,6 +84,7 @@ local function StoryError(props: Props)
TextWrapped = false,
LineHeight = 1,
Font = Enum.Font.RobotoMono,
ref = ref,
}),
})
end
Expand Down
1 change: 1 addition & 0 deletions wally.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ReactRoblox = "jsdotlua/[email protected]"
ReactSpring = "chriscerie/[email protected]"
Sift = "csqrl/[email protected]"
t = "osyrisrblx/[email protected]"
Highlighter = "boatbomber/[email protected]"

# dev dependencies
Roact = "roblox/[email protected]"
Expand Down

0 comments on commit d130e11

Please sign in to comment.