Files
genoffice/apps/docs/tests/auto-hyphenation-css.test.ts
T
merrick-2002andGenOffice 80d2a4651e Sync snapshot (2026-09-17) (#463)
- MCP over HTTP: `genoffice mcp --http` serves the tool set as a Streamable HTTP server for clients on other machines, with file upload, URL inputs and result files handed back; MCP agents can also read PDF text, edit the open document and drive the visible Sheets grid
- Docs: picture-heavy documents open lazily with media served from disk (gigabyte files in seconds), files over 512 MB are refused with a message instead of a crash, long documents open and type faster, and many Word-fidelity fixes for tables (autofit width, split rows, header-row keep, page-edge borders), anchored pictures and text boxes, header/footer spacing, chart labels and EMF+ clipping, Japanese font substitution, italic and bidi runs
- Markdown: saving keeps unchanged blocks byte-for-byte and re-serializes edited blocks in the document's own conventions (plus an opt-in unchanged-source round trip); ```wavedrom fences render as timing diagrams
- Sheets: smooth scrolling, duplicate and large-range copy on big streamed workbooks; context-menu submenus reopen reliably; AI bulk-job economy rules
- App: Help → Check for Updates and an About-dialog button; the in-editor Files pane and floating Files / Outline edge tabs are removed from all editors; AI panel can dock on either side
- AI providers: DeepSeek V4.1 Flash, gpt-6-astra and Opper added, retired ids dropped, clearer error when a tool call's arguments are too large
- PPTX: chart categories honor the 1904 date system, slide text extracts in presentation order, single-quoted attributes and case-insensitive preset colors parse; backports of public PRs #432–#461

Co-authored-by: GenOffice <merrick-2002@users.noreply.github.com>
2026-09-17 21:30:17 +08:00

125 lines
3.6 KiB
TypeScript

/**
* w:autoHyphenation → CSS hyphens, gated by w:suppressAutoHyphens (github run
* 20260825 samples 16/91: Word does not hyphenate when pPrDefault carries
* w:suppressAutoHyphens even though settings.xml enables autoHyphenation).
*/
import { describe, expect, it } from 'vitest'
import type { DocDefaults, ParsedDocFull, StyleInfo } from '@genoffice/docx-engine'
import { docStyleCss } from '../src/renderer/doc-style-css'
;(globalThis as { CSS?: unknown }).CSS ??= { escape: (s: string) => s }
function parsedDoc(opts: {
autoHyphenation?: boolean
docDefaults?: DocDefaults
styles?: StyleInfo[]
}): ParsedDocFull {
const styles = new Map<string, StyleInfo>()
for (const s of opts.styles ?? []) styles.set(s.styleId, s)
return {
styles,
docDefaults: opts.docDefaults ?? {},
blocks: [],
...(opts.autoHyphenation ? { autoHyphenation: true } : {}),
} as unknown as ParsedDocFull
}
const AUTO = '.doc-page { hyphens:auto; -webkit-hyphens:auto }'
describe('autoHyphenation CSS', () => {
it('emits document-wide hyphens:auto for plain autoHyphenation', () => {
expect(docStyleCss(parsedDoc({ autoHyphenation: true }))).toContain(AUTO)
})
it('emits nothing without autoHyphenation', () => {
expect(docStyleCss(parsedDoc({}))).not.toContain('hyphens')
})
it('pPrDefault suppressAutoHyphens turns the document-wide rule off', () => {
const css = docStyleCss(
parsedDoc({ autoHyphenation: true, docDefaults: { suppressAutoHyphens: true } }),
)
expect(css).not.toContain(AUTO)
})
it('default paragraph style suppressAutoHyphens turns the document-wide rule off', () => {
const css = docStyleCss(
parsedDoc({
autoHyphenation: true,
styles: [
{
styleId: 'Normal',
name: 'Normal',
type: 'paragraph',
isDefault: true,
display: { suppressAutoHyphens: true },
} as StyleInfo,
],
}),
)
expect(css).not.toContain(AUTO)
})
it("default style's explicit off overrides a suppressing pPrDefault", () => {
const css = docStyleCss(
parsedDoc({
autoHyphenation: true,
docDefaults: { suppressAutoHyphens: true },
styles: [
{
styleId: 'Normal',
name: 'Normal',
type: 'paragraph',
isDefault: true,
display: { suppressAutoHyphens: false },
} as StyleInfo,
],
}),
)
expect(css).toContain(AUTO)
})
it('styled paragraphs override per style in both directions', () => {
const css = docStyleCss(
parsedDoc({
autoHyphenation: true,
styles: [
{
styleId: 'NoHyph',
name: 'NoHyph',
type: 'paragraph',
isDefault: true,
display: { suppressAutoHyphens: true },
} as StyleInfo,
{
styleId: 'ReHyph',
name: 'ReHyph',
type: 'paragraph',
isDefault: true,
display: { suppressAutoHyphens: false },
} as StyleInfo,
],
}),
)
expect(css).toContain('[data-style="NoHyph"] { hyphens:manual;-webkit-hyphens:manual }')
expect(css).toContain('[data-style="ReHyph"] { hyphens:auto;-webkit-hyphens:auto }')
})
it('style values are inert without autoHyphenation', () => {
const css = docStyleCss(
parsedDoc({
styles: [
{
styleId: 'NoHyph',
name: 'NoHyph',
type: 'paragraph',
isDefault: true,
display: { suppressAutoHyphens: true },
} as StyleInfo,
],
}),
)
expect(css).not.toContain('hyphens')
})
})