Skip to content

Commit

Permalink
Reserve ":" within styled regions of string macro
Browse files Browse the repository at this point in the history
This allows us to potentially add a final format spec to a styling
group (i.e. "{style:content:format}") in future by reserving the use of
un-escaped colons in styled content now.
  • Loading branch information
tecosaur committed Oct 20, 2023
1 parent dec2bdd commit 5dd8b9e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/stylemacro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ macro styled_str(raw_content::String)
end =#

# Instead we'll just use a `NamedTuple`
state = let content = unescape_string(raw_content, ('{', '}', '$', '\n'))
state = let content = unescape_string(raw_content, ('{', '}', ':', '$', '\n'))
(; content, bytes = Vector{UInt8}(content),
s = Iterators.Stateful(zip(eachindex(content), content)),
parts = Any[],
Expand Down Expand Up @@ -221,7 +221,7 @@ macro styled_str(raw_content::String)
end

function escaped!(state, i, char)
if char in ('{', '}', '$', '\\')
if char in ('{', '}', ':', '$', '\\')
deleteat!(state.bytes, i + state.offset[] - 1)
state.offset[] -= ncodeunits('\\')
elseif char == '\n'
Expand Down Expand Up @@ -619,6 +619,8 @@ macro styled_str(raw_content::String)
else
stywarn("contains extranious style terminations", state, 2)
end
elseif char == ':' && !isempty(state.active_styles)
stywarn("colons within styled regions need to be escaped", state, 2)
end
end
# Ensure that any trailing unstyled content is added
Expand Down

0 comments on commit 5dd8b9e

Please sign in to comment.