diff options
| author | Katsumi Yamaoka | 2016-11-14 06:48:06 +0000 |
|---|---|---|
| committer | Katsumi Yamaoka | 2016-11-14 06:48:06 +0000 |
| commit | 99e7b99e43ade2b0b653547f901b0891884b92f6 (patch) | |
| tree | b3a5233ea474426294014563d9804d69c4ef89c3 | |
| parent | cbed42838e44e54460a27e643858d34b53f74c99 (diff) | |
| download | emacs-99e7b99e43ade2b0b653547f901b0891884b92f6.tar.gz emacs-99e7b99e43ade2b0b653547f901b0891884b92f6.zip | |
* lisp/net/shr.el (shr-tag-table): Avoid duplication of images.
(shr-collect-extra-strings-in-table): Render images as well.
| -rw-r--r-- | lisp/net/shr.el | 78 |
1 files changed, 37 insertions, 41 deletions
diff --git a/lisp/net/shr.el b/lisp/net/shr.el index afe190803b3..9628ac294ad 100644 --- a/lisp/net/shr.el +++ b/lisp/net/shr.el | |||
| @@ -1895,65 +1895,61 @@ The preference is a float determined from `shr-prefer-media-type'." | |||
| 1895 | bgcolor)) | 1895 | bgcolor)) |
| 1896 | ;; Finally, insert all the images after the table. The Emacs buffer | 1896 | ;; Finally, insert all the images after the table. The Emacs buffer |
| 1897 | ;; model isn't strong enough to allow us to put the images actually | 1897 | ;; model isn't strong enough to allow us to put the images actually |
| 1898 | ;; into the tables. | 1898 | ;; into the tables. It inserts also non-td/th objects. |
| 1899 | (when (zerop shr-table-depth) | 1899 | (when (zerop shr-table-depth) |
| 1900 | (save-excursion | 1900 | (save-excursion |
| 1901 | (shr-expand-alignments start (point))) | 1901 | (shr-expand-alignments start (point))) |
| 1902 | ;; Insert also non-td/th objects. | ||
| 1903 | (save-restriction | 1902 | (save-restriction |
| 1904 | (narrow-to-region (point) (point)) | 1903 | (narrow-to-region (point) (point)) |
| 1905 | (insert (mapconcat #'identity | 1904 | (insert (mapconcat #'identity |
| 1906 | (shr-collect-extra-strings-in-table dom) | 1905 | (shr-collect-extra-strings-in-table dom) |
| 1907 | "\n")) | 1906 | "\n")) |
| 1908 | (shr-fill-lines (point-min) (point-max))) | 1907 | (shr-fill-lines (point-min) (point-max)))))) |
| 1909 | (dolist (elem (dom-by-tag dom 'object)) | ||
| 1910 | (shr-tag-object elem)) | ||
| 1911 | (dolist (elem (dom-by-tag dom 'img)) | ||
| 1912 | (shr-tag-img elem))))) | ||
| 1913 | 1908 | ||
| 1914 | (defun shr-collect-extra-strings-in-table (dom &optional flags) | 1909 | (defun shr-collect-extra-strings-in-table (dom &optional flags) |
| 1915 | "Return extra strings in DOM of which the root is a table clause. | 1910 | "Return extra strings in DOM of which the root is a table clause. |
| 1916 | Render extra child tables of which the parent is not td or th as well. | 1911 | Render <img>s and <object>s, and strings and child <table>s of which |
| 1917 | FLAGS is a cons of two boolean flags that control whether to collect | 1912 | the parent is not <td> or <th> as well. FLAGS is a cons of two |
| 1918 | or render objects." | 1913 | boolean flags that control whether to collect or render objects." |
| 1919 | ;; Currently this function supports extra strings and <table>s that | 1914 | ;; As for strings and child <table>s, it runs recursively and |
| 1920 | ;; are children of <table> or <tr> clauses, not <td> nor <th>. | 1915 | ;; collects or renders those objects if the cdr of FLAGS is nil. |
| 1921 | ;; It runs recursively and collects strings or renders <table>s if | 1916 | ;; FLAGS becomes (t . nil) if a <tr> clause is found in the children |
| 1922 | ;; the cdr of FLAGS is nil. FLAGS becomes (t . nil) if a <tr> | 1917 | ;; of DOM, and becomes (t . t) if a <td> or a <th> clause is found |
| 1923 | ;; clause is found in the children of DOM, and becomes (t . t) if | 1918 | ;; and the car is t then. When a <table> clause is found, FLAGS |
| 1924 | ;; a <td> or a <th> clause is found and the car is t then. | 1919 | ;; becomes nil if the cdr is t then. But if the cdr is nil then, |
| 1925 | ;; When a <table> clause is found, FLAGS becomes nil if the cdr is t | 1920 | ;; it renders the <table>. |
| 1926 | ;; then. But if the cdr is nil then, render the <table>. | 1921 | (cl-loop for child in (dom-children dom) with recurse with tag |
| 1927 | (cl-loop for child in (dom-children dom) with tag with recurse | 1922 | do (setq recurse nil) |
| 1928 | if (stringp child) | 1923 | if (stringp child) |
| 1929 | unless (cdr flags) | 1924 | unless (cdr flags) |
| 1930 | when (string-match "\\(?:[^\t\n\r ]+[\t\n\r ]+\\)*[^\t\n\r ]+" | 1925 | when (string-match "\\(?:[^\t\n\r ]+[\t\n\r ]+\\)*[^\t\n\r ]+" |
| 1931 | child) | 1926 | child) |
| 1932 | collect (match-string 0 child) | 1927 | collect (match-string 0 child) |
| 1933 | end end | 1928 | end end |
| 1934 | else | 1929 | else if (consp child) |
| 1935 | do (setq tag (dom-tag child) | 1930 | do (setq tag (dom-tag child)) and |
| 1936 | recurse t) | 1931 | unless (memq tag '(comment style)) |
| 1937 | and | 1932 | if (eq tag 'img) |
| 1938 | if (eq tag 'tr) | 1933 | do (shr-tag-img child) |
| 1939 | do (setq flags '(t . nil)) | 1934 | else if (eq tag 'object) |
| 1940 | else if (memq tag '(td th)) | 1935 | do (shr-tag-object child) |
| 1941 | when (car flags) | ||
| 1942 | do (setq flags '(t . t)) | ||
| 1943 | end | ||
| 1944 | else if (eq tag 'table) | ||
| 1945 | if (cdr flags) | ||
| 1946 | do (setq flags nil) | ||
| 1947 | else | 1936 | else |
| 1948 | do (setq recurse nil) | 1937 | do (setq recurse t) and |
| 1949 | (shr-tag-table child) | 1938 | if (eq tag 'tr) |
| 1950 | end | 1939 | do (setq flags '(t . nil)) |
| 1951 | else | 1940 | else if (memq tag '(td th)) |
| 1952 | when (memq tag '(comment style)) | 1941 | when (car flags) |
| 1953 | do (setq recurse nil) | 1942 | do (setq flags '(t . t)) |
| 1954 | end end end end and | 1943 | end |
| 1955 | when recurse | 1944 | else if (eq tag 'table) |
| 1956 | append (shr-collect-extra-strings-in-table child flags))) | 1945 | if (cdr flags) |
| 1946 | do (setq flags nil) | ||
| 1947 | else | ||
| 1948 | do (setq recurse nil) | ||
| 1949 | (shr-tag-table child) | ||
| 1950 | end end end end end end end end end | ||
| 1951 | when recurse | ||
| 1952 | append (shr-collect-extra-strings-in-table child flags))) | ||
| 1957 | 1953 | ||
| 1958 | (defun shr-insert-table (table widths) | 1954 | (defun shr-insert-table (table widths) |
| 1959 | (let* ((collapse (equal (cdr (assq 'border-collapse shr-stylesheet)) | 1955 | (let* ((collapse (equal (cdr (assq 'border-collapse shr-stylesheet)) |