bir-import.el 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. ;;; bir-import.el --- Importing facilities for BIR -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2022 c1-g
  3. ;; Author: c1-g <char1iegordon@protonmail.com>
  4. ;; Keywords: convenience
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;;
  17. ;;; Code:
  18. (defun bir-import (&optional url)
  19. "URL's web page content.
  20. Content is processed with `eww-readable' and Pandoc.
  21. This is a simplified version of `org-web-tools--url-as-readable-org'."
  22. (-let* ((url (or url (org-web-tools--get-first-url)))
  23. (html (with-temp-buffer
  24. (insert (org-file-contents url))
  25. (condition-case nil
  26. ;; Fix undecoded text
  27. (decode-coding-region (point-min) (point-max) 'utf-8)
  28. (coding-system-error nil))
  29. (buffer-string)))
  30. (html (org-web-tools--sanitize-html html url))
  31. (readable (cdr (org-web-tools--eww-readable html)))
  32. (converted (org-web-tools--html-to-org-with-pandoc readable)))
  33. (with-temp-buffer
  34. (org-mode)
  35. (insert converted)
  36. (org-web-tools--demote-headings-below 1)
  37. (buffer-string))))
  38. (provide 'bir-import)
  39. ;;; bir-import.el ends here