Skip to content

[Bug]: RTF → TXT goes through Markdown and breaks code (backticks, indentation, blank lines) #1204

Closed

Description

@yavuzmeteafsar

What happened?

With Pandoc installed, filee convert file.rtf --to txt doesn't take LibreOffice's direct RTF → TXT edge (cost 25). It takes Pandoc's two steps, RTF → MD (gfm) → TXT, at a cost of 10 + 10 = 20. The result changes the text in two ways:

1. Code copied from an IDE gets backticks everywhere. Code pasted from an IDE keeps its colours: a monospace font, a \cfN run per token and an italic run here and there (System. + out). Pandoc then reads every run as an inline Code span. The Markdown step writes them next to each other, and the TXT step leaves the backticks in:

source:  content.append(line).append("\n");
result:  content.append(line).append(``"``\``n``"``);

The result no longer compiles.

2. Plain-font code loses its layout. In a normal font (TextEdit's default Helvetica) the result loses:

  • leading indentation
  • blank lines
  • runs of spaces, which collapse to one

In addition, straight quotes become curly quotes, "%d\n" becomes “%d”, C:\\Users becomes C:\Users, and lines are wrapped at 72 columns.

Where it comes from

  • PandocConverter has rtf → md and md → txt at the default cost of 10. LibreOfficeConverter adds rtf → txt at Fallback = 25. The route planner takes the cheaper two-step route.
  • Pandoc's RTF reader turns runs in a monospace font into separate Code inlines when it can't make one code block, here because of the italic run (issue 1).
  • The middle step writes gfm but reads it back as markdown, which has smart on and treats backslashes as escapes (part of issue 2). The plain writer wraps at 72 columns by default.
  • Calling Pandoc directly (-f rtf -t plain --wrap=none) fixes the backticks and the quotes. It still drops indentation and blank lines, so Pandoc isn't a good fit for RTF → TXT in general.

Suggestions

  1. Mark Pandoc's rtf → md edge DirectOnly (as txt → csv and pdf → xlsx already are). RTF → MD keeps working as it does today. RTF → TXT then goes through LibreOffice. This is the smallest change and fixes both issues when LibreOffice is there.
  2. When LibreOffice isn't installed, there's no other RTF → TXT route after (1). This could be a Pandoc rtf → txt edge with a cost above 25 and --wrap=none.
  3. Separately, for every MD → X step: read Markdown with the same flavour Filee writes it in (gfm), or at least markdown-smart. Then quotes and backslashes survive any route that passes through Markdown, not only this one.

I'd be happy to open a PR for (1) with a test for each sample, and (2)/(3) if you want them in the same change or separately.

What did you expect?

The same text as the RTF, line for line. On the attached samples, macOS textutil -convert txt -encoding UTF-8 produces exactly that.

Steps to reproduce

  1. Install Pandoc and LibreOffice (both "Found on this Mac" from Homebrew here).
  2. filee convert colored-code.rtf --to txt, and the same for plain-code.rtf from the attached zip.
  3. Compare each .txt with the RTF opened in TextEdit.

Running Filee's own commands by hand gives the same output (Pandoc 3.9, with the PlainMarkdown Lua filter):

pandoc in.rtf -f rtf -t gfm --lua-filter=plain.lua -o mid.md
pandoc mid.md -f markdown -t plain -o out.txt

Files involved

rtf-to-txt-samples.zip

Filee version

2.3.0

Operating system

MacOS 27.0.1

Engines page status

Pandoc, LibreOffice: Found on this Mac (Homebrew).

Log


Activity

  1. KnifeLemon commented on Nov 6, 2026

    @KnifeLemon
    Owner

    Thanks for the careful analysis, @yavuzmeteafsar! The route choice and the backticks are clear from what you've laid out, and this is a real bug.

    A two-step route through Markdown shouldn't beat a direct edge when the middle format loses information.

    Would you like to send a PR? If you'd rather not, just say so, and it stays open here for us. Please add a test with a run-heavy RTF like your IDE example.

  2. yavuzmeteafsar commented on Nov 6, 2026

    @yavuzmeteafsar
    ContributorAuthor

    Thanks for the careful analysis, @yavuzmeteafsar! The route choice and the backticks are clear from what you've laid out, and this is a real bug.

    A two-step route through Markdown shouldn't beat a direct edge when the middle format loses information.

    Would you like to send a PR? If you'd rather not, just say so, and it stays open here for us. Please add a test with a run-heavy RTF like your IDE example.

    Thanks! Yes, I'll send the PR. It will mark Pandoc's rtf → md edge DirectOnly, so RTF → TXT goes through LibreOffice again, plus a route test and an engine test with a run-heavy RTF like the IDE example (one colour run per token and an italic run). I'll link it here when it's up.

  3. KnifeLemon commented on Nov 6, 2026

    @KnifeLemon
    Owner

    Thanks, @yavuzmeteafsar, that plan works: DirectOnly on Pandoc's rtf → md edge, plus the route test and the engine test. I've assigned this to you.

  4. yavuzmeteafsar commented on Nov 11, 2026

    @yavuzmeteafsar
    ContributorAuthor

    The PR is up: #1388. The plan changed a little: DirectOnly on Pandoc's rtf → md sent RTF → TXT through the HWPX writer, which puts the whole file on one line, so the PR gives LibreOffice a direct rtf → txt edge instead. Details are in the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions