Bug 430538

Summary: Markdown files opened as plain text
Product: [Applications] okular Reporter: Yaroslav Sidlovsky <zawertun>
Component: generalAssignee: Okular developers <okular-devel>
Severity: normal CC: aacid, alfre2.as, bizyaev, filippo27998, generic, marcelo.jimenez, nate, ped, sh200105, simone, user6334
Priority: NOR    
Version: 21.12.3   
Target Milestone: ---   
Platform: Manjaro   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: Markdown file for tests
Opens as markdown document
Doesn't open as markdown document

Description Yaroslav Sidlovsky 2020-12-18 11:53:03 UTC
Created attachment 134178 [details]
Markdown file for tests

Okular uses wrong backend for Markdown files.
Issue could be fixed by the reverting this commit: https://invent.kde.org/graphics/okular/-/merge_requests/316/diffs?commit_id=d2ae2c283df3d42e72a964d8891e0915f8f3a94b.
Issue can't be reproduced with okular 20.08.3 (no other changes to the system was made).

1. Run "okular ~/Fedora-29-xrdp.md";
2. Check used backend in Help -> About Backend.

"Txt backend" is used.

"Markdown Backend" should be used instead.

Operating System: Fedora 33
KDE Plasma Version: 5.20.4
KDE Frameworks Version: 5.77.0
Qt Version: 5.15.2
Kernel Version: 5.9.13-200.fc33.x86_64
OS Type: 64-bit
Processors: 4 × AMD FX(tm)-9590 Eight-Core Processor
Memory: 22.4 ГиБ of RAM
Graphics Processor: GeForce GTX 1060 6GB/PCIe/SSE2
Comment 1 Ilya Bizyaev 2020-12-18 11:57:53 UTC
Same here.

Okular 20.12
Frameworks 5.76.0
Qt 5.15.2
Comment 2 user6334 2020-12-18 12:25:16 UTC
Same here.

OS: Arch Linux x86_64
Kernel: 5.4.84-1-lts
KDE Plasma Version: 5.20.4
KDE Frameworks Version: 5.77.0
Qt Version: 5.15.2
Okular Version: 20.12.0
Comment 3 Bug Janitor Service 2020-12-19 23:50:01 UTC
A possibly relevant merge request was started @ https://invent.kde.org/graphics/okular/-/merge_requests/347
Comment 4 Albert Astals Cid 2020-12-27 01:10:51 UTC
Git commit 9e23338b002cd14d8a9ad191526a7950e72d97e9 by Albert Astals Cid.
Committed on 27/12/2020 at 00:16.
Pushed by aacid into branch 'release/20.12'.

Fix opening markdown files

In d2ae2c283df3d42e72a964d8891e0915f8f3a94b we introduced a tweak that
broke opening markdown files.

what we really want is this:
 * If the mimetype from the filename is text (or children) but looking
   at the data says it's not text, then try opening first opening with
   the data suggeted mimetype
 * But if the data suggested mimetype says it's text, use the filename
   suggested mimetype since for example, the only way to really
   differentiate markdown from text is the filename, so trust that

M  +4    -2    part/part.cpp

Comment 5 Marcelo Jimenez 2021-01-05 16:55:33 UTC
*** Bug 431183 has been marked as a duplicate of this bug. ***
Comment 6 Simone Lazzaris 2021-11-26 09:26:04 UTC
I'm reopening this bug as I've got the same behavior in the newer version (21.08.3).

OS: Arch Linux x86_64
Kernel: 5.15.3-arch1-1
KDE Plasma Version: 5.23.3
KDE Gear: 21.08.3
Qt Version: 5.15.2
Okular Version: 21.08.3
Comment 7 Albert Astals Cid 2021-11-26 23:32:03 UTC
The attached file works, so you'll have to give us one that doesn't
Comment 8 Simone Lazzaris 2021-11-29 09:35:44 UTC
After an update and a reboot, it started to work for me too.
Sorry for the fuss.
Comment 9 Adrian W. 2022-03-17 16:17:16 UTC
I have a lot of markdown documents opening with the Txt backend. Figured it out eventually, it seems to me like it's a bug.

Attached 2 files, one opens with the Txt backend and the other with the Markdown backend.
- Both are 'mime-type: text/plain'
- Both show in Dolphin as 'Type: Markdown document' (*.md)

But Dolphin properties show different recognized content:
'markdown.md' shows correctly 'Content: plain text document'
'notmarkdown.md' shows incorrectly 'Content: MATLAB file'

The difference that triggers the content to be misdiagnosed is how the first line starts. Remove the first line from 'markdown.md' and the content changes to MATLAB document, consequently opening the file in Okular with the Txt backend.
Comment 10 Adrian W. 2022-03-17 16:18:19 UTC
Created attachment 147560 [details]
Opens as markdown document
Comment 11 Adrian W. 2022-03-17 16:18:54 UTC
Created attachment 147561 [details]
Doesn't open as markdown document
Comment 12 Bug Janitor Service 2022-08-21 17:18:53 UTC
A possibly relevant merge request was started @ https://invent.kde.org/graphics/okular/-/merge_requests/645
Comment 13 Albert Astals Cid 2022-08-31 17:29:20 UTC
Git commit 01871fdfff9363af3a90959650ef20ab9276c464 by Albert Astals Cid.
Committed on 31/08/2022 at 16:55.
Pushed by aacid into branch 'release/22.08'.

Even more tweaks to opening "text" files
Related: bug 456434

M  +10   -1    part/part.cpp