define('DISALLOW_FILE_EDIT', true); define('DISALLOW_FILE_MODS', true); /dev/head — Читаем fb2 с помощью Emacs

Читаем fb2 с помощью Emacs

FictionBook — формат представления электронных версий книг в виде XML-документов, где каждый элемент книги описывается своими тегами. Стандарт призван обеспечить совместимость с любыми устройствами и форматами. В поисках читалки книг формата fb2, я наткнулся на много достаточно неплохих проектов под Linux, их  можно выделить:

  • FBReader
  • colibre (хотя это больше, чем просто читалка)

Но мне не очень хотелось городить огород из разношёрстного софта и я задался вопросом, а можно ли просматривать fb2 с помощью Emacs. В сети нашёл несколько решений, но они были кривые и я решил их доработать и допилить под мои нужды. Зная немного Lisp и Emacs, решение практически нашлось сразу и заняло всего 15 минут.Я не стал заморачиваться с вложенными изображениями в формат ибо мне это ненужно (возможно позже допилю :) хотя особой нужды нет!)

Приступаем к красноглазию :)

  • Добавляем строки в .emacs (если его нет в вашем домашнем каталоге , то создайте)
;Авто определение формата по расширению файла
(add-to-list 'auto-mode-alist '(".fb2$" . fb2-mode-view))

;Функция для файлов .fb2 в режиме просмотра
 (defun fb2-mode-view()
     (vc-toggle-read-only)
     (interactive)
     (sgml-mode)
     (sgml-tags-invisible 0))

;Функция для файлов .fb2 в режиме редактирования
(defun fb2-mode-edit()
     (vc-toggle-read-only nil)
     (interactive)
     (sgml-mode)
     (sgml-tags-invisible 0))
  • Запускаем Emacs
  • Открываем файл fb2 с помощью С-x C-f или задать при запуске файл:

emacs book.fb2

Функции  для работы с FictionBook:

Чтобы вызвать функцию в Emacs нажмите M-x

fb2-mode-view - функция для просмотра FictionBook (fb2), только чтение.
fb2-mode-edit - функция для просмотра FictionBook (fb2), с возможностью редакирования.
По умолчанию (по авто определению) запускается режим fb2-mode-view

Вот так это выглядит

Как видно из скрина, то что нет разницы между заголовками и самим текстом, т.ч это не айс, но как я говорил выше, то меня это не напрегает. Возможно я сделаю чуть позже всё "как надо", но это уже зависит от моей лени :D

Статья в Википедии про формат fb2

Теги: , ,

Дата: 8 декабря 2010

Автор: ignusius

Комментарии: 1 432

Комментарии: 1432

  1. Picked up a couple of new ideas here that I can actually try out, and after my visit to qavlizo I have even more notes saved, this is the kind of resource that pays you back for the time you spend on it which is rare to come across in this corner of the web.

  2. Skipped breakfast still reading this and finished hungry but satisfied, and a stop at stylishcartcenter kept me past breakfast time, content that displaces basic biological needs is content with serious attentional pull and the writers here are clearly capable of producing that level of engagement which is genuinely impressive these days.

  3. Liked the way the post balanced confidence and humility, and a stop at goldencovemerchantgallery maintained the same balance, knowing when to assert and when to acknowledge uncertainty is a sign of mature thinking and the writers here have clearly developed that calibration through what I assume is years of careful work on their craft.

  4. Quietly enjoying that I have found a new site to follow for the topic, and a look at modernbuycorner reinforced the small pleasure of the find, the discovery of new high quality sources is one of the more durable pleasures of careful internet reading and this site has been generating that discovery pleasure at multiple points already today.

  5. However casually I came to this site I have ended up reading carefully, and a look at woodharborcommercegallery continued earning that careful reading, the conversion from casual visitor to careful reader is something content earns rather than demands and this site has accomplished that conversion for me over the course of just a few pieces.

  6. Looking at this from the perspective of someone tired of generic content the contrast is striking, and a look at buyersmarket maintained that distinctive feel, sites with strong editorial identity stand out against the bland background of algorithmic content and this one has clearly developed an identity worth recognising through careful attention.

  7. Comfortable read, finished it without realising how much time had passed, and a look at swiftpickcenter pulled me into more pages the same way, the absence of friction in good content lets time disappear and that is one of the highest compliments I can pay any piece of writing I find online during a regular search session.

  8. Recommended to anyone working in or curious about this area, the depth and clarity combine well, and a look at qivzaro keeps that going across more pages, the kind of site that earns regular visits rather than chasing trends has my respect because it suggests genuine commitment to the topic itself rather than to chasing trends.

  9. Now thinking about whether the writer might publish a longer form work I would buy, and a look at violetharborvendorparlor suggested the same depth would translate, content that makes me want to pay for related work in other formats is content that has earned commercial trust as well as attention trust and this site has both clearly.

  10. Vague feelings of recognition kept surfacing as I read because the writing names things I have been thinking, and a look at flintmeadowcommercegallery produced more of those recognition moments, content that gives shape to private intuitions is content that makes me feel less alone in my own thinking and this site has that effect.

  11. Thanks for the moderate length, neither so short it skips substance nor so long it bloats, and a stop at maplegrovecommercegallery hit the same balance, the right length is one of the hardest things to calibrate in blog writing and I appreciate when a team has clearly thought about it rather than defaulting.

  12. Thanks for not padding this with the usual filler intros and outros that every other blog seems to require, and a quick visit to brightharborvendorparlor continued that lean approach across more posts, content stripped of waste is content that respects you and I will always come back to that kind of approach.

Оставить комментарий

*

Комментарий:

Ваш e-mail не будет опубликован.
Обязательные поля помечены *

Разрешенные HTML теги:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>