Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export function setAnalysisLocale(locale?: string): void {

const arabicScriptRe = /\p{Script=Arabic}/u
const combiningMarkRe = /\p{M}/u
const currencySymbolRe = /\p{Sc}/u
const decimalDigitRe = /\p{Nd}/u

function containsArabicScript(text: string): boolean {
Expand Down Expand Up @@ -270,7 +271,7 @@ function isLeftStickyPunctuationSegment(segment: string): boolean {
if (isEscapedQuoteClusterSegment(segment)) return true
let sawPunctuation = false
for (const ch of segment) {
if (leftStickyPunctuation.has(ch)) {
if (leftStickyPunctuation.has(ch) || currencySymbolRe.test(ch)) {
sawPunctuation = true
continue
}
Expand All @@ -290,7 +291,7 @@ function isCJKLineStartProhibitedSegment(segment: string): boolean {
function isForwardStickyClusterSegment(segment: string): boolean {
if (isEscapedQuoteClusterSegment(segment)) return true
for (const ch of segment) {
if (!kinsokuEnd.has(ch) && !forwardStickyGlue.has(ch) && !combiningMarkRe.test(ch)) return false
if (!kinsokuEnd.has(ch) && !forwardStickyGlue.has(ch) && !combiningMarkRe.test(ch) && !currencySymbolRe.test(ch)) return false
}
return segment.length > 0
}
Expand Down
10 changes: 10 additions & 0 deletions src/layout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,16 @@ describe('prepare invariants', () => {
expect(prepared.segments).toEqual(['say', ' ', String.raw`\"hello\"`, ' ', 'there'])
})

test('keeps prefix currency symbols attached to the following number', () => {
const prepared = prepareWithSegments('costs $500 today', FONT)
expect(prepared.segments).toEqual(['costs', ' ', '$500', ' ', 'today'])
})

test('keeps postfix currency symbols attached to the preceding number', () => {
const prepared = prepareWithSegments('price 500€ each', FONT)
expect(prepared.segments).toEqual(['price', ' ', '500€', ' ', 'each'])
})

test('keeps URL-like runs together as one breakable segment', () => {
const prepared = prepareWithSegments('see https://example.com/reports/q3?lang=ar&mode=full now', FONT)
expect(prepared.segments).toEqual([
Expand Down