Skip to content

Instantly share code, notes, and snippets.

@kuanyui
Last active December 22, 2015 17:18
Show Gist options
  • Save kuanyui/6504771 to your computer and use it in GitHub Desktop.
Save kuanyui/6504771 to your computer and use it in GitHub Desktop.
程式碼超難看的livedoor reader的OPML轉Markdown
(defun opml-to-markdown ()
(interactive)
(let (output-markdown opml-copy-to trans input-file)
(setq output-markdown "~/Dropbox/Blog/source/blogrolls/index.md"
opml-copy-to "~/Dropbox/Blog/source/blogrolls/"
input-file (read-file-name "OPML file's location: "))
(if (not (string-match "\\(\.opml\\|\.xml\\)$" input-file))
(progn "It's not an OPML file."
(opml-to-markdown))
(progn
(copy-file input-file (format "%srss-reader.xml" opml-copy-to) 'overwrite)
(copy-file input-file output-markdown 'overwrite)
(find-file output-markdown)
(goto-char (point-min))
(re-search-forward "<\\?xml\\(?:.\\|\n\\)*<outline title=\"Subscriptions\">" nil :no-error)
(replace-match "")
(while (re-search-forward "<outline title=\"\\(.+\\)\">" nil :no-error)
(replace-match (format "###%s###" (match-string 1))))
(goto-char (point-min))
(while (re-search-forward "<outline title=\"\n?*\\(.+?\\)\n?*\" htmlUrl=\"\\(.+?\\)\".*/>" nil :no-error)
(replace-match (format "- [%s](%s)" (match-string 1) (match-string 2))))
(goto-char (point-min))
(while (re-search-forward "</outline>" nil :no-error)
(replace-match ""))
(goto-char (point-min))
(while (re-search-forward "</body></opml>" nil :no-error)
(replace-match ""))
(goto-char (point-min))
(while (re-search-forward "^ +" nil :no-error)
(replace-match ""))
(goto-char (point-min))
(insert (format "<blockquote class=\"pullquote\">這是我所訂閱的所有RSS feed,部份飼料的分類標準不明不白為正常現象,安心食用。<br>
完整的OPML檔可以在<a href=\"rss-reader.xml\">這裡</a>取得。
此頁面於%s產生</blockquote>" (format-time-string "%Y/%m/%d" (current-time))))
(save-buffer)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment