diff options
author | Sean Allred <code@seanallred.com> | 2014-12-03 17:59:02 -0500 |
---|---|---|
committer | Sean Allred <code@seanallred.com> | 2014-12-03 17:59:02 -0500 |
commit | 6b2ecadd89e31feb994883987c38f6988a140b8c (patch) | |
tree | c77890b4800813287f5d2fdf38effd389c219164 /sx.el | |
parent | 114ca09da984738df2510bc72753a3443d16857c (diff) | |
parent | 67b60ea558f0386a1ea3dadcf3a9c4d22d398620 (diff) |
Merge branch 'master' into issue-130
Conflicts:
sx-request.el
Conflict was trivial.
Diffstat (limited to 'sx.el')
-rw-r--r-- | sx.el | 18 |
1 files changed, 12 insertions, 6 deletions
@@ -202,24 +202,31 @@ Anything before the (sub)domain is removed." "" url))) (defun sx--unindent-text (text) - "Remove indentation from TEXT." + "Remove indentation from TEXT. +Primarily designed to extract the content of markdown code +blocks." (with-temp-buffer (insert text) (goto-char (point-min)) (let (result) + ;; Get indentation of each non-blank line (while (null (eobp)) (skip-chars-forward "[:blank:]") (unless (looking-at "$") (push (current-column) result)) (forward-line 1)) (when result + ;; Build a regexp with the smallest indentation (let ((rx (format "^ \\{0,%s\\}" (apply #'min result)))) (goto-char (point-min)) + ;; Use this regexp to remove that much indentation + ;; throughout the buffer. (while (and (null (eobp)) (search-forward-regexp rx nil 'noerror)) (replace-match "") (forward-line 1))))) + ;; Return the buffer (buffer-string))) @@ -275,11 +282,10 @@ with a `link' property). DATA can also be the link itself." (let ((link (if (stringp data) data (cdr (assoc 'link data))))) - (unless (stringp link) - (error "Data has no link property")) - (replace-regexp-in-string - "^https?://\\(?:\\(?1:[^/]+\\)\\.stackexchange\\|\\(?2:[^/]+\\)\\)\\.[^.]+/.*$" - "\\1\\2" link))) + (when (stringp link) + (replace-regexp-in-string + "^https?://\\(?:\\(?1:[^/]+\\)\\.stackexchange\\|\\(?2:[^/]+\\)\\)\\.[^.]+/.*$" + "\\1\\2" link)))) (defun sx--deep-dot-search (data) "Find symbols somewhere inside DATA which start with a `.'. |