Incremental writer emits LF for a rewritten block or separator in a CRLF document

Abierto
#966 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust
Área
backend

Línea de trabajo

Start in crates/pampa/src/writers/incremental.rs, especially write_block_to_string and compute_separator; compare their freshly generated text with copied text on a CRLF input. The issue gives a reproduction shape and a suggested approach: detect the original document’s line endings and preserve them for rewritten blocks and synthesized separators. Done when the output keeps CRLF throughout after a block rewrite, while existing inline splicing still works.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Reproduction

At tag v0.37.0 (and on main at a37801fe4), on a CRLF (\r\n) document, make an edit that forces the incremental writer to rewrite a block from scratch rather than copy or splice it (for example, appending a brand-new paragraph with no original counterpart, or editing a paragraph in a way the inline-splice safety check rejects). Compute quarto_ast_reconcile::compute_reconciliation(&original, &edited) and call pampa::writers::incremental::incremental_write.

Minimal shape:

First paragraph.\r\n\r\nLast paragraph.\r\n

(all \r\n). After an edit that forces a block-level rewrite, the rewritten block and the separator immediately around it come out with \n instead of \r\n, while the rest of the file keeps \r\n.

A simpler case — editing a word in place inside a CRLF paragraph, where the result is handled by inline splicing rather than a full block rewrite — keeps \r\n correctly, because splicing copies bytes from the original rather than writing fresh text.

Observed vs expected

Observed: a rewritten block, and the separators the incremental writer has to synthesize around it (rather than copy from the original gap), use bare \n, producing a document with mixed line endings.

Expected: a rewritten block and its separators use the same line-ending convention as the rest of the document.

Cause

The standard QMD writer (crates/pampa/src/writers/qmd.rs) always emits bare \n — reasonably so, since most callers want platform-independent output. The incremental writer calls that standard writer whenever it has to rewrite a block from scratch (write_block_to_string in crates/pampa/src/writers/incremental.rs), and falls back to a literal "\n" separator in compute_separator whenever it can't copy the original gap verbatim (one of the two adjacent entries is a rewrite). Neither function looks at the original document's line-ending convention.

Suggested fix

Detect the document's line-ending convention once from original_qmd (e.g. "does it contain \r\n"), and when a block must be rewritten or a separator must be synthesized, convert/emit \r\n instead of \n in that case. The standard writer itself does not need to change — only the incremental writer's own freshly-generated text.

Lenguaje dominante
Rust
Estrellas
302
Forks
22
Merge medio
5 h 8 min
PR fusionados (30 d)
220

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de quarto-dev/q2

Todos los issues de quarto-dev/q2

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.